1

Is it possible to add a link to the comparison page from within the confirmation that an item has been added to the compare list?

The addAction() function in app/code/core/Mage/Catalog/controllers/Product/CompareController.php is where the success message is generated. I tried adding some code in there to create the link to the compare page but I got a fatal error.

2 Answers 2

2

Quick dirty fix. at about line 93 app/code/core/Mage/Catalog/controllers/Product/CompareController.php

I added:

if ($product->getId()/* && !$product->isSuper()*/) {
//$_helper = $this->helper('catalog/product_compare');
$lin1= '<script type="text/javascript">';
$lin2 = "decorateList('compare-items')</script>";
$lin3 = '<a href="#"onclick="popWin(';
$lin4 = "'".Mage::getUrl('catalog/product_compare/index');
$lin5 = "','compare','top:0,left:0,width=820,height=600,resizable=yes,scrollbars=yes')";
$lin6 = '" >View compared products. </a>';
$house = $lin1.$lin2.$lin3.$lin4.$lin5.$lin6;
Mage::getSingleton('catalog/product_compare_list')->addProduct($product);
Mage::getSingleton('catalog/session')->addSuccess(
    $this->__('The product %s has been added to comparison list. %s', Mage::helper('core')->escapeHtml($product->getName()), $house)

I'm running magento version 1.9.2.1

1
  • Wow perfect, just what I was looking for. Great job men Commented Feb 13, 2017 at 9:52
1

The add action has the event catalog_product_compare_add_product which passes in the product object.

What you could do here is listen to this event and add a message to the session containing the url to the compare page.

Try using the following to get the url.

Mage::getUrl('catalog/product_compare/index');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.