5

I have develop custom module that can update add to cart and update cart button but I can`t update Update cart button

I have update Add to Cart button using catalog_product_view.xml

<referenceBlock name="product.info.addtocart">
      <action method="setTemplate">
          <argument name="template" xsi:type="string">Vendor_Customproduct::catalog/product/view/addtocart.phtml</argument>
      </action>
    </referenceBlock>

    <referenceBlock name="product.info.addtocart.additional">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Vendor_Customproduct::catalog/product/view/addtocart.phtml</argument>
        </action>
    </referenceBlock>

I have try to update update cart button using 'checkout_cart_configure.xml'

I want to Over write template

\vendor\magento\module-checkout\view\frontend\templates\cart\item\configure\updatecart.phtml

So I have create

app\code\Vendor\Customproduct\view\frontend\layout\checkout_cart_configure.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">
    <head>
        <link src="Magento_Checkout::js/view/configure/product-customer-data.js"/>
    </head>
    <update handle="catalog_product_view"/>
    <body>
        <referenceBlock name="head.components">
            <block class="Magento\Framework\View\Element\Js\Components" name="checkout_cart_configure_head_components" template="Magento_Checkout::js/components.phtml"/>
        </referenceBlock>
        <referenceBlock name="product.info">
            <block class="Magento\Checkout\Block\Cart\Item\Configure" name="checkout.cart.item.configure.block"/>
        </referenceBlock>
        <referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Customproduct::cart/item/configure/updatecart.phtml</argument>
            </action>
        </referenceBlock>
        <referenceBlock name="product.info.addtocart.additional">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Customproduct::cart/item/configure/updatecart.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

app\code\Vendor\Customproduct\view\frontend\templates\cart\item\configure\updatecart.phtml

<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Update Cart'); ?>
<?php if ($_product->isSaleable()): ?>
    <div class="box-tocart update">
        <fieldset class="fieldset">
            <?php if ($block->shouldRenderQuantity()): ?>
            <div class="field qty">
                <label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
                <div class="control">
                    <input type="number"
                           name="qty"
                           id="qty"
                           value=""
                           title="<?= /* @escapeNotVerified */ __('Qty') ?>"
                           class="input-text qty"
                           data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
                </div>
            </div>
            <?php endif; ?>
            <div class="actions">
                <button type="submit"
                        title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
                        class="action primary tocart"
                        id="product-updatecart-button">
                    <span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
                </button>
                <?= $block->getChildHtml('', true) ?>
            </div>
        </fieldset>
    </div>
    <script type="text/x-magento-init">
        {
            "#product_addtocart_form": {
                "validation": {},
                "addToCart": {
                    "cartButtonId": "#product-updatecart-button",
                    "cartForm": "#product_addtocart_form"
                }
            }
        }
    </script>
    <script>alert('i am here');</script>
<?php endif; ?>

enter image description here

But There is no changes

So If You have any solution then Please help

5
  • what type of updation you want to make in update cart button ?? Mar 25, 2019 at 6:57
  • I want to overwrite tamplate \vendor\magento\module-checkout\view\frontend\templates\cart\item\configure\updatecart.phtml Mar 25, 2019 at 6:59
  • can you please check my answer and let me know if issue resolved Mar 25, 2019 at 7:04
  • can you include which button are you trying to update? I mean a screenshot is much better.
    – fmsthird
    Mar 25, 2019 at 8:16

3 Answers 3

2

For customization on the Update cart button.Please follow this link it is worked great:

How to override the checkout_cart_configure.xml template file into custom module

Thank you.

0

As per your comments if you only want to override

\vendor\magento\module-checkout\view\frontend\templates\cart\item\configure\updatecart.phtml

This can be done by creating same file in your theme at:

/app/design/frontend/Namespace/Theme/Magento_Checkout/templates/cart/item/configure/updatecart.phtml

Try this:

As you did for addtocart using catalog_product_view can you try using "checkout_cart_configure" originally at /vendor/magento/module-checkout/view/frontend/layout/checkout_cart_configure.xml

Create a new in your module and change argument same as you did for add to cart, see original vendor for reference.

Let me know if any issue

8
  • here i am develop only Extension not a theme so provide solution for this if u have Mar 25, 2019 at 7:09
  • please check my updated answer if it works for you Mar 25, 2019 at 7:21
  • i have test it but there is no changes you can see my update on this question Mar 25, 2019 at 7:23
  • do all setup upgrade, di compile, cache flush Mar 25, 2019 at 7:23
  • 1
    i have run all commands Mar 25, 2019 at 7:24
0

As per the image attached, I can confirm that your code is right.
However, you will not be able to see or notice the changes unless you try to change the characters in this line (in your updatecart.phtml):

<?php $buttonTitle = __('Update Cart'); ?>  

or by inspecting it in your browser. And you will find the classes present in your .phtml file.
From there, you will be able to see that your override is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.