`
kirenenko04
  • 浏览: 152197 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Best Selling

 
阅读更多

 

/*Get overall Bestselling products*/
public function getBestsellingProducts()
{  
    // number of products to display
    $productCount = 5;
     
    // store ID
    $storeId    = Mage::app()->getStore()->getId();      
     
    // get most viewed products for current category
    $products = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')     
                    ->addOrderedQty()
                    ->setStoreId($storeId)
                    ->addStoreFilter($storeId)                  
                    ->setOrder('ordered_qty', 'desc')
                    ->setPageSize($productCount);
     
    Mage::getSingleton('catalog/product_status')
            ->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')
            ->addVisibleInCatalogFilterToCollection($products);
     
    return $products;
}

/*Get Bestselling products for current category*/
public function getBestsellingProducts()
{  
    // number of products to display
    $productCount = 5;
     
    // store ID
    $storeId    = Mage::app()->getStore()->getId();      
     
    // get most viewed products for current category
    $products = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')     
                    ->addOrderedQty()
                    ->setStoreId($storeId)
                    ->addStoreFilter($storeId)
                    ->addCategoryFilter(Mage::registry('current_category'))
                    ->setOrder('ordered_qty', 'desc')
                    ->setPageSize($productCount);                    
     
    Mage::getSingleton('catalog/product_status')
            ->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')
            ->addVisibleInCatalogFilterToCollection($products);
     
    return $products;
}

/*Get Bestselling products for last 30 days*/
public function getBestsellingProducts()
{  
    // number of products to display
    $productCount = 5;
     
    // store ID
    $storeId    = Mage::app()->getStore()->getId();
 
    // get today and last 30 days time
    $today = time();
    $last = $today - (60*60*24*30);
 
    $from = date("Y-m-d", $last);
    $to = date("Y-m-d", $today);
     
    // get most viewed products for current category
    $products = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')     
                    ->addOrderedQty($from, $to)
                    ->setStoreId($storeId)
                    ->addStoreFilter($storeId)                  
                    ->setOrder('ordered_qty', 'desc')
                    ->setPageSize($productCount);
     
    Mage::getSingleton('catalog/product_status')
            ->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')
            ->addVisibleInCatalogFilterToCollection($products);
     
    return $products;
}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics