PHP Magento Tips

Magento get Most Viewed Products and best selling products List

Rate this posting:
{[['']]}

Magento get best selling products Collection:

Mage::getResourceModel(‘reports/product_collection’) is used to get the most ordered (Best Selling) items on the basis of ordered quantities.

$storeId    = Mage::app()->getStore()->getId();



$productsCollection = Mage::getResourceModel('reports/product_collection')

            ->addOrderedQty()

            ->setStoreId($storeId)

            ->addStoreFilter($storeId)

            ->setOrder('ordered_qty', 'desc')//This tells the most ordered products

            ->setPageSize(10);



Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productsCollection);

Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productsCollection);



foreach($productsCollection as $product){

        $productIds[] = $product->getId();

}

The above example will give you the top 10 most selling products in Magento. You can add your own filter and page size to get the collection of the product.


Magento get Most Viewed Products:

Mage::getResourceModel(‘reports/product_collection’)->addViewsCount() Collection is used to get the most viewed items.

$mostViewedProd = Mage::getResourceModel('reports/product_collection')

              ->addViewsCount()

              ->setPageSize(10);

$productIds = array();



foreach ($mostViewedProd as $product) {

   $productIds[] = $product->getId();

}

The above example will give you top 10 most viewed products.

The most interesting part in this query is its get data from 'report_event' table whose event_type_id=1 make INNER JOIN with 'catalog_product_entity' table whose entity_type_id = 4

You can check different type of event_type_id and entity_type_id from below screenshot.

report_event_type Table


eav_entity_type Table


Tag : Magento
3 Comments On "Magento get Most Viewed Products and best selling products List"

The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..
ecommerce website development company | ECommerce Development Company in Bangalore|Ecommerce Website Design and Development Company in Bangalore | Magento Development Company

Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
magento development company in bangalore 

I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Typo3, kindly contact us http://www.maxmunus.com/contact
MaxMunus Offer World Class Virtual Instructor led training on Typo3. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us:
Name : Arunkumar U
Email : arun@maxmunus.com
Skype id: training_maxmunus
Contact No.-+91-9738507310
Company Website –http://www.maxmunus.com


Back To Top