1、销售排行

protected function _beforeToHtml()
{
    $collection = Mage::getResourceModel('reports/product_collection');
    $storeId = Mage::app()->getStore()->getId();
    $collection = $this->_addProductAttributesAndPrices($collection)
        ->setStoreId($storeId)
        ->addStoreFilter($storeId)
        ->addOrderedQty()
        ->setOrder('ordered_qty', 'desc')
        ->addUrlRewrite()
        ->setPageSize(10)
        ->setCurPage(1);
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    $this->setProductCollection($collection);
    return parent::_beforeToHtml();
};

2、浏览排行

protected function _beforeToHtml()
{
    $storeId = Mage::app()->getStore()->getId();
    $products = Mage::getResourceModel('reports/product_collection')
        ->addOrderedQty()
        ->addAttributeToSelect('*')
        ->setStoreId($storeId)
        ->addStoreFilter($storeId)
        ->addUrlRewrite()
        ->addViewsCount();
    $products->setPageSize(10)->setCurPage(1);
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

    $this->setProductCollection($products);
    return parent::_beforeToHtml();
 }

3、新产品

protected function _getProductCollection()
{
    $lastmonthDated = date("Y-m-d h:i:s",strtotime("-30 day"));
    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToSelect('updated_at')
        ->addAttributeToFilter('updated_at',array("gt" => $lastmonthDated))
        ->setOrder('updated_at', 'desc')
        ->setPageSize(10)
        ->setCurPage(1);

    $this->setProductCollection($collection);
    return $collection;
 }

4、特价产品

protected function _getProductCollection()
{
    $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    $collection = Mage::getResourceModel('catalog/product_collection');
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
        ->addAttributeToFilter('special_to_date', array('or'=> array(
            0 => array('date' => true, 'from' => $todayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
        ), 'left')
        ->addAttributeToSort('special_from_date', 'desc')
        ->setPageSize(10)
        ->setCurPage(1);

    $this->setProductCollection($collection);
    return $collection;
}

results matching ""

    No results matching ""