1

I want to check if any variants (not the default variant) have any active sales applied. How can I do this at a product level when looping through products (think teasers).

1

So the only way I could seem to make this work was as follows:

{% set onSale = product.variants|filter(v => v.onSale())|length %}

{% if onSale %}
   code here for sales badge/message etc
{% endif %}

Not sure if there is a more direct method? If there is please let me know...

1

the following query possibly produce the similar result

{% set variantsHasSales = craft.variants()
    .product(product)
    .hasSales(true)
    .all() 
%}
{% if variantsHasSales|length > 0 %}
  code here for sales badge/message etc
{% endif %}

reference : https://craftcms.com/docs/commerce/3.x/products-variants.html#variant-hassales

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.