0

我正在尝试替换“添加到购物车”按钮的模板,但没有任何反应。

布局文件:
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>

模板文件 app/code/Plumrocket/Callforprice/view/frontend/templates/catalog/product/view/addtocart.phtml
包含来自
vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

我尝试更改product.info.addtocartproduct.info.addtocart.additional,但它仍然无法正常工作。

如果需要,这里是项目的链接

4

1 回答 1

1

看起来问题是你同时做这两个remove="true"然后设置模板。您可以删除和替换它,但最简单的方法是设置模板。假设您的 Plumrocket_Callforprice 模块已启用并且您的 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">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Plumrocket_Callforprice::catalog/product/view/addtocart.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

注意 'remove="true"' 不再包括在内

于 2018-04-05T12:50:41.770 回答