Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to get the best sellers module to show the overall bestsellers? 
 
Emperor
Sr. Member
 
Total Posts:  111
Joined:  2007-08-31
 

I have installed the best sellers module (Los mas vendidos), but this shows the best sellers for all categories and not the overall bestsellers.

The code is as follows. Can someone help me customize it.

I need to show the ovrall bestsellers for the entire website.

class Mage_Catalog_Block_Product_Bestsellers extends Mage_Catalog_Block_Product_Abstract
{
    
public function __construct()
    
{
        parent
::__construct();
        
/* 
            Set the collection all categories in the store 
        */
        
$this->setProductCollection(Mage::helper('catalog/category')->getStoreCategories('order'truefalse));
    
}

    
public function getBestsellers($category=NULL,$perPage=NULL,$currentPage=1){
        
if(!get_class($category) === 'Mage_Catalog_Model_Category') return;
        
/* 
            Always set de $perPage, by template or by config 
            if $perPage eq 0 (zero) not limit the list
        */
        
if($perPage === NULL$perPage    = (int) Mage::helper('bestsellers/data')->getQty();
        
        
/*
            Show all the product list in the current store
            order by ordered_qty, showing the bestsellers first
        */
        
$storeId Mage::app()->getStore()->getId();
        
$products Mage::getResourceModel('catalog/product_collection')
            ->
setStoreId($storeId)
            ->
addAttributeToSelect('*')
            ->
addStoreFilter($storeId)
            ->
setOrder('ordered_qty''desc');
        
//Adrian: I commented out the line below. 
        //$products->addCategoryFilter($category);
        
        /*
            Filter list of product showing only the active and 
            visible product
        */
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);

        
$products->setPageSize($perPage)->setCurPage($currentPage);
        
        return 
$products;
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Mmmm I have some code for this that worked for me. I believe I got it from this thread:

Might want to try a search

This thread looks promising:
http://www.magentocommerce.com/boards/viewthread/9058/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top