Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always pre-select a available variant on the product detail page #3554

Open
niklaswolf opened this issue Feb 5, 2024 · 4 comments
Open

Always pre-select a available variant on the product detail page #3554

niklaswolf opened this issue Feb 5, 2024 · 4 comments
Labels

Comments

@niklaswolf
Copy link
Contributor

PHP Version

8.2

Shopware Version

6.5.7.4

Expected behaviour

There is always a available variant selected by default on a product detail page (if there are any available).

Actual behaviour

The cheapest variant is selected by default, disregarding the availability

How to reproduce

https://github.com/shopware/shopware/blame/trunk/src/Core/Content/Product/SalesChannel/Detail/ProductDetailRoute.php#L145
This is because this is the generated SQL:

ORDER BY IFNULL((ROUND((ROUND(CAST((COALESCE((JSON_UNQUOTE(JSON_EXTRACT(`product`.`price`, "$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.gross")) + 0.0))) as DECIMAL(30, 20)), 2)) * 100, 0) / 100), (ROUND((ROUND(CAST((COALESCE((JSON_UNQUOTE(JSON_EXTRACT(`product.parent`.`price`, "$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.gross")) + 0.0))) as DECIMAL(30, 20)), 2)) * 100, 0) / 100)) ASC, `product`.`available` DESC,

If the two sortings get reversed, it works correctly.

ORDER BY `product`.`available` DESC, IFNULL((ROUND((ROUND(CAST((COALESCE((JSON_UNQUOTE(JSON_EXTRACT(`product`.`price`, "$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.gross")) + 0.0))) as DECIMAL(30, 20)), 2)) * 100, 0) / 100), (ROUND((ROUND(CAST((COALESCE((JSON_UNQUOTE(JSON_EXTRACT(`product.parent`.`price`, "$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.gross")) + 0.0))) as DECIMAL(30, 20)), 2)) * 100, 0) / 100)) ASC
@niklaswolf niklaswolf added the Bug label Feb 5, 2024
@kingschnulli
Copy link
Contributor

I think i fixed that already:

#3352

@niklaswolf
Copy link
Contributor Author

@kingschnulli not entirely in my case. As I described I have to switch order, the sortings are added to the criteria. Only after that it works correctly.
This only occurs, if the variants of a product have different prices. Then the availability-sorting is applied AFTER the price-sorting, which leaves us with a selected unavailable variant, if all variants with the cheapest price are unavailable.

@kingschnulli
Copy link
Contributor

Ah good catch, never saw that case. You can use my pr as a starting point for yours, sounds like the tests need some love here as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants