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
  3.  
  4. $collection = $category->getProductCollection();
  5.  
  6. $collection = Mage::getResourceModel('catalog/product_collection');
  7.  
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.