Product targeting
Choose which products, variants, or collections a promotion or pickup rule applies to.
Installation
Writes app/components/product-targeting.tsx and adds @shopify/polaris-types@2.0.0 once authenticated.
API reference
valueRequiredProductTargetingValueUse scope all, products with productIds and variantIds, or collections with collectionIds. Persist the scope and Shopify global IDs on your rule.- Required
recordsRequiredProductTargetingRecordsDisplay records keyed by Shopify global ID with status available, unavailable, or unverified and optional title, imageUrl, detail, and meta. Omitted records are unverified.- Required
onChangeRequired(value: ProductTargetingValue, picked: readonly TargetRecord[]) => voidUpdate the controlled value and merge any newly selected display records. Save the value with the rest of the host form.- Required
pickerTargetPickerOverride selection with a function that receives the resource kind and current IDs. Resolve to display records on confirmation or undefined on cancellation.Shopify Resource Pickerscopesreadonly ProductTargetingValue["scope"][]Restrict which targeting scope radio choices are presented to merchants.["all", "products", "collections"]maxSelectionsnumberDisplay a selection count cap badge and warn merchants when selected targets exceed the limit.OptionalfilterThresholdnumberMinimum selected item count before rendering the inline selected-items filter search field.4checkingbooleanShow progress while the host verifies its saved selections.falseonRecheck() => voidResolve the current IDs again. Update the display records when the request completes.OptionalheadingstringName the targeting section.Product targetingdisabledbooleanDisable targeting edits while the host is saving or reopening the rule.false
Run under Shopify App Home AppProvider. Point polarisUrl to the Polaris 2.0 runtime.
The default picker opens the Shopify Resource Picker through App Bridge. Whole products include all their variants. Choose exact variants separately.
Changing scope starts a new selection. Confirming a picker updates its resource kind and preserves omitted unavailable or unverified IDs. Remove those IDs from the form.
The usage example connects a promotion or pickup editor to an authenticated resource route. useTargetingRoute connects reopening, saving, and rechecking to your app’s rule store and Shopify Admin API.