Quantcast
Viewing all articles
Browse latest Browse all 10

How to do a Best Seller Blocks

Here are codes which you can put on the block to show your best seller products.

Bestseller.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
//bestseller module - grabs from all products, returns in order of total quantity ordered
class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract
{
public function __construct()
{
parent::__construct();
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel(’reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(array(’name’, ‘price’, ’small_image’, ’short_description’, ‘description’, ‘author’))
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder(’ordered_qty’, ‘desc’);
Mage::getSingleton(’catalog/product_status’)->addVisibleFilterToCollection($products);
Mage::getSingleton(’catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($products);
//$products->setPageSize(6)->setCurPage(1);
$this->setProductCollection($products);
}
}
?>

These blocks do not represent all there is to making use of them. These should all work with “List.phtml” in the Catalog module design files, but you might want to create your own template.

The easiest way to implement these and make them usable is to add them to a Mage folder within the Local code folder (rather than core):
app/code/local/Mage/Catalog/Block/Product/Bestseller.php

This lets you skip the step of creating a custom module in order to use a simple block who’s only purpose is to list a category of products (or bestsellers in this case).

Codes from http://www.exploremagento.com


Viewing all articles
Browse latest Browse all 10

Trending Articles