Skip to content

M2.2.6 : "Order by price" not working in product listing #18264

@kanduvisla

Description

@kanduvisla

I'm running into the issue on a Magento 2.2.6 installation the "order by price" option for a product listing is not working. Neither ascending or descending.

Preconditions

  1. M2.2.6

Steps to reproduce

I'm not sure if it is part of the conditions to reproduce the problem but:

  1. Some products have special prices with a from- and to-date or only a from-date, but most of them are regular prices.
  2. Products have fixed product taxes.

Expected result

As a customer, If I order a product listing on price, the products should be ordered on price.

Actual result

They aren't

Own research

If I look at the query that is eventually created by \Magento\Catalog\Block\Product\ListProduct::initializeProductCollection(), I get the following result:

SELECT `e`.*, 
       `cat_index`.`position`              AS `cat_index_position`, 
       `price_index`.`price`, 
       `price_index`.`tax_class_id`, 
       `price_index`.`final_price`, 
       IF(price_index.tier_price IS NOT NULL, Least(price_index.min_price, 
                                              price_index.tier_price), 
       price_index.min_price)              AS `minimal_price`, 
       `price_index`.`min_price`, 
       `price_index`.`max_price`, 
       `price_index`.`tier_price`, 
       `stock_status_index`.`stock_status` AS `is_salable` 
FROM   `catalog_product_entity` AS `e` 
       INNER JOIN `catalog_category_product_index_store1` AS `cat_index` 
               ON cat_index.product_id = e.entity_id 
                  AND cat_index.store_id = 1 
                  AND cat_index.visibility IN( 2, 4 ) 
                  AND cat_index.category_id = '26' 
       INNER JOIN `catalog_product_index_price` AS `price_index` 
               ON price_index.entity_id = e.entity_id 
                  AND price_index.website_id = '1' 
                  AND price_index.customer_group_id = '1' 
       LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index` 
              ON e.entity_id = stock_status_index.product_id 
                 AND stock_status_index.website_id = 0 
                 AND stock_status_index.stock_id = 1 
ORDER  BY `price_index`.`min_price` ASC, 
          `e`.`entity_id` DESC 
LIMIT  12 

The main thing I notice here is that it gets ordered by price_index.min_price. But if I look at my price index, min_price is set to 0 everywhere, except for the products that have a special price set.

This caused me to look at the catalog_product_price_index-table where I saw the same: almost all products have a min_price of 0, except the products that have special price set.

A bin/magento indexer:reindex or a re-save of the product does not change the price index.

So the problem might be the product listing (should it perhaps use a different column from the price index?) or should the price index have a min_price of at least the default price for regular products?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogComponent: IndexerFixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions