Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 3
Custom Best Sellers Module - Finished! 
 
coug
Jr. Member
 
Total Posts:  20
Joined:  2008-06-27
 

After some research i found some codes and i have that code. Thanks to cosmicbandito for this post

I’m using the class posted by laurent.

In new.phtml rename in bestsellers.phtml i have done this hack :

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<div class="box recently">
<
h3><?php echo $this->__('Best Selling Products'?></h3>
<
table cellspacing="0" class="recently-list" id="recently-compared-list-table">
<
tr>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php
     $_categories 
$_product->getCategoryIds();
   
$_category Mage::getModel('catalog/category')->load($_categories[0]);
   
?>
    <?php 
if ($i>5): continue; endif; ?>
    
<td>
        <
div>
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img class="product-image" src="<?php echo $_product->getSmallImageUrl() ?>" width="80" height="77" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            </
a>
        </
div>
            <
p><class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
          <
p><a href="<?php echo $this->getUrl($_category->getUrlPath()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></p>
          <
div class="clear"></div>            
        </
td>
<?php $i++; endforeach; ?>
<?php 
for($i;$i%5!=0;$i++): ?>
        
<td>&nbsp;</td>
    
<?php endfor ?>
    
</tr>
</
table></div>
<?php endif; ?>

Now i have categorie name and link to the category
This functions on simple product.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Georg Ringer
Member
 
Avatar
Total Posts:  63
Joined:  2008-07-04
Linz, Austria
 

Hi,

i did a bestselling module too which is based on this code but also uses the categories! Please check out the code here and answer there: http://www.magentocommerce.com/boards/viewthread/11558/

Georg

 
Magento Community Magento Community
Magento Community
Magento Community
 
coug
Jr. Member
 
Total Posts:  20
Joined:  2008-06-27
 

there is a problem with configurabe products : the category link doesn’t function

take care : my code only function with simple product

 
Magento Community Magento Community
Magento Community
Magento Community
 
coug
Jr. Member
 
Total Posts:  20
Joined:  2008-06-27
 

i have made some tests and i don’t understand what happens. The problem is the same : i can’t get the url of configurable products.
I have discovered that this code,

$_categories $_product->getCategoryIds();
   
$_category Mage::getModel('catalog/category')->load($_categories[0]);
functions in recently viewed items.
i try to modify the class with the code of viewed.php
i obtain :
public function __construct()
    
{
        parent
::__construct();
    
$storeId    Mage::app()->getStore()->getId();

        
$products Mage::getResourceModel('reports/product_collection')
            ->
addOrderedQty()
            ->
addAttributeToSelect('*')
            ->
setStoreId($storeId)
            ->
addStoreFilter($storeId)
            ->
setOrder('ordered_qty''desc');
        
$id_toto = array();
        foreach (
$products as $toto)
        
{
            $id_toto[] 
$toto->getId();
        
}
        
        
unset($products);
        
$products null;
        if (
$id_toto{
            $products 
Mage::getModel('catalog/product')
                ->
getCollection()
                ->
addAttributeToSelect('name')
                ->
addAttributeToSelect('price')
                ->
addAttributeToSelect('small_image')
                ->
addIdFilter($id_toto)
                ->
addUrlRewrite();
            
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
            
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
            
$products->setPageSize(5)->setCurPage(1)->load();

            foreach (
$products as $product{
                $product
->setDoNotUseCategoryId(true);
            
}
        }
        $this
->setProductCollection($products);
    
}
}
but i have the same problem.

Is there someone to explain me why my code doesn’t work with configurable products and why the code of viewed.php functions ?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cosmicbandito
Jr. Member
 
Total Posts:  16
Joined:  2008-06-04
 

Hi,

try to add the attribute ‘url_key’ when you get your collection. So something like this:

->addAttributeToSelect('url_key')
 
Magento Community Magento Community
Magento Community
Magento Community
 
coug
Jr. Member
 
Total Posts:  20
Joined:  2008-06-27
 

ok i will try it as soon as possible.

 
Magento Community Magento Community
Magento Community
Magento Community
 
coug
Jr. Member
 
Total Posts:  20
Joined:  2008-06-27
 

new solution and new problem :
I solve my problem with the category path :
The problem was here : the url of the product sold was http://www.shop.com/category/name-color-1.html.
But the url find is http://www.shop.com/category/name-color-2.html. and this product wasn’t set to a category, so the url of the category doesn’t exist

Is it a bug ?.

I think the url of the product was save with the order and after the url of the product was changed.

I’m right ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kerry Hatcher
Sr. Member
 
Avatar
Total Posts:  96
Joined:  2008-07-15
Macon, GA
 

I’ll admit, I’m a bit lost on this one. Could someone PM me and lets work on an extension so we don’t have to use a hack? After the last two updates I’m really concerned about changing a lot of code.

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
PimSchaaf
Jr. Member
 
Total Posts:  13
Joined:  2008-09-08
Rotterdam
 

How is the progress going on this module/extension?

I failed creating a working module using this topic in Mage v1.1.3.

 
Magento Community Magento Community
Magento Community
Magento Community
 
John R
Sr. Member
 
Total Posts:  90
Joined:  2008-08-21
 

There already is an extension for this: http://www.magentocommerce.com/extension/reviews/module/438/p/3/

I hacked up the sidebar page and it actually works well - as far as outputting products.

It has two critical failures:

a) The logic is off. It shows products, but they are not the best selling

b) When you go to certain categories that apparently don’t have best sellers, it breaks

