Skip to content

[5.2] Promotional pricing query methods - #3670

Merged
lukeholder merged 10 commits into
5.2from
feature/promotion-query-methods
Oct 9, 2024
Merged

lukeholder merged 10 commits into
5.2from
feature/promotion-query-methods

Conversation

@AugustMiller

@AugustMiller AugustMiller commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

Description

Adds PurchasableQuery::hasPromotionalPrice() to aid in discovering purchasables with a promotional price less than their regular price. This is designed as a replacement for the hasSales() query parameter for legacy Commerce applications.

{% set variantsWithPromotionalPrices = craft.variants()
  .hasPromotionalPrice(true) %}

{% set productsOnSale = craft.products()
  .hasVariant(variantsWithPromotionalPrices)
  .all() %}

Our Listing Products On Sale Knowledge Base article covers some DIY versions of this method—and a few advanced arithmetic queries! (I'll update this after this PR is merged.)

We've talked internally about what being “on promotion” actually means—currently, the comparisons are done against catalog pricing—but there are definitely developers and store managers who would expect that the system looks at the base prices (i.e. base price > price, or base price > promotional price), not just the fully-resolved catalog prices!

The existence of a base promotional price is a bit more challenging to detect (as far as query complexity goes), but I am pretty confident that the result would be the same… whether you check for an empty basePromotionalPrice or price = promotionalPrice would net the same results, due to the way purchasable prices are translated into the catalog pricing table (and then normalized/aggregated during the query).

@nfourtythree
nfourtythree changed the base branch from 5.x to 5.2 September 13, 2024 08:48
@nfourtythree nfourtythree changed the title Promotional pricing query methods [5.2] Promotional pricing query methods Sep 23, 2024
@lukeholder
lukeholder marked this pull request as ready for review October 9, 2024 09:46
@lukeholder
lukeholder requested a review from a team as a code owner October 9, 2024 09:46
@lukeholder
lukeholder merged commit e92bf58 into 5.2 Oct 9, 2024
@lukeholder
lukeholder deleted the feature/promotion-query-methods branch October 9, 2024 09: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.

3 participants