0

I've read this post already, however I'm failing to apply it properly.

I want to remove the totals section from the mini-cart. To track down the block I've enabled path hints.

Minicart with path hints enabled

So it seems the block of interest is Magento\Checkout\Block\Cart\Totals and the template of interest is vendor/magento/module-checkout/view/frontend/templates/cart/totals.phtml. Searching the code I found this line

<block class="Magento\Checkout\Block\Cart\Totals" name="checkout.cart.totals" template="cart/totals.phtml">

in vendor/magento/module-checkout/view/frontend/layout/checkout_cart_index.xml. So in my custom module trying to remove it, I've created this file vendor/my-module/view/frontend/layout/checkout_cart_index.xml which looks like this

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.cart.totals" remove="true" />
    </body>
</page>

That doesn't remove the totals section, however I feel like I'm on the right track because two exercises succeed in my attempt

  • Editing vendor/magento/module-checkout/view/frontend/layout/checkout_cart_index.xml and removing the declaration for the Magento\Checkout\Block\Cart\Totals block
  • Editing vendor/magento/module-checkout/view/frontend/templates/cart/totals.phtml and removing cart-totals div.

So I seem to be working with the correct block and template, but my layout update doesn't work; any idea why? Note, caching is disabled.

3

<referenceBlock name="checkout.cart.totals" remove="true" />

This is not true. Remove attribute stop the default cart functionality in magento2. Use display="false" attribute in xml file.

Solution:
Create default.xml file at view/frontend/layout/default.xml in custom module.

<referenceBlock name="checkout.cart.totals" display="false" />

Default .xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <body>
     <referenceBlock name="checkout.cart.totals" display="false" />
 </body>
</page>
  • Hi, this is an interesting point about using display=false instead of remove=true for blocks pertaining to the cart. However putting the default.xml file as you have show does not hide the block for me, so something still isn't working correctly. – quickshiftin Jul 26 '16 at 13:51
  • my side is working. show the code plz – Sourav Jul 26 '16 at 17:32
  • Hmm, it seems I needed to run bin/magento setup:di:compile for it to take effect, whether I place it in default.xml or checkout_cart_index.xml. Does that sound right? – quickshiftin Jul 26 '16 at 17:32

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.