Magento – Magento 2.1.2: How to delete element “minicart” from the website to make the print invoice (print.xml)

magento2mini-cart

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

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

and

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">
<body>
    <referenceContainer name="page.wrapper">
        <container name="side.navbar.container" remove="true"/>
    </referenceContainer>
    <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"/>
</body>

Best Answer

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

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

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.