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>
Tags: , , , , , , ,

Post simili:

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.

One Response to “Magento add Bestseller products by date range”
  1. kobe
    08:00 on August 30th, 2011

    And look forward to reading more here, really interesting times. Thank you again for all the details.

Leave a comment

(required)

(required)


*

Categories