Who wants to work on this extension? PM me!

 
Magento Community Magento Community
Magento Community
Magento Community
 
remb
Jr. Member
 
Total Posts:  20
Joined:  2008-11-06
 
coug - 03 July 2008 03:45 AM

After some research i found some codes and i have that code. Thanks to cosmicbandito for this post

I’m using the class posted by laurent.

In new.phtml rename in bestsellers.phtml i have done this hack :

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<div class="box recently">
<
h3><?php echo $this->__('Best Selling Products'?></h3>
<
table cellspacing="0" class="recently-list" id="recently-compared-list-table">
<
tr>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php
     $_categories 
$_product->getCategoryIds();
   
$_category Mage::getModel('catalog/category')->load($_categories[0]);
   
?>
    <?php 
if ($i>5): continue; endif; ?>
    
<td>
        <
div>
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img class="product-image" src="<?php echo $_product->getSmallImageUrl() ?>" width="80" height="77" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            </
a>
        </
div>
            <
p><class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
          <
p><a href="<?php echo $this->getUrl($_category->getUrlPath()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></p>
          <
div class="clear"></div>            
        </
td>
<?php $i++; endforeach; ?>
<?php 
for($i;$i%5!=0;$i++): ?>
        
<td>&nbsp;</td>
    
<?php endfor ?>
    
</tr>
</
table></div>
<?php endif; ?>

Now i have categorie name and link to the category
This functions on simple product.

Can you please explain a bit how did you managed to use the hack? I saved laurent’s class on /app/code/local/Mage/Catalog/Block/Product/Bestseller.php (the folders were not there but I created them), then copied the code above and saved it into a file called bestsellers.php . Next, I’m calling it on my left bar in catalog.xml but nothing is happening… Please advice? Thanks a lot!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Leo27
Sr. Member
 
Total Posts:  127
Joined:  2008-10-08
 

Same problem as Rem, but calling the bestsellers from the homepage cms.
How can we use this tip since nothing is happening

best regards
L. Nunes

 
Magento Community Magento Community
Magento Community
Magento Community
 
tomislavbilic
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-17
Osijek, Croatia
 

Hello,

This article could also be of help to some of you.
http://inchoo.net/ecommerce/magento/bestseller-products-in-magento/

 
Magento Community Magento Community
Magento Community
Magento Community
 
chris_
Jr. Member
 
Total Posts:  27
Joined:  2009-03-18
 

Hello,

i’ve been looking at the different code snippets here and have made some adjustments for the new version 1.2.1.2.

I have updated bestsellers.phtml according to http://www.magentocommerce.com/wiki/upgrading_magento_themes_for_the_latest_releases#fatal_calls_to_product_helper

and then went on to look at why this does not show the configurables

in Bestsellers.php the following filter

Mage::getSingleton(’catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($products);

resturns all products visible in the shop but as a Configurable product has simple products which are not visible in shop (ie ‘Nowhere’)
these do not show.

Is there a way to get the ‘parent’ configurable product from a simple product ?

If i could adjust Bestsellers.php to something like :

-> getResourceModel
--->addVisibleFilterToCollection()
--->addVisibleInCatalogFilterToCollection --> if $_product not viisibleInCatalog try getting configurable if not exclude else include
-> setProductCollection

regards, chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
guillaume7684
Sr. Member
 
Total Posts:  241
Joined:  2008-10-20
 

Hello,

I have the same problem, I created a block with the best sellers in the home page of my website: [url=http://www.sygma-nails.com]http://www.sygma-nails.com[/url]

In this actual list I have 8 products of 10 who are some configurable products, the problem is the URL link is not correct because these products are not visible on the website.

What can I modify on my file: bestseller.phtml

Thank you so much if you can help me.

Guillaume.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 3