0

It doesn’t work to do an override addtocart.phtml file for configurable products, for single products it works well.

<?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>
        <css src="Module_AddCart::css/disableaddtocart.css"/>
    </head>
    <body>
        <referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Module_AddCart::catalog/product/view/addtocart.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  • I dont know where to add this – Mikel Aug 29 '19 at 18:30
  • <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart.additional" as="product.info.addtocart" template="Magento_Catalog::product/view/addtocart.phtml"/> – Mikel Aug 29 '19 at 18:30
1

try this -

First clear your var/cache folder using command

rm -rf var/cache/*.

Now check template path using path hint for both type products.

In default magento addtocart button is rendered from template file for both simple and configurable products

vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

You need to check catalog_product_view.xml layout file where template file is defined for both type of products.

In this xml, this code is used for simple products-

<block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="Magento_Catalog::product/view/addtocart.phtml"/>  

and this code is used for configurable products template file --

<block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart.additional" as="product.info.addtocart" template="Magento_Catalog::product/view/addtocart.phtml"/>

as you can see for both type of products same file addtocart.phtml is being used.

So check this xml file for your theme, might be different template file are set there for both type of products

  • ok, where i should add this in my file <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart.additional" as="product.info.addtocart" template="Magento_Catalog::product/view/addtocart.phtml"/> – Mikel Aug 29 '19 at 18:53
  • Replace the body tag by : <body> <referenceBlock name="product.info.addtocart"> <action method="setTemplate"> <argument name="template" xsi:type="string"> Module_AddCart::product/view/addtocart.phtml</argument> </action> </referenceBlock> <referenceBlock name="product.info.addtocart.additional"> <action method="setTemplate"> <argument name="template" xsi:type="string"> Module_AddCart::product/view/addtocart.phtml</argument> </action> </referenceBlock> </body> – Yassine Hassaine Aug 29 '19 at 19:04

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.