PHP Magento Tips

Check If Product are in Compare List and Add To Compare URL in Magento

Rate this posting:
{[['']]}

To Check your product are already added in "Add to Compare" list or not:

<?php
$_product = Mage::getModel('catalog/product')->load($id);

$compared = false;

$collection = $this->helper('catalog/product_compare')->getItemCollection();
foreach($collection as $comparing_product) {
    if ($comparing_product->getId() === $_product->getId()) {
        $compared = true;
    }
}

if ($compared == false) {
    echo Mage::helper('catalog/product_compare')->getAddUrl($_product);
}
Tag : Magento
0 Comments On "Check If Product are in Compare List and Add To Compare URL in Magento"

Back To Top