Showing results for 
Search instead for 
Did you mean: 

Remove item in (js) layout array

Remove item in (js) layout array



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="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="checkout.cart.totals">
                <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>


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?


Re: Remove item in (js) layout array

Hi there,


have you already found the solution for this?




Re: Remove item in (js) layout array


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:


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 name="template" xsi:type="string">Magento_Checkout/cart/totals/shipping

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'">
            window.checkoutConfig = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getCheckoutConfig()); ?>;
            window.customerData = window.checkoutConfig.customerData;
            window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
            ], function(url, blockLoader) {
                blockLoader("<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>");
                return url.setBaseUrl('<?php /* @escapeNotVerified */ echo $block->getBaseUrl();?>');