0

I am trying to replace the template for the Add To Cart button, but nothing is happening.

Layout file:
app/code/Plumrocket/Callforprice/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">
    <head>
        <css src="Plumrocket_Callforprice::css/colorcart.css"/>
    </head>

    <body>
        <referenceBlock name='product.info.addtocart' remove="true">

            <action method='setTemplate'>
                <argument name='template' xsi:type='string'>Plumrocket_Callforprice::catalog/product/view/addtocart.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Template file app/code/Plumrocket/Callforprice/view/frontend/templates/catalog/product/view/addtocart.phtml
contains content from
vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

I tried to change product.info.addtocart to product.info.addtocart.additional, but it still does not work.

If needed, here's a link to the project

  • If your theme is enabled, forget the xml and copy the contents of `vendor/.../addtocart.phtml` to `app/design/frontend/Plumrocket/Callforprice/Magento_Catalog/templates/product/view/addtocart.phtml`, then edit away – mtr.web Apr 04 '18 at 20:17
  • I need to do this exactly from the module. I can only change the files that are located in this module. – Vitaliy Kviatkovsky Apr 04 '18 at 20:47

1 Answers1

1

It looks like the problem is that you are doing both remove="true" and then setting the template. You could remove and replace it, but the easiest way is to just set the template. Assuming your Plumrocket_Callforprice module is enabled and your xml file is being parsed, it would only be a small change from what you have:

<?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="Plumrocket_Callforprice::css/colorcart.css"/>
    </head>
    <body>
        <referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Plumrocket_Callforprice::catalog/product/view/addtocart.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Note the 'remove="true"' is no longer included

mtr.web
  • 1,505
  • 1
  • 13
  • 19
  • At first I tried without it, it's just that I tried different options. But without 'remove="true"', it still does not work. – Vitaliy Kviatkovsky Apr 07 '18 at 11:39
  • 1
    In this code example, the `setTemplate` method is specifying the path to be `app/design/frontend/[Vendor]/[Theme]/Plumrocket_Callforprice/templates/catalog/product/view/addtocart.phtml`. This is also assuming that you have an activated & applied theme. You could also change it to be `app/design/frontend/[Vendor]/[Theme]/Magento_Catalog/templates/catalog/product/view/addtocart.phtml` by replacing `Plumrocket_Callforprice` with `Magento_Catalog` in the XML, but if you simply created the file in your existing theme, the XML would not be necessary for that – mtr.web Apr 09 '18 at 14:50