1

guys I am trying to add a button in the Shopping Cart page named "Save Cart" near "Update Cart Button".

I have the following folder structure:

Mustard

-- SavedCart

-------Block

-----------Cart.php

Setup

---InstallSchema.php

etc

--di.xml

--module.xml

view

---frontend

-----layout

---------checkout_cart_index.xml

template

---save_cart_button.phtml

So here are the codes

Cart.php

<?php

namespace Mustard\SavedCart\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;


class Cart extends \Magento\Checkout\Block\Cart
{

    public function __construct() {

        parent::__construct();
    }


}

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Checkout\Block\Cart"
            type="Mustard\SavedCart\Block\Cart"/>
</config>

module.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mustard_SavedCart" setup_version="1.0.0">
</module>
</config>

checkout_cart_index.xml

<?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" 
        template="Mustard_SavedCart::save_cart_button.phtml"/>
</body>
</page>

save_cart_button.phtml

<form>
<button type="button" name="saveCart">
        Save Cart
</button>
</form>

now with this configuration in place when in run magento , i get a blank page at localhost/magento21/checkout/cart

Can anyone help me Please ? I need to add a button in the shopping cart page near the Update Shopping Cart button.

0

I was able to finally solve the issue. I Over rided couple of template files and blocks that were child components of \Magento\Checkout\Block\Cart block. You can find those related templates and blocks that are needed to be over rided inside the checkout_cart_index.xml file. After all this i was able to get that button on the cart page.

Thanks!

| improve this answer | |
  • can you provide the code fot Cart.php file? Thanks – Sunny Rahevar Dec 25 '18 at 11:07

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.