cancel
Showing results for 
Search instead for 
Did you mean: 

Remove item in (js) layout array

Remove item in (js) layout array

Hi,

 

We're trying to remove the 'discount' item in checkout_cart_index.xml, but we can't find a way to achieve this. We defined an extension with a custom checkout_cart_index.xml which inserts one (or more) new items. But how can we remove the existing item?

 

This is our layout:

 

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<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">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="block-totals" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="before_grandtotal" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="customdiscount" xsi:type="array">
                                            <item name="component"  xsi:type="string">Custom_ShoppingCart/js/view/cart/totals/customdiscount</item>
                                            <item name="config" xsi:type="array">
                                                <item name="title" xsi:type="string">Custom Discount</item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

 

We read something about unsetChild, but I can't get it to work?

Or is there a way to overwrite the SalesRule/view/frontend/web/js/view/cart/totals/discount.js, to return false in the isDisplayed method?

2 REPLIES 2

Re: Remove item in (js) layout array

Hi there,

 

have you already found the solution for this?

 

Regards

Jaime

Re: Remove item in (js) layout array

Hi, 

I don't know if you are looking for a solution yet.

 

What you need to do is override the layout in your theme, adding:
Magento_Checkout/layout/override/base/checkout_cart_index.xml

 

Here, you copy the file and do your modifications.

 

If you want to remove the shipping estimate, you will notice you really need this block...

What you have to do is just remove or comment the item:

<item name="shipping" xsi:type="array">
  <item name="component"  xsi:type="string">Magento_Checkout/js/view/cart/totals/shipping</item>
    <item name="config" xsi:type="array">
      <item name="title" xsi:type="string" translate="true">Shipping
      </item>
      <item name="template" xsi:type="string">Magento_Checkout/cart/totals/shipping
     </item>
   </item>
</item>

At the checkout.cart.totals block. 

And edit the cart/shipping.phtml. You must keep the #block-shipping and #block-summary by this way:

<div id="block-shipping">
   <div id="block-summary" data-bind="scope:'block-summary'">
        <script>
            window.checkoutConfig = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getCheckoutConfig()); ?>;
            window.customerData = window.checkoutConfig.customerData;
            window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
            require([
                'mage/url',
                'Magento_Ui/js/block-loader'
            ], function(url, blockLoader) {
                blockLoader("<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>");
                return url.setBaseUrl('<?php /* @escapeNotVerified */ echo $block->getBaseUrl();?>');
            })
        </script>
    </div>
</div>