when I want to delete a block minicart I have the following error:

Uncaught TypeError: Cannot read property 'captcha' of undefined(…)


Uncaught TypeError: Cannot read property 'autocomplete' of undefined(…)

This is my code template (Vendor/theme/Magento_Theme/layout/print.xml)

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="page.wrapper">
        <container name="side.navbar.container" remove="true"/>
    <referenceBlock name="top.links" remove="true"/>
    <referenceContainer name="footer" remove="true"/>
    <move element="copyright"   destination="footer.grid-container" remove="true"/>
    <move element="minicart"    destination="header-wrapper.grid-container" remove="true"/>


As far as I can tell from looking into this, the error is thrown because the minicart's phtml file has the line:

        window.checkout = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>;

Javascript values for "captcha" and "autocomplete" are set in the code it generates.

This value is referenced in scripts from other modules, such as vendor\magento\module-catalog\view\frontend\web\js\view\image.js - and so if you remove that block, other modules which need that configuration script start getting upset.

Whilst I'm sure it is possible to remove other blocks that reference it, or create a widget to add this code elsewhere, I'd personally just hide the cart with CSS.

| improve this answer | |

One workaround is to add the missing window.checkout variable via the layout.xml file, like so:

<referenceContainer name="after.body.start">
    <block class="Magento\Framework\View\Element\Text" name="fixminicarterror">
            <argument name="text" xsi:type="string"><![CDATA[<script>window.checkout = {};</script>]]></argument>

Solution from a GitHub bug here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.