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…)
<ul>
<?php
$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')
->addAttributeToSelect('*')
->addOrderedQty($from, $to, true)
->addAttributeToFilter('status', 1)
->setOrder('ordered_qty', 'desc')
->getSelect()->limit(10)->query();
foreach ( $_productCollection as $prod ) :
$_product = Mage::getModel('catalog/product');
$_product->load($prod['entity_id']);
($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>
</li>
<?php
endforeach;
?>
</ul>
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.



06:31 on November 14th, 2011
My battery’s about to run out underage girl
bzyl
18:46 on October 11th, 2011
I would truly enjoy reading some more, yet still I have no idea how to use php in the proper way, so I will just quit it!
03:50 on September 8th, 2011
A Second Class stamp pedo tgp
olrzyx
13:58 on September 7th, 2011
My battery’s about to run out underage girl
bzyl
04:02 on September 7th, 2011
A jiffy bag preteen galleries
6237
20:38 on September 5th, 2011
What sort of music do you like? pthc r search ygold 48991
08:00 on August 30th, 2011
And look forward to reading more here, really interesting times. Thank you again for all the details.