I want to have several products on my homepage which are my best sellers or most viewed? Is it possible to do this so that it automatically updates depending on what is selling the best or viewed the most. How do I go about it??
there’s a thread hanging around somewhere that has a bestsellers module, but I’ll post the code I was successfully able to use to get “bestsellers” (based on that thread)- not sure about the “most viewed” part (altho if magneto keeps track of that metric, it would be easy to get)
This is the Model class you would use to get Bestsellers:
<?php class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract { public function __construct() { parent::__construct();
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() //->addAttributeToSelect('*') ->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description')) //edit to suit tastes ->setStoreId($storeId) ->addStoreFilter($storeId) ->setOrder('ordered_qty', 'desc'); //best sellers on top
Whoa, 3 weeks ago. I should start clicking the “Notify me via email” button....
OK, here is what I would do - you don’t need to declare a custom module for this (for the sake of simplicity)
The code above goes in “Bestseller.php”
app/code/local/Mage/Catalog/Block/Product/Bestseller.php
You then need a template to use.
I modified a stock Magento file (copied it and edited it)
app/design/frontend/*/*/template/catalog/product/bestseller.phtml
I used something like this:
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?> <div class="home-page-cntr"> <?php $i=0; foreach ($_products->getItems() as $_product): ?> <?php if ($i>5): continue; endif; ?>
To use this code, you need to add the block somewhere, either via XML or in a CMS page like your home page:
To use in a CMS page, use this where you enter your content - use it where you want to this item to show up!:
If you look in the admin you will see that best sellers and Most Viewed are in the same format. maybe you just need to change the “Bestseller “ to “Most Viewed”
I managed it so that the products appear on the front page. what are the creteria that the products appear in this section?
and how do I set the outcome into a table so that everything is sorted? I also would like to delete the product information there. Just want to see the name and the price.
Can anybody help? I’m just into html and got no php skills.... yet..