Monday 8 July 2013

Magento - How to get all products collection from a particular category id in magento


- To get all products collection from a particular category id ,


$categoryId = 10;// category id as 10.
$category = Mage::getModel('catalog/category')->load($categoryId);

$storeid = 1;
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('price')
->addAttributeToSelect('special_price')
->addAttributeToSelect('name')
->addAttributeToSelect('short_description')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->addAttributeToSelect('image')
->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
$collection->setStoreId($storeid);

$collection->joinAttribute('product_title', 'catalog_product/name', 'entity_id', null, 'inner', $storeid);
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $storeid);
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $storeid);
$collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $storeid);

$_products = $collection->addCategoryFilter($category);

foreach($_products as $_product)

{
       echo $_product->getName();
       echo $_product->getProductUrl();
}

4 comments:

  1. Hi Ravi,

    How to delete orders of particular user/customer in Magento?

    ReplyDelete
    Replies
    1. Hi
      Please refer my Latest Post.
      http://ravichandranjothi.blogspot.in/2013/07/magento-how-to-delete-particular-orders.html

      Delete
  2. Hi,

    This is Awesome post.. Great Thank you very much for sharing..

    Web Development India | Wedding Websites

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete