Magento - Sort by position and name?

Is it possible to sort by A position, and then B these products in alphabetical order.

I have new products and products for sale included in the category, and they show all new and then all sales.

But I need to sort it by name.

+4
source share
4 answers

In admin

Go to the "Category Management" section, select a category, then on the "Products" tab specify each item number. They will be sorted according to this order.

Program

You can do this by calling the addAttributeToSort collection addAttributeToSort for each order.

For example, wherever you see $_category->getProductCollection() or $_product->getCollection() in the template, you can add ->addAttributeToSort('position')->addAttributeToSort('name') right after it.

addAttributeToSort() also takes direction as the second parameter, so you can either addAttributeToSort('name', 'asc') or addAttributeToSort('name', 'desc') .

+14
source

The best way to get around this without changing the main files is to copy the Toolbar.php file located:

 /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php 

then create a new directory path (if you did not create one):

 /app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php 

Now replace the following from line 232:

  if ($this->getCurrentOrder()) { $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); } 

to

 if ($this->getCurrentOrder()) { if(($this->getCurrentOrder())=='position'){ //defines the sort option //sort by position (ascending) and entity_id (descending) $this->_collection->addAttributeToSort('position','asc')->addAttributeToSort('entity_id','desc'); } else { $this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection()); } } 

Finally, reindex and update the cache on your Magento backend and is ready to go. If you need to define more than one instance of the sort option and paste the code below immediately before} else {

 if(($this->getCurrentOrder())=='######'){ //defines the sort option //sort by ###### (ascending) and ###### (descending) $this->_collection->addAttributeToSort('######','asc')->addAttributeToSort('######','desc'); 
+3
source

Instead of coding, you can do it by the administrator. Go to your admin panel Go to system ---> Configuration and select a directory from the left tab.

Then click the Fronend tab on the right. Go to the "Product Limit" section. Sort and select "Name" from the drop-down menu and save the configuration.

Make sorting relatively easy. There is an expansion in the purple market. This extension will help you drag the products into place according to our desire. I have provided an extension link below

http://www.magentocommerce.com/magento-connect/product-sorting-sequence-drag-and-drop.html

0
source

In response to clockworkgeek,

A product may have several attributes. When you assign one item to each product, it refers to 1 attribute. In addition, you will need to determine a position for each product.

The problem is that the drop-down list on the product page offers you the option to select one of several attributes. For instance:

Size: S, M, L, XL

When you select an attribute, the default is to sort this attribute in alphabetical order, which makes no sense (L, M, S, XL). Instead, I would like to use the same position of the option attribute (s = 1, m = 2, l = 3, xl = 4) for sorting.

I get the impression that this could be done by completing the merge and order in the Magento collections. Do you know how to get these values ​​or sort them like that?

0
source

All Articles