Magento – Magento 2 Store switcher error in “section-config.js” Uncaught TypeError: Cannot read property ‘*’ of undefined(…)

blocksjavascriptmagento-2.1magento2store-switcher

I'm implementing a custom store switcher in my custom theme.

Block template is as follow:

<?php if (count($block->getStores())>1): ?>
    <?php $id = $block->getIdModifier() ? '-' . $block->getIdModifier() : ''?>

    <span><?php echo $block->escapeHtml($block->getStoreName()) ?></span>

    <span>/</span>

    <?php foreach ($block->getStores() as $_lang): ?>
        <?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
            <span class="view-<?php echo $block->escapeHtml($_lang->getCode()); ?> switcher-option">
                <a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getTargetStorePostData($_lang); ?>'>
                    <?php echo $block->escapeHtml($_lang->getName()) ?>
                </a>
            </span>
        <?php endif; ?>
    <?php endforeach; ?>

<?php endif; ?>

The link to new store is correctly displayed so I guess the xml stuff is OK, but on click I receive the following error:

section-config.js:33 Uncaught TypeError: Cannot read property '*' of
undefined(…)

The generated html looks like the following:

<span class="view-it switcher-option">
  <a href="#" data-post="{"action":"http:\/\/test.mysite.eu\/stores\/store\/switch\/","data":{"___store":"it","uenc":"aHR0cDovL3Rlc3QuZnJhZ2lhY29tb21pbGFuby5ldS8,"}}">
    It
  </a>
</span>

Best Answer

I had the same problem and found out that these two blocks where not called any more due to customizations in the theme.

The two blocks are per default added in the <referenceContainer name="content"> of vendor/magento/module-customer/view/frontend/layout/default.xml.

Try re-adding these blocks in your layout.xml:

<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"/>
Related Topic