Question

I'm new to magento, and I'm struggling with this problem. I want to add Customize Compare Product to Customer Account Page, so i created my customize block in

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

and in my local.xml I add

<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>

It's work, but that block was called 2 times. And original compare products (one with new windows when clicked) also changed it's layout! How should I do to fix it??

Was it helpful?

Solution

The Problem was because I use same path with pop-up compare product.

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

and this code

 <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>

change pop-up compare product layout.

So, what I do here just to create new module. Create IndexController with indexAction,

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

and change some code in 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>

OTHER TIPS

Since I'm not sure what you want to achieve, I will be providing 2 different solutions:

Solution 1. If you need to remove the duplication in compare products popup window and add your own custom compare products block template, then you need to implement the following in 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>

Solution 2. If you need to add your custom compare products template block to Customer Account Dashboard page, then you need to implement the following in 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>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top