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.
I'm not sure if it is part of the conditions to reproduce the problem but:
As a customer, If I order a product listing on price, the products should be ordered on price.
They aren't
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?
Hi @kanduvisla. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento-engcom-team give me $VERSION instance
where $VERSION
is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.
@kanduvisla do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[ ] 6. Add label Issue: Confirmed
once verification is complete.
[ ] 7. Make sure that automatic system confirms that report has been added to the backlog.
I've did some more research and I found the following to trigger this bug:
min_price
to 0.0000
.min_price
to 0.0000
.So if you want to reproduce this issue:
special price from date
in the past and/or a special price to date
in the future.0.000
as min_price
, resulting in a wrongly price sorting.So the bug is probably in the indexing process.
I also tested with a special price of 0.0000
euro without any from/to date, and this also triggered the bug, although I'm not sure if this is the same bug: in my product listing and on the product detail page the regular price was shown (not 0.00 euro
), but if I added the product to the cart the special (0.00) price was used. So this was kind of misleading because I did not notice that the products had a special price of 0.00 euro, until I looked at the extremely low price of my cart.
I encountered this same issue.
Same for me.
Do you have any temporary fix for indexer?
If I look at the price indexing process, I see the following in \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Query\BaseFinalPrice::getQuery()
:
$select->columns(
[
//orig_price in catalog_product_index_price_final_tmp
'price' => $connection->getIfNullSql($price, 0),
//price in catalog_product_index_price_final_tmp
'final_price' => $connection->getIfNullSql($finalPrice, 0),
'min_price' => $connection->getIfNullSql($finalPrice, 0),
'max_price' => $connection->getIfNullSql($finalPrice, 0),
'tier_price' => $tierPrice,
]
);
If I understand this correctly, the final_price
, min_price
and max_price
are set to a default value of 0
if $finalPrice
is NULL
. Shouldn't the default value be $price
if this is the case?
$select->columns(
[
//orig_price in catalog_product_index_price_final_tmp
'price' => $connection->getIfNullSql($price, 0),
//price in catalog_product_index_price_final_tmp
'final_price' => $connection->getIfNullSql($finalPrice, $price),
'min_price' => $connection->getIfNullSql($finalPrice, $price),
'max_price' => $connection->getIfNullSql($finalPrice, $price),
'tier_price' => $tierPrice,
]
);
I did a very small local test, only with simple products, but this seems to fix the issue in my case. But then again: IMHO price indexing is one of the trickiest things in Magento and I don't feel comfortable by tinkering with it. Can anyone shine a bit more light on this?
I found the core of the problem: It's a mixup between AND
and OR
-statements in the building of the SQL-query. And even better: I also found that this has been fixed in the upcoming 2.3-branch:
https://github.com/magento/magento2/commit/14ab8ace12f0e95a476675548d0712d5ecaf9a26#diff-5a30a751305f50e9d7bbd8a2576a2b46
I'll backport this issue to the 2.2-dev branch as well and send a PR.
I've created a PR for this issue for the 2.2 branch:
Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[x] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[x] 4. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[x] 5. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[x] 6. Add label Issue: Confirmed
once verification is complete.
[x] 7. Make sure that automatic system confirms that report has been added to the backlog.
@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-95895
, MAGETWO-95896
were created
Hi @kanduvisla. Thank you for your report.
The issue has been fixed in magento/magento2#18737 by @kanduvisla in 2.2-develop branch
Related commit(s):
The fix will be available with the upcoming 2.2.8 release.
I would not create a new issue for the same problem so will re-open this one.
This issue relates to bundle price indexer as well and as I see still exists in M2.2.8
https://github.com/magento/magento2/blob/2.2/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php#L319
It affects category product sorting if there are bundle products.
PR: https://github.com/magento/magento2/pull/23056
We also have the same issue with M2.3.1
We also have the same issue in 2.2.7 even after applying the patches mentioned here
I got it working when I applied the fix mentioned by gavinlimely at https://github.com/magento/magento2/issues/7367
Most helpful comment
We also have the same issue with M2.3.1