Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I have an empty collection and a list of productIDs. I want to populate the collection with products specified by the IDs in the list. How would I do this?

share|improve this question
up vote 2 down vote accepted

If you want to prepare a "Collection" if you have product ID's then this should be fine.

Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('entity_id', array('in' => array(OF_YOUR_PRODUCTIDS)));

In this way you can get the "collection" object, just query it using those IDs.

share|improve this answer

This is what I did:

// Get array of IDs from cookie
$productIds = explode(';', Mage::helper('customcompare/cookieAccess')->readCookie());

// Add products to collection
$count=0;
foreach ($productIds as $productId) {
    $newProduct = Mage::getModel('catalog/product')->load($productId);
    $collection[$count] = $newProduct;
    $count = $count + 1;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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