Mirrors each active product's productType into a normalized custom.collection_key metafield so smart collections can be bound to typo-proof type slugs.
async def run(ctx): for product in await ctx.shopify.query(ACTIVE_PRODUCTS): key = slugify(product.product_type)
How do you build smart collections by product type on Shopify that do not silently drop products?
To build smart collections by product type on Shopify that do not silently drop products, this template mirrors each product's type into a normalized custom.collection_key metafield: lowercased, slugged, typo-tolerant. Collections bind to the clean key instead of the raw string, so "T-Shirt", "t-shirt" and "Tshirt " all land in the same collection instead of three. The original type field stays exactly as entered; only the key is normalized, so nothing changes in the admin's own views.
Type-based collections fail quietly: one variant spelling and a product just never appears, with nothing anywhere flagging why. The mirror re-runs as types get edited, so a supplier's creative spelling gets absorbed on the next pass instead of becoming a missing product. The run report lists every key it would write, which is also where you first notice that someone invented four new product types last week.
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