1

How can I add a custom button adjacent to Update Shopping car button in Magento2.1?

enter image description here

I created a file checkout_cart_index.xml with following content.

<?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>
        <referenceContainer name="content">
            <block template="Namespace_Module::custom/mybutton.phtml" class="Magento\Framework\View\Element\Template" name="my.button" as="my.button"/>
        </referenceContainer>
    </body>
</page>

But it shows button below the Apply Discount Code section.

Is it possible to achieve this without overriding cart/form.phtml

<block class="Magento\Checkout\Block\Cart" name="checkout.cart.form" as="cart-items" template="cart/form.phtml" after="cart.summary">
    <block class="Magento\Framework\View\Element\RendererList" name="checkout.cart.item.renderers" as="renderer.list"/>
    <block class="Magento\Framework\View\Element\Text\ListText" name="checkout.cart.order.actions"/>
</block>
0

If we need the button adjacent to other button then we have to override form.phtml file. Which is used in the core checkout module of magento2

vendor\magento\module-checkout\view\frontend\layout\checkout_cart_index.xml

check for

<block class="Magento\Checkout\Block\Cart" name="checkout.cart.form" as="cart-items" template="cart/form.phtml" after="cart.summary">
    <block class="Magento\Framework\View\Element\RendererList" name="checkout.cart.item.renderers" as="renderer.list"/>
    <block class="Magento\Framework\View\Element\Text\ListText" name="checkout.cart.order.actions"/>
</block>

So we need to create checkout_cart_index.xml file in our custom module and set a custom template consisting core code as well as our on button code.

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.