Magento custom product collection

/ Published in: PHP
Save to your folder(s)

Copy this code and paste it in your HTML
  1. $category = new Mage_Catalog_Model_Category();
  2. $category->load(3); // this is category id
  4. $collection = $category->getProductCollection();
  6. $collection = Mage::getResourceModel('catalog/product_collection');
  8. Mage::getModel('catalog/layer')->prepareProductCollection($collection);
  9. $collection->getSelect()->order('rand()'); //this orders them randomly and is optional
  10. $collection->setPage(1,1); //this sets the number of items. set the 2nd parameter to increase the number, it is currently set as 1
  11. $_productCollection= $collection->addStoreFilter();

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.