Tags active products with 'on-sale' when any variant has a compare-at price above its current price, and removes the tag when nothing is discounted.
async def run(ctx): for product in await ctx.shopify.query(ACTIVE_PRODUCTS): on_sale = any( v.compare_at_price and v.compare_at_price > v.price for v in product.variants
How do you build an automatic Sale collection on Shopify?
To build an automatic Sale collection on Shopify, this template tags a product when any variant's compare-at price sits above its current price and removes the tag when nothing is discounted anymore. The check reads real price fields, not a discount app's state, so it catches sales set by hand, by import, or by another automation, and one discounted variant is enough to qualify the product. Bind a smart collection to the tag and it fills when discounts start and empties when they end.
The usual version is a manual sale tag that outlives the sale, leaving full-price products in the Sale collection and shoppers feeling baited; consumer authorities fine stores for exactly that. Collaudo re-checks every product on every run and reports which ones would gain or lose the tag. The storefront only changes after you have seen the list.
Last updated August 24, 2026
If you run a sharper version of this template, or something it inspired, send it in. We review every application and publish the good ones, credited to you or your agency.
AI writes real Python or TypeScript, a dry run rehearses it, you approve, it deploys.
Free plan · no card · 🇪🇺 EU data residency