1

I need little help,I am trying to override vendor\magento\module-catalog\view\frontend\templates\product\view\addtocart.phtml but no luck

I am using Magento 2.1 version.

I tried below code in my module file location: Myvendor1_Module1/view/frontend/templates/catalog/product/view/addtocart.phtml

Layout file: catalog_product_view

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
       <referenceBlock name="product.info.addtocart">
           <action method="setTemplate">
            <argument name="template" xsi:type="string">Myvendor1_Module1::catalog/product/view/addtocart.phtml</argument>
           </action>
       </referenceBlock>
   </body>
</page>

I already cleared cache, generation folder and as well as flush cache but it cannot override addtocart.phtml template file.

Edit: My module is fine working and it is enabled. Please help

3

Try this out in

Myvendor1_Module1/view/frontend/layout/catalog_product_view.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">
    <body>        
        <referenceContainer name="product.info.form.content">
            <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="Myvendor1_Module1::catalog/product/view/addtocart.phtml"/>
        </referenceContainer>  
    </body>
</page>
  • Magento 2.1.17 - Override product option select.phtml file.(Not block file only phtml file) Any idea? – Emipro Technologies Pvt. Ltd. Apr 23 '19 at 9:23
0

To override addtocart.phtml template file in your module use below code

1. Create file catalog_product_view.xml in the directory path Vendor_Module/view/frontend/layout and add below code.

    <?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">
        <body>        
            <referenceContainer name="product.info.form.content">
                <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="Vendor_Module::catalog/product/view/addtocart.phtml"/>
            </referenceContainer>  
        </body>
    </page>

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.