@shopify/shop-minis-platform 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -148,6 +148,106 @@ export interface SelectProductVariantResult extends ProductVariantSelection {
|
|
|
148
148
|
outcome: 'selected'
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
// Add to Cart Intent — add_to_cart:shopify/ProductVariant
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Data payload for the `add_to_cart:shopify/ProductVariant` intent.
|
|
157
|
+
*
|
|
158
|
+
* Adds a variant to the user's cart. If `productVariantId` is omitted (or
|
|
159
|
+
* `forceShow` is `true`), the host opens the same native variant selector
|
|
160
|
+
* sheet as `select:shopify/ProductVariant` first — the user picks a variant
|
|
161
|
+
* and quantity, and the host then performs the add-to-cart on confirm.
|
|
162
|
+
*
|
|
163
|
+
* For products outside Shop's catalog (referral products), the host
|
|
164
|
+
* navigates the user to the product's PDP instead of adding to cart.
|
|
165
|
+
*
|
|
166
|
+
* @publicDocs
|
|
167
|
+
*/
|
|
168
|
+
export interface AddToCartProductVariantParams {
|
|
169
|
+
/**
|
|
170
|
+
* The GID of the product. E.g. `gid://shopify/Product/123`.
|
|
171
|
+
*/
|
|
172
|
+
productId: string
|
|
173
|
+
/**
|
|
174
|
+
* The GID of the variant to add. When provided, the host adds it
|
|
175
|
+
* directly without showing the sheet. Omit to let the user pick.
|
|
176
|
+
*/
|
|
177
|
+
productVariantId?: string
|
|
178
|
+
/** Quantity to add. Defaults to `1`. */
|
|
179
|
+
quantity?: number
|
|
180
|
+
/**
|
|
181
|
+
* Discount codes to apply to the cart when adding.
|
|
182
|
+
*/
|
|
183
|
+
discountCodes?: string[]
|
|
184
|
+
/**
|
|
185
|
+
* Optional allow-list of variant GIDs. When set, only these variants are
|
|
186
|
+
* presented to the user. Other variants are filtered out before the option
|
|
187
|
+
* tree is built. Ignored when `productVariantId` is supplied.
|
|
188
|
+
*/
|
|
189
|
+
includedProductVariantGIDs?: string[]
|
|
190
|
+
/**
|
|
191
|
+
* If present, the GID of the variant that should be initially highlighted
|
|
192
|
+
* in the sheet. Defaults to the product's default variant. Ignored when
|
|
193
|
+
* `productVariantId` is supplied.
|
|
194
|
+
*/
|
|
195
|
+
initialVariantId?: string
|
|
196
|
+
/** Initial quantity displayed in the stepper. Defaults to `quantity ?? 1`. */
|
|
197
|
+
initialQuantity?: number
|
|
198
|
+
/**
|
|
199
|
+
* Maximum quantity selectable in the stepper. Defaults to the variant's
|
|
200
|
+
* `quantityAvailable` (or unbounded when stock is not tracked).
|
|
201
|
+
*/
|
|
202
|
+
maxQuantity?: number
|
|
203
|
+
/** Whether to show the quantity stepper. Defaults to `true`. */
|
|
204
|
+
showQuantity?: boolean
|
|
205
|
+
/**
|
|
206
|
+
* When `true`, always render the sheet — even for products with a single
|
|
207
|
+
* variant or when `productVariantId` is supplied. Bypasses the
|
|
208
|
+
* single-variant short-circuit so the mini gets a consistent confirmation
|
|
209
|
+
* step. Defaults to `false`.
|
|
210
|
+
*/
|
|
211
|
+
forceShow?: boolean
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Variant added to the cart by `add_to_cart:shopify/ProductVariant`.
|
|
216
|
+
*/
|
|
217
|
+
export interface AddToCartAddedResult extends ProductVariantSelection {
|
|
218
|
+
/** Discriminator. The host added a concrete variant to the cart. */
|
|
219
|
+
outcome: 'added_to_cart'
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Returned when the product cannot be added to the cart from the mini
|
|
224
|
+
* (e.g. referral products outside Shop's catalog) and the host instead
|
|
225
|
+
* sent the user to the product's PDP. The mini should treat this as a
|
|
226
|
+
* successful hand-off — the shopper is now on the PDP.
|
|
227
|
+
*/
|
|
228
|
+
export interface AddToCartNavigatedToProductResult {
|
|
229
|
+
/** Discriminator. The host navigated the user to the PDP instead. */
|
|
230
|
+
outcome: 'navigated_to_product'
|
|
231
|
+
/** GID of the product the host navigated to. */
|
|
232
|
+
productId: string
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Successful payload returned from `add_to_cart:shopify/ProductVariant`.
|
|
237
|
+
*
|
|
238
|
+
* Discriminate via `data.outcome`:
|
|
239
|
+
* - `'added_to_cart'` — a concrete variant was added; selection fields
|
|
240
|
+
* (`productVariantId`, `quantity`, `source`) are present.
|
|
241
|
+
* - `'navigated_to_product'` — the host could not add this product (e.g.
|
|
242
|
+
* referral product on another merchant's storefront) and instead sent
|
|
243
|
+
* the user to the PDP. Only `productId` is present.
|
|
244
|
+
*
|
|
245
|
+
* @publicDocs
|
|
246
|
+
*/
|
|
247
|
+
export type AddToCartProductVariantResult =
|
|
248
|
+
| AddToCartAddedResult
|
|
249
|
+
| AddToCartNavigatedToProductResult
|
|
250
|
+
|
|
151
251
|
// ---------------------------------------------------------------------------
|
|
152
252
|
// Intent Registry
|
|
153
253
|
// ---------------------------------------------------------------------------
|
|
@@ -171,6 +271,12 @@ export interface IntentDefinitions {
|
|
|
171
271
|
data: SelectProductVariantParams
|
|
172
272
|
result: SelectProductVariantResult
|
|
173
273
|
}
|
|
274
|
+
addToCartProductVariant: {
|
|
275
|
+
action: 'add_to_cart'
|
|
276
|
+
type: 'shopify/ProductVariant'
|
|
277
|
+
data: AddToCartProductVariantParams
|
|
278
|
+
result: AddToCartProductVariantResult
|
|
279
|
+
}
|
|
174
280
|
}
|
|
175
281
|
|
|
176
282
|
export type IntentKey = keyof IntentDefinitions
|
|
@@ -186,6 +292,10 @@ export const INTENT_REGISTRY = {
|
|
|
186
292
|
createUserImage: {action: 'create', type: 'shop/UserImage'},
|
|
187
293
|
tryOnProduct: {action: 'try_on', type: 'shopify/Product'},
|
|
188
294
|
selectProductVariant: {action: 'select', type: 'shopify/ProductVariant'},
|
|
295
|
+
addToCartProductVariant: {
|
|
296
|
+
action: 'add_to_cart',
|
|
297
|
+
type: 'shopify/ProductVariant',
|
|
298
|
+
},
|
|
189
299
|
} as const satisfies {
|
|
190
300
|
[K in IntentKey]: {
|
|
191
301
|
action: IntentDefinitions[K]['action']
|