Magento - Sort products by ID

I am trying to set up my Magento store to sort products in the order in which they were added to the catalog (by product ID). However, I could not find a good example of how to do this. This seems to be done by default in most of my product categories, but not for everyone.

I thought sorting by the “Position” option on the interface would do it, but it doesn't seem to work for all my categories. I am using community version 1.6.1.

Thanks in advance!

+4
source share
3 answers

Copy:
app/code/core/Mage/Catalog/Block/Product/List.php

(create the appropriate folder):
app/code/local/Mage/Catalog/Block/Product/List.php

Find the following line in List.php:

 $this->_productCollection = $layer->getProductCollection(); 

add the following line below:

 $this->_productCollection->joinField('category_product', 'catalog/category_product', 'product_id', 'product_id=entity_id', array('store_id'=> Mage::app()->getStore()->getId()), 'left'); // Here is the explain /* * @param string $alias 'category_product' * @param string $table 'catalog/category_product' * @param string $field 'name' * @param string $bind 'PK(product_id)=FK(entity_id)' * @param string|array $cond * @param string $joinType 'left' * * default definition * joinField($alias, $table, $field, $bind, $cond=null, $joinType='inner') * */ 

Copy
app/code/core/Mage/Catalog/Model/Config.php

in
app/code/local/Mage/Catalog/Model/Config.php

Locate the following line in the Config.php line:

 'position' => Mage::helper('catalog')->__('Position') 

Replaced by:

 $options = array( 'position' => Mage::helper('catalog')->__('Position'), 'product_id' => Mage::helper('catalog')->__('Product ID') ); 

PS: I am writing this article from home on which I do not have Magento installed on my machine, so I have not tested it, but the structure is fine. If you encounter any problem, make sure the name of the field and table.

+3
source

Just in case, someone needs: Change this:

 'product_id' => Mage::helper('catalog')->__('Product ID') 

:

 'entity_id' => Mage::helper('catalog')->__('Product ID') 
+1
source

Copy

 app/code/core/Mage/Catalog/Model/Config.php 

to

 app/code/local/Mage/Catalog/Model/Config.php 

Find the following line in Config.php :

 $options = array( 'position' => Mage::helper('catalog')->__('Position') ); 

Replaced by:

  $options = array( // 'position' => Mage::helper('catalog')->__('Position') 'entity_id' => Mage::helper('catalog')->__('Last') ); 

then change the default sort direction to descending: open app/design/frontend/your theme/your layout/layout/catalog.xml add a line

 <action method="setDefaultDirection"><dir>desc</dir></action> 

in block

 <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> <block type="page/html_pager" name="product_list_toolbar_pager"/> <!-- The following code shows how to set your own pager increments --> here </block> </block> 
+1
source

Source: https://habr.com/ru/post/1390892/


All Articles