blog site of branko ajzele, senior developer / project manager

Magento Bestseller module (Extensions)

Although I already wrote about Bestseller stuff and how to do it in Magento, here is a working module for those in need. This module was tested on Magento 1.2.1.2 and 1.3.

ActiveCodeline_Bestseller module (extension) for MAGENTO

NOTE, using a block
{{block type=”ActiveCodeline/Bestseller” template=”activecodeline/bestseller.phtml”}}

Before I get “why don’t you place this on Magento Connect” comments, let me elaborate few things first… For now I will not place any of my stuff on their site. If there is one thing that bothers me about Magento, then it’s the extensions (module) system. I’d be most happy if all modules could be transfered in one single folder making it ultra portable. I like doing some things by hand so I don’t like auto installer.

Besides, I need to refresh my site every now and then, don’t wanna loose my visitors :)

This said, I don’t wanna leave a negative impression on Magento. I use it daily. Sometimes I hate it (mostly it’s my, developers, fault) and for the most time I love it.

Keep up the great work guys and girls.

Happy Easter to those who celebrate it. Cheers.

  • Priyanka
    I am new to module development .This module is very good.I learned allot from this module..Thanks
  • rashidsahil
    A lot of thanks to give the extension.
  • n/m I figured out how to display the prices for the module by using Nightfly's suggestion by changing the code to "extends Mage_Catalog_Block_Product_Abstract". Only issue now is my ajax function isn't working for it anymore. That's ok though.
  • Hi. Love the module. its a great addition to my store. I have a question about the price thing. I'm a bit confused and would kindly like if someone could clarify a bit more on how to display prices for this module. Also do you think that this extension could be configured to display "Special Price" items? I'm trying to create a "Daily Deal" type thing for my site. Thanks in advance.
  • Omer
    we need a way to only show it on the cms page please
  • Hi Branko,
    Do you know if there is some way to filter on products actually invoiced, as opposed to ordered? This is a biggy for ourselves, as we have seasonal products, but allow people to order months in advance, so we only want to show the most recently invoiced products so people can see what is currently going out the door. Hope you can give some suggestion, Thanks...
    ... hmm would be great if the admin panel did the same thing . . .
  • jepotski
    Thanks Buddy. this module run to my website smoothly. keep posting useful idea. Rock!!!
  • al
    Add to cart and Add to wishlist does not work for me.
    Does anyone have solution?

    Please help...



    Kind Regards,
    al
  • bala123
    Hi

    Great Module..I have small doubt in this.. In home page,i want to show this module in left side..but in category page it will show in right side..pls help me

    Thanks
  • bobbrodie
    I noticed that this extension does not limit the results to the current store. I've added:
    $storeId = Mage::app()->getStore()->getId();

    and then to the product collection:
    ->setStoreId($storeId)

    but this doesn't work.

    If I add:

    $websiteId = Mage::app()->getWebsite()->getId();

    and
    ->addAttributeToFilter('website_id', $websiteId)

    An error is thrown.

    Should this be changed to catalog/product_collection?
  • daebak
    Hi Branko,
    usually I try my best for don't bother with questions that are already fixed but still I have problem with "add to cart" that just refresh the page without add anything to cart. My version is 1.3.2.4. How I can solve my problem.
    Thnx.
  • idiot.com
    http://www.magentocommerce.com/extension/570/be...

    Look , this one works to - sorry I didn't Want Waste Your Time ...
  • @idiot.com I would say the nick name suites you quite well. Please take that nap you mentioned than grab some coffee and write down the necessary code you need yourself. I have no intention wasting countless hours on idiots like you!

    To tiered? Welcome to my world. Knowledge does not fall out from sky. If you are new to Magento, I would suggest you start with Zend first.
  • idiot.com
    dear author of this code !

    can you just publish a tutorial on "how to use this"
    step by step .... I simply am to to new and to tired to dial with this in any other way
  • fourroses
    Hmm didn't see James his comment.
    /layout/activecodeline_bestseller.xml

    changed refer content to right :)
  • fourroses
    Well thought i had to install the ideal to let the bestsellers show, anyway i have it now visable.

    How to put it to the right side? I don't want to have it on to the main :Z Looked into the files but till now no succes :(
  • fourroses
    Hmm, is not showing, probably because the are no products which are sold, im still developing.

    Is there a way so i can see how it looks like?
  • alaa
    i want use this module in sidebar (left), i want to know if there is a way for show the bestseller of a specific category,
    for ex. the module must diplay the bestseller of laptops category if I went to the laptops category
  • Jimmy Jørgensen
    Hey Branko, great module and it works fine on my homepage except if I click on “Add to cart” the website refreshes and nothing happens. Any clue what the problem could be? When I use other modules and click the “Add to cart” button it redirects to the product as it should be.

    Got this problem to, and the problem with it showing in every category, and not only on the home page. Any pointers?
  • Hey Branko, great module and it works fine on my homepage except if I click on "Add to cart" the website refreshes and nothing happens. Any clue what the problem could be? When I use other modules and click the "Add to cart" button it redirects to the product as it should be.

    Here is the link: http://offroadgears.com

    I really appreciate any help!
  • Toni
    Hi,
    does this module work with product-bundles too or only with simple products?
  • bongani
    @branko

    forgive me. I'm a total n00b with magento.

    how do I create the cutom view file and am I pasting the code from the xml or html of the module?
  • @all

    For people experiencing trouble getting module to work or "appear" where they want... Why not simply grab the code from module and copy paste it into your custom (view) file then call if like you call any core/template type file. Module itself is really simple, so this should not be a problem.
  • Hi Branko thank you very much for the module, i have follow the steps and using block to show bestseller product on home page but nothing showing.

    do i have to make test order please tell me how i can make test order if from backend on which table i need to make changes Please help
  • bongani
    Hi.

    Pleae could someone post instructions on how to get the Bestseller block to display only on a single page.

    For my purposes specifically on the home page only.

    I have tried adding the block call

    {{block type=”ActiveCodeline/Bestseller” template=”activecodeline/bestseller.phtml”}}

    to the Home Page CMS, but nothing displays.

    Right now, the block is in the left column on the website. Done by changing the in bestseller.xml
    How can I get it to show in the content area, but only on the home page?

    If is in bestseller.xml, it appears on every page!

    Help
  • @all

    For all those experiencing issues with configurable products... This module was never imagined to be used for any other product type then simple one.

    @Bibo If you study the line Mage::getResourceModel('reports/product_collection') with a bit "Search all" you will find the places where it is called and defined and used (Mage_Adminhtml_Block_Dashboard_Tab_Products_Ordered) like

    $collection = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addAttributeToSelect(array('name', 'price'))
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->setOrder('ordered_qty', 'desc');

    Try playing around with adding few extra stuff to the collection.
  • Bibo
    @Jools
    It seems it doesn't work with configurable products. I've just installed the module and no products showed up. After going through the code I found the culprit :

    // Select only visible products, the one that show in our store
    $visibility = array(
    Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
    Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
    );

    ....

    ->addAttributeToFilter('visibility', $visibility)

    I commented the above addAttributeToFilter line and the products showed up. However, only the associated products did, not the main configurable product. :-( I need the main configurable product to show up.

    Any help Branko?
  • jobo13
    Many thanks for this module.

    I set up the module with success in my former template, however it doesn't work with the new one I bought, nothing is displayed.

    I don't see any cms.xml file in my new template..

    Any idea ?

    Thanks
  • I didn't take a close look at your code, but how would it handle configurable products? (where the simple products have a visibility of nowhere)? Many thanks.
  • w1ll1
    I got it to work too, but I want to Show the Products only in a single Block. I created a Categorie named Bestsellers and linked it to a static Block where I put the Block Code in, but the Bestsellers are still showing on every page. I know that this is because of the reference name="content", but how can I change this to show them only on that one page?
  • Danny
    Ah. I think I figured it out.. But 1 thing.. How can I have it appear at just the home page and on the bottom? And, how can I have it so that it has the default add to cart button?
  • Danny
    I've set everything up as instructed on this page, but it still doesn't show up on the front page...

    Could it be because of the site having only 1 test sale?

    Thanks
  • Biji
    Best seller module will keep showing on top of the page… is there any way that we can set it to show on home page only within a specific div?

    Thanks
  • Aurimas
    I dont get it .. for me also worked {{block type="bestseller/bestseller" template="activecodeline/bestseller.phtml"}}


    Branko block call doesnt work for me ...
  • Eron
    @branko
    Thanks for the response. I tried what you suggested but still had problems getting anything to display. Looks like there were a few things going on.

    I went into the logs and realized that an exception was being raised. It looks like WordPress is replacing the quotation marks in your block statement with different ones. When I copy/paste the block code the module name is incorrect and causes the block load to fail in Mage/core/Model/Layout.php. So, if I replace the quotes with double/single quotes of my own it works.

    BUT, I still get nothing to display with:

    {{block type='ActiveCodeline/Bestseller' template='activecodeline/bestseller.phtml'}}

    Replacing with a different value for type finally worked:

    {{block type='bestseller/bestseller' template='activecodeline/bestseller.phtml'}}

    Hopefully this helps anyone else who is having similar problems.
  • @Aurimas Module is so simple that it does not get any simpler than that...

    I hate Magento connect therefore I do not place my modules on Magento connect. All my modules are installed by simple un-archiving the module file you download and copy-paste to your Magento folder.

    Folder structure is set to map to appropriate folders so thats it. Copy - Paste is entire installation. If you are having issues with getting module to run (although I don't see why, since i used it several of my project and it works out of the box) then try playing with the SmallCaps variations. But keep in mind that block call I stated above in post should work.

    Hope this helps. Let me know if you sort it out. Cheers.
  • Aurimas
    {{block type=”ActiveCodeline/Bestseller” template=”activecodeline/bestseller.phtml”}} doesnt work .. works only from layout reference ://
  • Aurimas
    I cant get it working :// can someone provide details for installing this module and make it available as block from cms pages? tried various things noticed in earlier comments with no luck :/
  • @Eron... Have you read my last comment? Case sensitive :) ... use

    {{block type=”ActiveCodeline/Bestseller” template=”activecodeline/bestseller.phtml”}}
  • Eron
    Thanks for providing this module.

    I've tried using it with Magento 1.3.2.1 but I can't seem to get it to display on the home page. I've added the block to the home page through the CMS menu like you mentioned:

    {{block type=”bestseller/bestseller” template=”activecodeline/bestseller.phtml”}}

    Is there something that I am missing? I appreciate any help you can provide.
  • Le
    Hi Branko, I've to ask separate question than this. can we change that product gride column count? if that so, how?

    Thanx...
  • Yes it works on 1.3.2.

    Call the block via

    {{block type="ActiveCodeline/Bestseller" template="activecodeline/bestseller.phtml"}}
  • Jo
    Does this work for Magento 1.3.2? I added all the files from the zip, from what i can see into the correct location and added:

    {{block type=”bestseller/bestseller” template=”activecodeline/bestseller.phtml”}} and tried

    {{block type=”activecodeline/bestseller” template=”activecodeline/bestseller.phtml”}} in my CMS > manage pages, main homepage template as this is the only page i wish it to show up on.

    I purchase several items at £0.00, but nothing shows up.

    Can you point me the right direction or perhaps to another script suitable for my version?
  • Gorky,

    Here is the code to properly enable $this->getPriceHtml($product, TRUE); with *any* product collection.

    I posted this on my blog as well at http://colin.mollenhour.com/2009/06/adding-mini...

    $productIds = array_keys($_products->getItems());
    $minimalPriceModel = Mage::getResourceModel('catalogindex/price');
    $minimalPriceModel->setStoreId(Mage::app()->getStore()->getId());
    $minimalPriceModel->setCustomerGroupId(
    Mage::getSingleton('customer/session')->getCustomerGroupId());
    $minimalPrices = $minimalPriceModel->getMinimalPrices($productIds);
    foreach ($minimalPrices as $row) {
    $item = $_products->getItemById($row['entity_id']);
    if ($item) {
    $item->setData('minimal_price', $row['value']);
    $item->setData('minimal_tax_class_id', $row['tax_class_id']);
    }
    }
  • @Colin

    What makes the "->joinField(’in ..." a better version? I mean, where do we draw the line? Magento is perfectly capable of showing products out of stock (it merely shows the message out of stock on product page). Most of other client wish to show out of stock products with some special message like "will be available soon... or... call for availability". I mean, the point of bestseller module is to show bestselling products. If you are going to filter them by "in stock" why not filter them by other countless conditions. What if your 50 bestselling products happen to be out of stock at the moment customer comes to the page? Then your Bestseller module will most definitely not show top 5 bestselling products. Not to mention that one can attach literally tens of conditions on which to filter (an probably none of them would cover all the angles).
  • A better version of the above:
    ->joinField(’inventory_in_stock’,'cataloginventory/stock_item’,'is_in_stock’,
    ‘product_id=entity_id’,'{{table}}.is_in_stock=1′,’right’)
  • In my Bestsellers.php block function, I used this to filter out only the in-stock items since we didn't want out of stock items listed with our bestsellers:
    ->joinField('inventory_in_stock','cataloginventory/stock_item','is_in_stock',
    'product_id=entity_id','{{table}}.is_in_stock=1','left')
    ->addAttributeToFilter('inventory_in_stock', 1);
  • K-man
    Great module Branco - works well, however I'm still having trouble displaying it where I want to. I only want to show the bestsellers on a CMS page I have set up. I tried what Nightfly suggested - adding {{block type=”bestseller/bestseller” template=”activecodeline/bestseller.phtml”}} to the bestseller CMS content and commenting out the block in activecodline_bestseller.xml, but now it doesn't show up on my bestseller CMS page or anywhere else.
    Can someone help show me where I'm going wrong? Thanks..
  • @Nightfly

    Super... That really helps me a lot. Thank you very much! :D
  • @Nightfly Thank you for this tip. I totally overlooked that one :)
  • Hi Branco, I tried your module and it's really good. I have one suggestion: Derive the block from Mage_Catalog_Block_Product_Abstract, so that getPriceHtml() works.
  • @Sukses:
    Almost, use {{block type="bestseller/bestseller" template="activecodeline/bestseller.phtml"}}
    If you want to control the arrangement of the block, you must change the layout file. I started by removing the block from the content block in the activecodeline_bestseller.xml file so I could instead arrange it in my CMS page.
  • #pUnKs
    Thanks Nighfly .
  • After I try to place order, the bestseller product shows in all of my page the homepage and also in the product page.

    Some questions here :
    1.How can I control where it show, i.e. by utilising the {{block code?
    2.How can I remove the bestseller from the top of homepage and product page?

    Sorry for my noob questions. Thanks for your help.
  • Hi Branko, I think this is a great extension.

    I'm pretty noobs in magento. I want to show the bestseller block in my homepage cms, I use the code :

    {{block type="activecodeline/bestseller" template="activecodeline/bestseller.phtml"}}

    It's no luck. It shows nothing on the homepage. Please shed some light.
  • Is there a way to make this relative to the category that you are currently viewing?

    For example it only shows the best selling products from the laptop category if that is what you are currently viewing.
  • Branko, nice work on this - and also your price post was also useful for other issues.

    AprilCherrie.. it displays on all pages as the layout xml file has sent the block to display under the main content block which is on all pages... to move it, just change the block it refers to in layout/activecodeline_bestseller.xml .. for example I have mine displaying in the right side bar on most pages... i changed to reference=right instead of reference=content.

    Cheers,
  • hi, just realize that the best seller module will keep showing on top of the page... is there any way that we can set it to show on home page only?

    Thanks
  • oh.. i got it d... Thanks :)
  • hi,

    I'm really new to magento.. have no idea how to install this best seller module.. can anyone help?
  • @Damu

    Here is special little post for your issue http://activecodeline.com/magento-price-helper-...

    Hope it helps.
  • tried this:

    helper('catalog/product')->getPriceHtml($_product, true) ?>

    but no joy.
  • sorry, what does mage product price helper code looks like? stucked with price display, everything works. Hope to get help. Thanks.
  • joe
    Thank you. It works very well in 1.3.1!!!
  • joe
    Have you tested it with 1.3.1?

    All the functions will work? Including all the types of products?

    Thanks in advance.
  • Bizz
    hi,

    i'm very new to magento and i can't work out what i need to put in the block call to get this to work.

    I have tried copying other block calls but i am at a loss.

    Thank you for your help
  • $this->getPriceHtml($_product, true) wont work. Use the Mage product price helper to manually construct price from $product objects price property.
  • Raja
    Hi,
    i have an issue with magento v1.2.1.2
    "as low as" price in product listing along with search results would disappear after 24 hours of adding tier prices in product in admin.
    the following code is used in file list.phtml :
    echo $this->getPriceHtml($_product, true)
    it can show special price but disappears the tier price after 24 hours
    could u plz help me on this !!
  • Hej,

    Could you please help me with another problem. Somehow prices in your modul are not shown. As far as I digged in function getPriceHtml() is never called although I call it with $this->getPriceHtml($_product, true) in bestseller.phtml.

    Gorky
  • edit: I got it. Thanks and keep up the good work!
  • I'm kinda new to Magento, so what do I write in type/name/template attribute of block?
  • Hello Branko,

    Congrats on great work you doing here.

    Can you please write how to use your module on home page with a block call?

    Lep pozdrav,
    Gorky
  • Open the cms.xml inside theme layout folder, then add the block call to the appropriate place. This way you do not need to add the block call to Administration > CMS > Manage Pages. Hope this is what you had in mind.
blog comments powered by Disqus
Powered by Wordpress | Designed by Elegant Themes