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

Promotional pricing query methods #3670

Draft
wants to merge 9 commits into
base: 5.2
Choose a base branch
from

Conversation

AugustMiller
Copy link
Contributor

@AugustMiller AugustMiller commented Sep 13, 2024

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
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.

2 participants