0

Is there any way to select only product Id for compare items in collection Like:

$compare = Mage::helper('catalog/product_compare')->getItemCollection();
$compare_product = array();
$compareList = '';
foreach ($compare as $product) {
    $compareList .= $product->getId();
    $compare_product[] = $product->getId();
}

instead:

$compare = Mage::helper('catalog/product_compare')->getItemCollection()->addAttributeToSelect('product_id');
  • Please elaborate more about your question. – Rohan Hapani Aug 27 at 10:43
  • Did you checked addFieldToFilter( instead of addAttributeToFilter(? – Arif Ahmad Aug 27 at 10:45
  • @ArifAhmad, yes nothing changed, When I print query, It show multiple column selected – Yogita Aug 27 at 11:24
  • Can you try this : $compare = Mage::helper('catalog/product_compare')->getItemCollection(); $productIdsCollection = $compare->addAttributeToSelect('product_id'); I don't have a M1 setup so can't see what is going wrong but this should technically work. I believe you have attribute - product_id – Arif Ahmad Aug 27 at 11:49
  • No difference, Still show the same, I already applied the same. You can see in my question. – Yogita Aug 27 at 11:55

Your Answer

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

Browse other questions tagged or ask your own question.