Skip to content

Fixed ordering purchasable queries by salePrice - #4448

Merged
lukeholder merged 1 commit into
6.xfrom
bugfix/com-668-purchasable-price-ordering
Nov 11, 2026
Merged

lukeholder merged 1 commit into
6.xfrom
bugfix/com-668-purchasable-price-ordering

Conversation

@lukeholder

Copy link
Copy Markdown
Member

Variant::find()->orderBy('salePrice') didn't sort anything when there were no catalog pricing rules. PurchasableQuery doesn't select salePrice (it's a read-only attribute on the element), so ORDER BY "salePrice" didn't name a real column. SQLite treats that as a string literal and returns rows unsorted; MySQL and Postgres would error.

QueriesPurchasablePricing now rewrites price, promotionalPrice and salePrice order clauses in its beforeQuery callback, before cms resolves the query's order columns:

  • With catalog pricing rules: catalogprices.price, catalogprices.promotionalPrice and catalogprices.salePrice.
  • Without: purchasables_stores.basePrice, basePromotionalPrice, and the same CASE WHEN sale price expression the salePrice() filter already uses (moved into a shared helper).

The new tests give the most expensive variant a promotional price, so a sort that does nothing can't pass. The salePrice cases fail without this change. Closes COM-668.

🤖 Generated with Claude Code

@lukeholder
lukeholder requested a review from a team as a code owner November 11, 2026 13:42
@linear-code

linear-code Bot commented Nov 11, 2026

Copy link
Copy Markdown

COM-668

@lukeholder
lukeholder merged commit 2f442a3 into 6.x Nov 11, 2026
7 checks passed
@lukeholder
lukeholder deleted the bugfix/com-668-purchasable-price-ordering branch November 11, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant