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

Products repeated in category view when sorting by Brand, Price, etc. 
 
eliacimd
Jr. Member
 
Total Posts:  6
Joined:  2012-11-09
 

Hi everybody.

I wanted to see if anyone else has thought this curious case, which I think is a bug, beacuse all tasks involving this point directly are made by the core of Magento. I will try to be as clear as possible, because itself is something confused, even for me, and I do not speak very good English. Be patient, please.

The thing is this: We are currently handling a store with a considerably high volume products (we currently have more than 21,000), and the category view is sorted descendent by the products’ entity_id by default, such that products with the largest ID go to the top of the category (so, the newest). To do this, I add this in local.xml:

<catalog_category_layered
    <
reference name="product_list_toolbar">
            <
action method="setDefaultDirection"><string>desc</string></action>
    </
reference>
</
catalog_category_layered>

And to “force” it to take the entity_id by default, I override the method Mage_Catalog_Block_Product_List_Toolbar::getCurrentOrder

public function getCurrentOrder()
{
    $order 
$this->_getData('_current_grid_order');
        if (
$order{
            
return $order;
        
}

        $orders 
$this->getAvailableOrders();
        
$defaultOrder 'entity_id';

        
$order $this->getRequest()->getParam($this->getOrderVarName());
        if (
$order && isset($orders[$order])) {
            
if ($order == $defaultOrder{
                Mage
::getSingleton('catalog/session')->unsSortOrder();
            
else {
                $this
->_memorizeParam('sort_order'$order);
            
}
        } 
else {
            $order 
Mage::getSingleton('catalog/session')->getSortOrder();
        
}
        
// validate session value
        
if (!$order || !isset($orders[$order])) {
            $order 
$defaultOrder;
        
}
        $this
->setData('_current_grid_order'$order);
    return 
$order;
}

So far everything works well, it shows you the category, shows the products in the order I want, etc. But, the user has the option to order the products by name, brand, model and price. Model and name don’t have problem, but when he sort by price or brand, is where the problem arises: some products appear repeated between pages. For example: I enter to the category, page 1, limited 15 for page, and sorted by brand. It shows 15 different products sorted correctly. But, passing to page 2, however, sometimes you get to show 3, 4 or even more products that you already had repeatedly shown on page 1. And if you go to page 3, the same occurs, showing you products that had already shown on page 2, or sometimes even the 1.

I was watching and trying and trying, and I realized that this problem arises only in brand and price when there are many products with the same brand or price (which gives much the case in this store). If more than 15 products, for example, have the same brand, tend to repeat from one page to another. I do not understand how or why this happens, but the final collection of 15 products to be displayed on the page, proceeds directly from the method Mage_Catalog_Block_Product_List_Toolbar::setCollection

public function setCollection($collection)
{
    $this
->_collection $collection;

        
$this->_collection->setCurPage($this->getCurrentPage());

        
// we need to set pagination only if passed value integer and more that 0
        
$limit = (int)$this->getLimit();
        if (
$limit{
            $this
->_collection->setPageSize($limit);
        
}
        
if ($this->getCurrentOrder()) {
            $this
->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        
}
        
        
return $this;
}

In other words, this method returns the collection to me with the repeated products. I did not change anything in this collection, so that means that the sorted is directly does by the core.

I know that is half confusing to understand, but in short this is happening to me, I get repeated products from one page to another when they are sorted by an attribute in which many products have the same value (eg brand or price). Does anyone else happened something similar?, Do you know if it is some kind of bug, or does know how is that Magento does this sorted?, As it seems that does not do a simple “ORDER BY x LIMIT Y, Z” as even I get the products in different order when I refresh the page.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top