我是magento的新手,我正在努力解决这个问题。我想添加自定义比较产品到客户帐户页面,所以我创建了我的自定义块

\template\catalog\product\compare\mycompare.phtml

在我的地方。xml我添加

<action method="addLink" translate="label" module="catalog">
     <name>catalog.compare.list</name>
     <path>index.php/catalog/product_compare/index/</path>
     <label>My Compare</label>
</action>

<catalog_product_compare_index>
        <label>Catalog Product Compare List</label>
        <!-- Mage_Catalog -->
        <update handle="customer_account"/>
        <reference name="my.account.wrapper">
        <block type="catalog/product_compare_list" name="catalog.compare.list" template="catalog/product/compare/mycompare.phtml"/>
        </reference>
</catalog_product_compare_index>

这是工作,但那个街区被叫了2次。和原来的比较产品(一个与新的窗口点击时)也改变了它的布局!我该怎么做才能修复它??

有帮助吗?

解决方案

问题是因为我使用相同的路径与弹出比较产品。

<path>index.php/catalog/product_compare/index/</path>

而这段代码

 <catalog_product_compare_index>
        <label>Catalog Product Compare List</label>
        <!-- Mage_Catalog -->
        <update handle="customer_account"/>
        <reference name="my.account.wrapper">
        <block type="catalog/product_compare_list" name="catalog.compare.list" template="catalog/product/compare/mycompare.phtml"/>
        </reference>
</catalog_product_compare_index>

更改弹出式比较产品布局。

所以,我在这里做的只是为了创建新的模块。创建 IndexControllerindexAction,

public function indexAction() {
        $this->loadLayout();
        $this->getLayout()->getBlock('head')->setTitle($this->__('My Compare'));
        $this->renderLayout(); 
}

并更改一些代码 local.xml:

<action method="addLink" translate="label" module="mycompare">
     <name>mycompare</name>
     <path>mycompare/index</path>
     <label>My Compare</label>
</action>

<mycompare_index>
        <label>Catalog Product Compare List</label>
        <!-- Mage_Catalog -->
        <update handle="customer_account"/>
        <reference name="my.account.wrapper">
        <block type="catalog/product_compare_list" name="mycompare" as="mycompare" template="catalog/product/compare/mycompare.phtml"/>
        </reference>
</mycompare_index>

其他提示

由于我不确定您想要实现什么,我将提供2种不同的解决方案:

解决方案1。 如果您需要删除比较产品弹出窗口中的重复,并添加您自己的自定义比较产品块模板,那么您需要在 local.xml:

<catalog_product_compare_index>
        <update handle="customer_account"/>

        <reference name="content">
            <action method="unsetChild"><name>catalog.compare.list</name></action>
        </reference>            

        <reference name="my.account.wrapper">
            <block type="catalog/product_compare_list" name="catalog.compare.list" template="catalog/product/compare/mycompare.phtml"/>
        </reference>
</catalog_product_compare_index>

解决方案2。 如果您需要将自定义比较产品模板块添加到客户帐户仪表板页面,那么您需要在 local.xml:

<customer_account_index>

    <reference name="my.account.wrapper">
        <block type="catalog/product_compare_list" name="catalog.compare.list" template="catalog/product/compare/mycompare.phtml"/>
    </reference>

</customer_account_index>
许可以下: CC-BY-SA归因
scroll top