0

First of all thanks for your help, until now I never needed to write anything here, but I wasn't able to find any answer to this.

I have a compare list in a Magento Store and I want to compare all the items with the same 'name' attribute.

In other words, when I click to the comparison button to add the Product X, I want to see all the products with the same NAME as Product X in the comparison list.

Anyonw knows how to do that?

Thanks!

1 Answer 1

0

You can rewrite the Mage_Catalog_Product_CompareController::addAction and when a product is added add the ones with the same name.
for this you need to add this after Mage::getSingleton('catalog/product_compare_list')->addProduct($product);

$collection = Mage::getModel('catalog/product')->getCollection()
    ->setStoreId(Mage::app()->getStore()->getId())
    ->addAttributeToFilter('name', $product->getName())
    ->addAttributeToFilter('entity_id', array('neq' => $product->getId())); //exclude the product that was just added;
//get only available products
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

//get the product ids
$ids = $collection->getAllIds();
if (count($ids) > 0) {
    Mage::getSingleton('catalog/product_compare_list')->addProducts($ids);
}
1
  • Marvelous, thanks so much for your help! :)
    – Joanmacat
    Commented Nov 18, 2014 at 15:20

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.