Magento add Bestseller products by date range

Here is how to get a collection of products best sold in a given date range (could be daily, monthly, weekly, etc…)

$from = date("Y-m-d H:i:s", (time()-2592000));
$to = date("Y-m-d H:i:s", time());

$_productCollection = Mage::getResourceModel('reports/product_collection')
->addOrderedQty($from, $to, true)
->addAttributeToFilter('status', 1)
->setOrder('ordered_qty', 'desc')

foreach ( $_productCollection as $prod ) :
$_product = Mage::getModel('catalog/product');
($i%2) ? $even = "class='even-li'" : $even = "";
<li <?php echo $even ?>>
<div><a href="<?php echo $this->getUrl($_product->getUrlPath()) ?>" title="View <?php echo $_product->name ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(48); ?>" alt="<?php echo $_product->name ?>"  /></a>
<a href="<?php echo $this->getUrl($_product->getUrlPath()) ?>" title="View <?php echo $_product->name ?>"><?php echo Mage::helper('core/string')->truncate($_product->name, 50) ?></a>
<p><?php echo Mage::helper('core/string')->truncate(strip_tags($_product->description), 130); ?></p></div>

Leave a Comment