Magento CE / Replace category sort by product-ID fallback

311 views Asked by At

How can the default sort-by 'ID' fallback mechanism be replaced in Magento?

When you create a custom attribute 'Used for Sorting in Product Listing' and assign it for 'Product Listing Sort by' in the catalog configuration, the custom attribute will be used as far as there are multiple products with the same value in the specified custom attribute. Then the fallback mechanism is to sort those products again by 'Position'.

Since all my products have a catalog position value = 0, the last fallback sort-by option is the product 'ID'.

My question is: how can it be accomplished to change this behaviour to sort them by ID in the end but a good choice for example could be the stock keeping unit 'SKU' or maybe also another custom created attribute.

1

There are 1 answers

0
Patrick On

In the end the solution was quite simple.

  1. All ERP products have a field 'shop-position' with default value = 0 (shop-position will be our custom attribute in Magento Used for Sorting in Product Listing) except those where we want to change the position value to something else (1,2,3 ecc.)
  2. For the Magento DB-import a conditional command like IF([shop-position] = 0, [SKU], [shop-position) does the rest.

So when the product has a value = 0, then the product SKU will be used for import, which for someone could be a better way for sorting instead of fallback sorting all products by their Magento-ID.