Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. class Company_Bestseller_Block_Bestseller extends Mage_Catalog_Block_Product_Abstract
  4. {
  5. public function getBestsellerProducts()
  6. {
  7. $storeId = (int) Mage::app()->getStore()->getId();
  8.  
  9. $date = new Zend_Date();
  10. $toDate = $date->setDay(1)->getDate()->get('Y-MM-dd');
  11. $fromDate = $date->subMonth(1)->getDate()->get('Y-MM-dd');
  12.  
  13. $collection = Mage::getResourceModel('catalog/product_collection')
  14. ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
  15. ->addStoreFilter()
  16. ->addPriceData()
  17. ->addTaxPercents()
  18. ->addUrlRewrite()
  19. ->setPageSize(5);
  20.  
  21. $collection->getSelect()
  22. ->joinLeft(
  23. array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
  24. "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
  25. array('SUM(aggregation.qty_ordered) AS sold_quantity')
  26. )
  27. ->group('e.entity_id')
  28. ->order(array('sold_quantity DESC', 'e.created_at'));
  29.  
  30. Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
  31. Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
  32.  
  33. return $collection;
  34. }
  35. }
  36.  
  37. <?php foreach ($this->getBestsellerProducts() as $_product): ?>
  38. <?php if($_product->getRatingSummary()): ?>
  39. <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
  40. <?php endif; ?>
  41. <?php endif; ?>
  42.  
  43. Mage::getModel('review/review')->appendSummary($collection);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement