Hello All,
I like to share small code snippet to last 12 product details which are recently sold from the store.
public function getRecentlySoldItems()
{
$storeID = Mage::app()->getStore()->getId();
$itemsCollection = Mage::getResourceModel('sales/order_item_collection')
->join('order', 'order_id=entity_id')
->addFieldToFilter('main_table.store_id', array('eq'=>$storeID))
->setOrder('main_table.created_at','desc')
->setPageSize(12);
$itemsCollection->getSelect()->group(`main_table`.'product_id');
$products = array();
if(sizeof($itemsCollection)>0)
{
foreach ($itemsCollection as $item) {
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($item->getProductId());
$products[] = $product;
}
}
return $products;
}
Above function will return array of products.
I hope you will find the above code useful.
Thanks
Bijal Bhavsar 🙂