Get best seller,newarrivals ,most viewed product collection

//Get most sold product collection
<?php
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$_productCollection2 = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty()
->addAttributeToFilter('visibility', $visibility)
->setOrder('ordered_qty', 'desc'); 

//Get most viewed product collection

$_productCollection1 = Mage::getResourceModel('reports/product_collection')
        ->addAttributeToSelect('*')
        ->setStoreId($storeId)
        ->addStoreFilter($storeId)
        ->addViewsCount();
        //->setPageSize($productCount);
  Mage::getSingleton('catalog/product_status')
            ->addVisibleFilterToCollection($_productCollection1);
  Mage::getSingleton('catalog/product_visibility')
            ->addVisibleInCatalogFilterToCollection($_productCollection1);


//Get newarrivals product collection
 $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    $_productCollection3 = Mage::getModel('catalog/product')->getCollection() 
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToSort('news_from_date', 'desc');

Comments

  1. its helpful thanks for posting.
    Why you used getResourceModel insteed of model?

    ReplyDelete

Post a Comment

Popular posts from this blog

Category Name with Products in Cart Page Magento

Safe name of a file by php

Sort Products by popularity count in Magento