
Magento 2.x – Fix error “cannot read property ‘section loadurl’ of undefined in customer-data.js”
The data which code references to sectionLoadUrl is usually set in the following snippet that (should) be on every Magento front-end page:
1 2 3 |
<script type="text/x-magento-init"> {"*":{"Magento_Customer\/js\/customer-data":{"sectionLoadUrl":"http:\/\/magento-2-1-4.dev\/customer\/section\/load\/","cookieLifeTime":"3600","updateSessionUrl":"http:\/\/magento-2-1-4.dev\/customer\/account\/updateSession\/"}}} </script> |
So, either something in your system removed this snippet, or you’re somehow invoking the functionality in Magento_Customer/js/customer-data before the snippet’s had a chance to run.
A quick fix for that, would be adding the following code on “<Magento_directry>/app/design/frontend/<Vendor>/<theme>/Magento_Theme/layout/default.xml” :
1 2 3 4 5 6 7 |
<referenceContainer name="content"> <block name="customer.section.config" class="Magento\Customer\Block\SectionConfig" template="Magento_Customer::js/section-config.phtml"/> <block name="customer.customer.data" class="Magento\Customer\Block\CustomerData" template="Magento_Customer::js/customer-data.phtml"/> </referenceContainer> |
Afterwards, remember to clean cache, and try again.