0

I'm updating an old Magento instance from 1.7.0.2 to 1.9.2.1 (I know there is the v. 1.9.2.2).

I'm also using the Ultimo theme, but i tested the bug also with the standard RWD theme that comes with Magento 1.9.

The issue is about the add to compare button: it doesn't work. It only redirects me to the same page but it doesn't add the product to compare list.

I find out that the problem is in the addAction() function in CompareController.php

There is

public function addAction()
{
    if (!$this->_validateFormKey()) {
                $this->_redirectReferer();
                return;
            }
...
}

And $this->_validateFormKey() return FALSE so nothing is done.

Just for information, my add to compare link are looking like the following

http://example.com/catalog/product_compare/add/product/2480/uenc/aHR0cDovL3N0a25ldzE5Lmh0dGRldi5pdC9pcGhvbmUtNi1wbHVzLTE2Z2ItYmxhY2suaHRtbA,,/

At the moment, my solution is to comment the IF.

Somebody knows how to solve this problem?

EDIT:
Into the template file addto.phtml the code is the following:

...
<?php
    $_compareUrl = $this->helper('catalog/product_compare')->getAddUrl($_product);
?>
<?php if($_compareUrl) : ?>

    <li>
        <a class="link-compare feature feature-icon-hover first" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare') ?>">
            <span class="ic ic-compare ib icon-color-productview"></span>
            <span class="label"><?php echo $this->__('Add to Compare') ?></span>
        </a>
    </li>

<?php endif; ?>
...
  • I suggest you post your edit as an answer and accept it, since it seems to have solved your issue. – Julien Lachal Nov 3 '15 at 15:22
1

You will need to change compare URL in your phtml

<?php
    $_compareUrl = $this->helper('catalog/product_compare')->getAddUrl($_product);
?>

This code will give you the right compare URL for your product.

If this will not work show your phtml code which have compare link.

| improve this answer | |
  • Thanks for the answer, but my code is already this. – hippoglollum Nov 3 '15 at 11:42
  • actually compare url should be like catalog/product_compare/add/product/2480/uenc/aHR0cDovL2NjY2Rlc2t0b3AuY29tL3RlYW0vYWtoaWxlc2gvbWFnZTE5L2xhZmF5ZXR0ZS1jb252ZXJ0aWJsZS1kcmVzcy5odG1s/form_key/jHkteueHaz064EL8/ and in your case it is not adding this form_key in URL. try to debug in class Mage_Catalog_Helper_Product_Compare – Akhilesh Patel Nov 3 '15 at 12:22
  • Found!!! Thanks for the advise... I have an overload in local/ for the Mage_Catalog_Helper_Product_Compare class. – hippoglollum Nov 3 '15 at 14:38
0

I have an old overload in the local folder for the Mage_Catalog_Helper_Product_Compare Class, so it has not the new FORM_KEY feature in the function getAddUrl().

Thanks to @Akhilesh Patel

| improve this answer | |
  • great!! you can accept my answer as well if that help you :) – Akhilesh Patel Nov 4 '15 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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