cancel
Showing results for 
Search instead for 
Did you mean: 

Pagination problem: Same pages showing differents products and order

Pagination problem: Same pages showing differents products and order

Hi everyone,

 

This is my first post in the forum, I have a problem with our Magento site related with pagination:

1. We have created a custom date attribute for our catalog products

2. The pagination is configured to sort the elements by default using the custom date attribute in descending mode.

3. Accessing to the section/page with pagination, when you change the pages you can see that for the same page Magento does not show the same elements in the same order.

For example, you navigate to page 4 and see the results, change to page 3 and then change back to page 4 and the elements and order are not he same than the first time.

 

I have tried the following solutions with no success:

1. Checked in System-->Catalog-->FrontEnd the two checks for use plain catalog category and use plain catalog article (with no effect after reindexing).

 

2. Tried to create an event catalog_product_collection_load_before in order to add a second sort condition when the collection is obtained, but not sure if its working or not (the pagination still working in the same way):

 

- /var/www/magento/app/etc/modules/Encamina_Ordenacion.xml:

<?xml version="1.0"?>
<config>
<modules>
<Encamina_Ordenacion>
<codePool>local</codePool>
<active>true</active>
<depends>
<Mage_Catalog />
</depends>
</Encamina_Ordenacion>
</modules>
</config>

 

- /var/www/magento/app/code/local/Encamina/Ordenacion/etc/config.xml:

<?xml version="1.0"?>
<config>
<modules>
<Encamina_Ordenacion>
<version>1.0.0</version>
</Encamina_Ordenacion>
</modules>
<global>
<models>
<encamina_ordenacion>
<class>Encamina_Ordenacion_Model</class>
</encamina_ordenacion>
</models>
</global>
<adminhtml>
<events>
<catalog_product_collection_load_before><!-- observe the event -->
<observers>
<encamina_ordenacion>
<class>encamina_ordenacion/observer</class>
<method>agregarParametroOrdenacion</method>
</encamina_ordenacion>
</observers>
</catalog_product_collection_load_before>
</events>
</adminhtml>
</config>

 

/var/www/magento/app/code/local/Encamina/Ordenacion/Model/Observer.php:

<?php

class Encamina_Ordenacion_Model_Observer {
public function agregarParametroOrdenacion($observer) {

$observer->getCollection()->addAttributeToSort('sku', 'desc');
}

}
?>

 

Not sure if everything for the event is correct, any help withs this or any additional option to solve the problem will be appreciated.

 

Thanks in advance.

 

Best regards.

2 REPLIES

Re: Pagination problem: Same pages showing differents products and order

I finally found a solution.

 

Adding a second sort parameter in the Toolbar.php file seems to solve the problem.

 

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());
$this->_collection->setOrder('sku', 'desc');
}
return $this;
}

Re: Pagination problem: Same pages showing differents products and order

Thanks a lot @jaalvarez


jaalvarez wrote:

I finally found a solution.

 

Adding a second sort parameter in the Toolbar.php file seems to solve the problem.

 

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());
$this->_collection->setOrder('sku', 'desc');
}
return $this;
}


Following has solved our problem of duplicate products on Listing pages, I had spent so much time before this but was not able to fix it. Thanks again.

$this->_collection->setOrder('sku', 'desc');