Magento - get a list of products that are in the comparison list

I need to get a list of products that are in the comparison list.

I have this code in phtml and it does nothing>

$collection = Mage::getModel('catalog/product_compare_list')->getCollection()->load(); foreach($collection as $product) { echo $product->getId().'<Br />'; } 

any suggestions where is the problem? thanks

+4
source share
3 answers

Try using the getItems() method to compare the list of blocks (Mage_Catalog_Block_Product_Compare_List):

 $collection = $this->getLayout()->createBlock('catalog/product_compare_list')->getItems(); foreach($collection as $product) { echo $product->getId().'<Br />'; } 
+4
source
 $collection = Mage::getModel('catalog/product_compare_list')->getCollection(); foreach($collection as $product) { echo $product->getId().'<Br />'; } 
+1
source

Use this code:

 $collection = Mage::getModel('catalog/product_compare_list')->getItemCollection(); foreach($collection as $product) { echo $product->getId().'<Br />'; } 

That should work.

+1
source

Source: https://habr.com/ru/post/1435060/


All Articles