Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arrowParens": "avoid",
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": false,
"semi": true,
"tabWidth": 2,
"printWidth": 80,
"jsxSingleQuote": false,
"bracketSameLine": false,
"sortPackageJson": false,
"ignorePatterns": [
"**/dist/**",
"**/node_modules/**",
"**/.shopify/**",
"**/generated/**",
"**/package.json"
]
}
27 changes: 27 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"categories": {
"correctness": "off",
"suspicious": "off",
"pedantic": "off",
"perf": "off",
"style": "off",
"restriction": "off"
},
"ignorePatterns": [
"**/node_modules/**",
"**/dist/**",
"**/.shopify/**",
"**/generated/**",
"examples/mock-http-server/**"
],
"overrides": [
{
"files": ["**/*.{js,jsx}"],
"rules": {
"no-console": ["error", {"allow": ["error"]}],
"no-debugger": "error"
}
}
]
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Reference applications and examples demonstrating how to implement Shopify Disco
>
> This repository is read-only. All examples and code samples contained here are generated and maintained by Shopify.
>
> Shopify employees should make source changes in [Discount Functions Testing](https://github.com/Shopify/discount-functions-testing) and run `dev generate-reference-app` rather than editing generated files here directly.
>
> If you encounter any issues or have questions about the implementations, please submit them through the GitHub Issues section of this repository.
>
> We encourage you to use these examples as a learning resource while following the official tutorials on [Shopify Dev](https://shopify.dev/docs/apps/build/discounts).
Expand Down
55 changes: 55 additions & 0 deletions docs/discounts-in-rollouts-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Discounts in Rollouts Setup

Authenticated DFT tool that seeds the dedicated Discounts in Rollouts test shop with a fixed fixture matrix. Reachable from the Tools page or `/app/discounts-in-rollouts-setup`.

- Target shop: `discounts-in-rollouts.myshopify.com` (`gid://shopify/Shop/82109235446`)
- Tracking issue: https://github.com/shop/issues-discounts/issues/2230
- Project: https://vault.shopify.io/gsd/projects/51298

## What it seeds

One fixed, source-controlled configuration: `data/seed-configs/discounts-in-rollouts.ts`.

| Type | Fixtures |
| --- | --- |
| Products | `rollouts-seed-product-a`, `-b`, `-c` — active, untracked inventory, published to Online Store |
| Customers | one segment member (tagged `dft-rollouts-seed-segment-member`), one control |
| Segment | `[DFT Rollouts Seed] Segment members` on the member tag |
| Markets | resolves existing US and Canada region markets; creates `[DFT Rollouts Seed] Canada` only when no Canada market exists |
| Native discounts | 6 fixtures: add/remove x automatic/code, plus segment and Canada-market eligibility |
| Function discounts | `[DFT] Passthrough Order` (automatic app) and `[DFT] Passthrough Product` (code app) |

The tool never creates Rollout resources. Create launch and experiment Rollouts through Shopify Admin using the seeded discounts.

## Safety model

- Every loader and action authenticates with `authenticate.admin(request)`.
- Setup and reset mutations require `session.shop`, `shop.myshopifyDomain`, and `shop.id` to all match the target shop. The check runs inside the executor, not only in the UI.
- Dry run performs no mutations. On the target shop it checks existing resources; on any other shop it previews the plan from config without reading shop data.
- The config name is a constant; no form field selects a configuration.
- Preflight fails closed before the first mutation: config validation, shop identity, exact function-title resolution, Online Store publication, and required US market.

## Idempotency and ownership

- Every resource has a stable natural key (handle, email, name, title+code) and carries the `dft-rollouts-seed` tag or `[DFT Rollouts Seed]` title prefix.
- Setup looks up each resource before creating it. Reruns report `skipped` or `updated`, never duplicates.
- An existing resource with the same key but without the ownership marker (or with a different code) is reported as `conflict` and left untouched. Its dependents are `blocked`.

## Reset

- Reset preview lists what would be deleted; nothing is mutated. It reads shop data, so it only runs on the target shop.
- Destructive reset requires typing `discounts-in-rollouts` and runs only on the target shop.
- Deletion order: discounts, segment, customers, seeder-created market, products.
- Adopted markets, the primary market, and any resource without the ownership marker are never deleted; they are reported as manual cleanup steps.

## Scopes and deployment

Publishing products to Online Store requires `read_publications` and `write_publications`, added in `shopify.app.discount-functions-testing.toml`. A scope change requires deploying the app and reauthorizing it on the target shop before setup can publish products.

## Tests

```
pnpm vitest run -c tests/config/app-tests.config.ts \
app/routes/app.discounts-in-rollouts-setup/tests \
app/routes/tests/app.discounts-in-rollouts-setup.test.tsx
```
12 changes: 6 additions & 6 deletions docs/reference/components/DiscountClasses.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, Checkbox, Text, BlockStack, Box } from "@shopify/polaris";
import React, { useState, useCallback } from "react";
import {Card, Checkbox, Text, BlockStack, Box} from "@shopify/polaris";
import React, {useState, useCallback} from "react";

const DiscountClass = {
Product: "PRODUCT",
Expand All @@ -25,7 +25,7 @@ const DISCOUNT_CLASS_LABELS = {
* @returns A Polaris Card containing discount class selection checkboxes
*/
function DiscountClasses(props) {
const { discountClasses = [DiscountClass.Product], onChange } = props;
const {discountClasses = [DiscountClass.Product], onChange} = props;

const [selectedClasses, setSelectedClasses] = useState(
discountClasses.length > 0 ? discountClasses : [DiscountClass.Product],
Expand All @@ -35,7 +35,7 @@ function DiscountClasses(props) {
(checked, discountClass) => {
const updatedClasses = checked
? [...selectedClasses, discountClass]
: selectedClasses.filter((cls) => cls !== discountClass);
: selectedClasses.filter(cls => cls !== discountClass);

if (updatedClasses.length === 0) {
return;
Expand All @@ -62,7 +62,7 @@ function DiscountClasses(props) {

<Box paddingBlockStart="400">
<BlockStack gap="200">
{Object.values(DiscountClass).map((discountClass) => {
{Object.values(DiscountClass).map(discountClass => {
const isChecked = selectedClasses.includes(discountClass);
const isDisabled = isChecked && selectedClasses.length === 1;
return (
Expand All @@ -71,7 +71,7 @@ function DiscountClasses(props) {
label={DISCOUNT_CLASS_LABELS[discountClass]}
checked={isChecked}
disabled={isDisabled}
onChange={(checked) => handleChange(checked, discountClass)}
onChange={checked => handleChange(checked, discountClass)}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/shopify/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
packages:
- "extensions/*"
- 'extensions/*'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "How to build a combined Discount Function applying 10% off orders, 20% off the most expensive product, and free shipping"
name: 'How to build a combined Discount Function applying 10% off orders, 20% off the most expensive product, and free shipping'
api_name: discount
api_version: 2025-04
api_type: functions
Expand Down
Loading