@aglyn/plugins-commerce 1.20.3 → 1.22.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 +16 -16
- package/src/lib/components/cart-fulfillment.js +19 -8
- package/src/lib/components/cart-fulfillment.js.map +1 -1
- package/src/lib/components/cart.js +106 -9
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/console/catalog-organization-card.component.js +102 -32
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/discounts-card.component.js +39 -5
- package/src/lib/components/console/discounts-card.component.js.map +1 -1
- package/src/lib/components/console/local-delivery-settings-card.component.js +34 -9
- package/src/lib/components/console/local-delivery-settings-card.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +72 -46
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +43 -6
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/quote-settings-card.component.js +31 -8
- package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
- package/src/lib/components/console/reservations-card.component.js +39 -4
- package/src/lib/components/console/reservations-card.component.js.map +1 -1
- package/src/lib/components/console/return-settings-card.component.js +39 -17
- package/src/lib/components/console/return-settings-card.component.js.map +1 -1
- package/src/lib/components/console/shipping-settings-card.component.js +34 -10
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +38 -13
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/suppliers-card.component.js +49 -15
- package/src/lib/components/console/suppliers-card.component.js.map +1 -1
- package/src/lib/components/console/tax-settings-card.component.js +36 -12
- package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
- package/src/lib/model/commerce-pos-offline.d.ts +21 -3
- package/src/lib/model/commerce-pos-offline.js +17 -5
- package/src/lib/model/commerce-pos-offline.js.map +1 -1
- package/src/lib/server/cart.js +57 -0
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/pos-offline-card-order.d.ts +2 -0
- package/src/lib/server/pos-offline-card-order.js +6 -2
- package/src/lib/server/pos-offline-card-order.js.map +1 -1
- package/src/lib/server/pos-offline-card-reconcile.d.ts +5 -1
- package/src/lib/server/pos-offline-card-reconcile.js +42 -10
- package/src/lib/server/pos-offline-card-reconcile.js.map +1 -1
- package/src/lib/server/pos-offline-sync.d.ts +48 -6
- package/src/lib/server/pos-offline-sync.js +142 -31
- package/src/lib/server/pos-offline-sync.js.map +1 -1
- package/src/lib/server/pos-stripe.d.ts +11 -0
- package/src/lib/server/pos-stripe.js +14 -0
- package/src/lib/server/pos-stripe.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +21 -1
- package/src/lib/server/pos-terminal.js +41 -7
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/transfer/product-transfer.js +15 -1
- package/src/lib/transfer/product-transfer.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-commerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.
|
|
31
|
-
"@aglyn/shared-ui-next": "1.
|
|
32
|
-
"@aglyn/shared-ui-snackstack": "1.
|
|
33
|
-
"@aglyn/shared-util-email": "1.
|
|
34
|
-
"@aglyn/shared-util-http": "1.
|
|
35
|
-
"@aglyn/shared-util-timestamp": "1.
|
|
36
|
-
"@aglyn/shared-util-tools": "1.
|
|
37
|
-
"@aglyn/tenant-data-admin": "1.
|
|
38
|
-
"@aglyn/tenant-feature-instance": "1.
|
|
39
|
-
"@aglyn/tenant-runtime": "1.
|
|
40
|
-
"@stripe/react-stripe-js": "^
|
|
41
|
-
"@stripe/stripe-js": "^
|
|
42
|
-
"@swc/helpers": "0.5.
|
|
28
|
+
"@aglyn/aglyn": "1.22.0",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.22.0",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.22.0",
|
|
31
|
+
"@aglyn/shared-ui-next": "1.22.0",
|
|
32
|
+
"@aglyn/shared-ui-snackstack": "1.22.0",
|
|
33
|
+
"@aglyn/shared-util-email": "1.22.0",
|
|
34
|
+
"@aglyn/shared-util-http": "1.22.0",
|
|
35
|
+
"@aglyn/shared-util-timestamp": "1.22.0",
|
|
36
|
+
"@aglyn/shared-util-tools": "1.22.0",
|
|
37
|
+
"@aglyn/tenant-data-admin": "1.22.0",
|
|
38
|
+
"@aglyn/tenant-feature-instance": "1.22.0",
|
|
39
|
+
"@aglyn/tenant-runtime": "1.22.0",
|
|
40
|
+
"@stripe/react-stripe-js": "^7.0.1",
|
|
41
|
+
"@stripe/stripe-js": "^10.2.1",
|
|
42
|
+
"@swc/helpers": "0.5.24",
|
|
43
43
|
"dayjs": "^1.11.23",
|
|
44
44
|
"qrcode.react": "^4.2.0",
|
|
45
45
|
"sharp": "^0.35.5"
|
|
@@ -61,13 +61,25 @@ export function useCartFulfillment(hostId, cartSignature, /**
|
|
|
61
61
|
postalCode,
|
|
62
62
|
line1
|
|
63
63
|
]);
|
|
64
|
+
// What the request asks beyond the basket: a delivery quote, only for a
|
|
65
|
+
// postal code long enough to place. Keyed by its content, so the settle
|
|
66
|
+
// above handing back an equal object, or a switch between shipping and
|
|
67
|
+
// pickup, is not another request (AGL-4047: every cart load asked twice).
|
|
68
|
+
const wantsQuote = method === 'local_delivery' && asked.postalCode.length >= 3;
|
|
69
|
+
const quoteFor = wantsQuote ? JSON.stringify([
|
|
70
|
+
asked.postalCode,
|
|
71
|
+
asked.line1
|
|
72
|
+
]) : '';
|
|
64
73
|
useEffect(()=>{
|
|
65
74
|
if (!hostId || cartSignature === '[]' || buyNow === null) {
|
|
66
75
|
setOptions(EMPTY);
|
|
67
76
|
return;
|
|
68
77
|
}
|
|
69
78
|
let live = true;
|
|
70
|
-
const
|
|
79
|
+
const [quotePostal, quoteLine1] = quoteFor ? JSON.parse(quoteFor) : [
|
|
80
|
+
'',
|
|
81
|
+
''
|
|
82
|
+
];
|
|
71
83
|
fetch('/api/commerce/local-fulfillment-options', {
|
|
72
84
|
method: 'POST',
|
|
73
85
|
headers: {
|
|
@@ -75,12 +87,12 @@ export function useCartFulfillment(hostId, cartSignature, /**
|
|
|
75
87
|
},
|
|
76
88
|
body: JSON.stringify(_extends({
|
|
77
89
|
hostId
|
|
78
|
-
}, buyNow ? buyNow : {},
|
|
79
|
-
postalCode:
|
|
80
|
-
} : {},
|
|
90
|
+
}, buyNow ? buyNow : {}, quoteFor ? {
|
|
91
|
+
postalCode: quotePostal
|
|
92
|
+
} : {}, quoteFor && quoteLine1 ? {
|
|
81
93
|
address: {
|
|
82
|
-
line1:
|
|
83
|
-
postalCode:
|
|
94
|
+
line1: quoteLine1,
|
|
95
|
+
postalCode: quotePostal
|
|
84
96
|
}
|
|
85
97
|
} : {}))
|
|
86
98
|
}).then((response)=>response.ok ? response.json() : EMPTY).then((payload)=>{
|
|
@@ -113,8 +125,7 @@ export function useCartFulfillment(hostId, cartSignature, /**
|
|
|
113
125
|
hostId,
|
|
114
126
|
cartSignature,
|
|
115
127
|
round,
|
|
116
|
-
|
|
117
|
-
asked,
|
|
128
|
+
quoteFor,
|
|
118
129
|
buyNowKey
|
|
119
130
|
]);
|
|
120
131
|
const offered = options.pickup.length > 0 || Boolean(options.delivery);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/cart-fulfillment.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport FormControl from '@mui/material/FormControl'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport FormLabel from '@mui/material/FormLabel'\nimport MenuItem from '@mui/material/MenuItem'\nimport Radio from '@mui/material/Radio'\nimport RadioGroup from '@mui/material/RadioGroup'\nimport TextField from '@mui/material/TextField'\nimport Typography from '@mui/material/Typography'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport type { PickupLocationOption } from '../model/local-fulfillment-settings'\nimport type { ModifierSelection } from '../model/product-modifiers'\nimport { pickupReadyWithinLabel } from '../model/local-fulfillment-settings'\n\n/**\n * How the shopper receives the order (AGL-3624): shipped, picked up at one of\n * the store's locations, or brought by the store's own driver. Asked at the\n * cart because that is where the store still decides what the checkout\n * offers; `POST /api/commerce/local-fulfillment-options` answers what this\n * store and this basket can have, and the checkout decides the fee, the\n * minimum and the window again from the store's settings — nothing shown\n * here is trusted.\n *\n * A store with no pickup location and no local delivery gets an empty answer\n * and draws nothing: its cart is exactly what it was.\n */\n\nexport interface CartDeliveryWindow {\n id: string\n startMs: number\n endMs: number\n label: string\n}\n\nexport interface CartDeliveryQuote {\n zoneId?: string\n zoneName?: string\n feeCents?: number\n minimumCents?: number\n freeOverCents?: number\n shortfallCents?: number\n unavailable?: string\n}\n\nexport interface CartFulfillmentOptions {\n pickup: PickupLocationOption[]\n delivery: {\n country: string\n instructions?: string\n needsAddress: boolean\n windows: CartDeliveryWindow[]\n quote?: CartDeliveryQuote\n } | null\n /** Whether the store can text the buyer about the pickup or delivery. */\n texts?: boolean\n}\n\nexport type CartFulfillmentMethod = 'shipping' | 'pickup' | 'local_delivery'\n\nconst EMPTY: CartFulfillmentOptions = { pickup: [], delivery: null }\n\nexport function useCartFulfillment(\n hostId: string | undefined,\n cartSignature: string,\n /**\n * A product's Buy button asks for that product rather than the cart; `null`\n * asks nothing (a subscription, a download).\n */\n buyNow?: {\n productId: string\n variantId?: string\n quantity: number\n /** The add-ons chosen (AGL-4100): a delivery minimum counts them. */\n modifiers?: ModifierSelection[]\n } | null,\n) {\n const buyNowKey = buyNow === undefined ? '' : JSON.stringify(buyNow)\n const [options, setOptions] = useState<CartFulfillmentOptions>(EMPTY)\n const [method, setMethod] = useState<CartFulfillmentMethod>('shipping')\n const [locationId, setLocationId] = useState('')\n const [postalCode, setPostalCode] = useState('')\n const [line1, setLine1] = useState('')\n const [windowId, setWindowId] = useState('')\n const [textPhone, setTextPhone] = useState('')\n const [round, setRound] = useState(0)\n // The postal code and street the quote below was asked for, settled after\n // the shopper stops typing so a keystroke is not a request.\n const [asked, setAsked] = useState({ postalCode: '', line1: '' })\n useEffect(() => {\n const timer = setTimeout(() => setAsked({ postalCode: postalCode.trim(), line1: line1.trim() }), 400)\n return () => clearTimeout(timer)\n }, [postalCode, line1])\n\n useEffect(() => {\n if (!hostId || cartSignature === '[]' || buyNow === null) {\n setOptions(EMPTY)\n return\n }\n let live = true\n const wantsQuote = method === 'local_delivery' && asked.postalCode.length >= 3\n fetch('/api/commerce/local-fulfillment-options', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n ...(buyNow ? buyNow : {}),\n ...(wantsQuote ? { postalCode: asked.postalCode } : {}),\n ...(wantsQuote && asked.line1 ? { address: { line1: asked.line1, postalCode: asked.postalCode } } : {}),\n }),\n })\n .then((response) => (response.ok ? response.json() : EMPTY))\n .then((payload: CartFulfillmentOptions) => {\n if (!live) return\n const next: CartFulfillmentOptions = {\n pickup: Array.isArray(payload?.pickup) ? payload.pickup : [],\n delivery: payload?.delivery ?? null,\n texts: Boolean(payload?.texts),\n }\n setOptions(next)\n // A choice the store no longer offers falls back to shipping.\n setMethod((prior) =>\n (prior === 'pickup' && !next.pickup.length) || (prior === 'local_delivery' && !next.delivery)\n ? 'shipping'\n : prior,\n )\n setLocationId((prior) =>\n next.pickup.some((location) => location.id === prior) ? prior : (next.pickup[0]?.id ?? ''),\n )\n setWindowId((prior) =>\n next.delivery?.windows.some((window) => window.id === prior) ? prior : '',\n )\n })\n .catch(() => live && setOptions(EMPTY))\n return () => {\n live = false\n }\n // `buyNow` is read through its key.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hostId, cartSignature, round, method, asked, buyNowKey])\n\n const offered = options.pickup.length > 0 || Boolean(options.delivery)\n const quote = options.delivery?.quote\n const deliverable = Boolean(quote && !quote.unavailable && !(quote.shortfallCents && quote.shortfallCents > 0))\n /** What the checkout is sent; `null` for a shipped order. */\n const phone = options.texts && textPhone.trim() ? { textPhone: textPhone.trim() } : {}\n const request = useMemo(() => {\n if (method === 'pickup' && locationId) return { method: 'pickup' as const, locationId, ...phone }\n if (method === 'local_delivery') {\n return {\n method: 'local_delivery' as const,\n ...phone,\n postalCode: postalCode.trim(),\n ...(windowId ? { windowStartMs: Number(windowId) } : {}),\n ...(line1.trim() ? { address: { line1: line1.trim(), postalCode: postalCode.trim() } } : {}),\n }\n }\n return null\n // `phone` is derived from the two values listed.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [method, locationId, postalCode, windowId, line1, textPhone, options.texts])\n /** Whether the choice is complete enough to check out with. */\n const ready =\n method === 'shipping' ||\n (method === 'pickup' && Boolean(locationId)) ||\n // The quote is the server's answer for what was typed: a zone that\n // reaches it and an order that meets its minimum.\n (method === 'local_delivery' && Boolean(postalCode.trim()) && Boolean(windowId) && deliverable)\n const signature = JSON.stringify(request)\n const reload = useCallback(() => setRound((value) => value + 1), [])\n return {\n options,\n offered,\n method,\n setMethod,\n locationId,\n setLocationId,\n postalCode,\n setPostalCode,\n line1,\n setLine1,\n windowId,\n setWindowId,\n textPhone,\n setTextPhone,\n request,\n ready,\n signature,\n reload,\n }\n}\n\nexport type CartFulfillmentState = ReturnType<typeof useCartFulfillment>\n\nexport function CartFulfillmentChoice(props: {\n state: CartFulfillmentState\n formatCents: (cents: number) => string\n}) {\n const { state, formatCents } = props\n const { options, method } = state\n if (!state.offered) return null\n const location = options.pickup.find((entry) => entry.id === state.locationId)\n const delivery = options.delivery\n const quote = delivery?.quote\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n <FormControl>\n <FormLabel id=\"cart-fulfillment-method\">\n <Typography variant=\"subtitle2\" component=\"span\">\n {'How do you want your order?'}\n </Typography>\n </FormLabel>\n <RadioGroup\n aria-labelledby=\"cart-fulfillment-method\"\n value={method}\n onChange={(event) => state.setMethod(event.target.value as CartFulfillmentMethod)}\n >\n <FormControlLabel value=\"shipping\" control={<Radio size=\"small\" />} label=\"Ship it\" />\n {options.pickup.length ? (\n <FormControlLabel\n value=\"pickup\"\n control={<Radio size=\"small\" />}\n label={options.pickup.length === 1 ? `Pick up at ${options.pickup[0].name}` : 'Pick up in store'}\n />\n ) : null}\n {delivery ? (\n <FormControlLabel value=\"local_delivery\" control={<Radio size=\"small\" />} label=\"Local delivery\" />\n ) : null}\n </RadioGroup>\n </FormControl>\n {method === 'pickup' ? (\n <>\n {options.pickup.length > 1 ? (\n <TextField\n select\n label=\"Pickup location\"\n value={state.locationId}\n onChange={(event) => state.setLocationId(event.target.value)}\n size=\"small\"\n >\n {options.pickup.map((entry) => (\n <MenuItem key={entry.id} value={entry.id}>\n {entry.name}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n {location ? (\n <Box>\n {location.address ? (\n <Typography variant=\"body2\">{location.address}</Typography>\n ) : null}\n {location.hours ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ whiteSpace: 'pre-line' }}>\n {location.hours}\n </Typography>\n ) : null}\n {location.readyWithinMinutes ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {`${pickupReadyWithinLabel(location.readyWithinMinutes)}. We’ll email you when it’s ready.`}\n </Typography>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {'We’ll email you when it’s ready.'}\n </Typography>\n )}\n {location.instructions ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {location.instructions}\n </Typography>\n ) : null}\n </Box>\n ) : null}\n </>\n ) : null}\n {method !== 'shipping' && options.texts ? (\n <TextField\n label=\"Mobile number (optional)\"\n value={state.textPhone}\n onChange={(event) => state.setTextPhone(event.target.value)}\n size=\"small\"\n helperText={\n method === 'pickup'\n ? 'We’ll text you when your order is ready'\n : 'We’ll text you when your order is on its way'\n }\n slotProps={{ htmlInput: { autoComplete: 'tel', inputMode: 'tel', maxLength: 24 } }}\n />\n ) : null}\n {method === 'local_delivery' && delivery ? (\n <>\n <TextField\n label=\"Postal code\"\n value={state.postalCode}\n onChange={(event) => state.setPostalCode(event.target.value)}\n size=\"small\"\n slotProps={{ htmlInput: { autoComplete: 'shipping postal-code', maxLength: 12 } }}\n />\n {delivery.needsAddress ? (\n <TextField\n label=\"Street address\"\n value={state.line1}\n onChange={(event) => state.setLine1(event.target.value)}\n size=\"small\"\n helperText=\"Delivery depends on the distance from the store\"\n slotProps={{ htmlInput: { autoComplete: 'shipping address-line1', maxLength: 120 } }}\n />\n ) : null}\n {quote?.unavailable ? <Alert severity=\"info\">{quote.unavailable}</Alert> : null}\n {quote && !quote.unavailable ? (\n quote.shortfallCents && quote.shortfallCents > 0 ? (\n <Alert severity=\"info\">\n {`Delivery needs an order of at least ${formatCents(quote.minimumCents ?? 0)}. ` +\n `Add ${formatCents(quote.shortfallCents)} more.`}\n </Alert>\n ) : (\n <Typography variant=\"body2\">\n {quote.feeCents\n ? `Delivery: ${formatCents(quote.feeCents)}`\n : 'Delivery: free'}\n {quote.freeOverCents && quote.feeCents\n ? ` (free over ${formatCents(quote.freeOverCents)})`\n : ''}\n </Typography>\n )\n ) : null}\n {delivery.windows.length ? (\n <TextField\n select\n label=\"Delivery time\"\n value={state.windowId}\n onChange={(event) => state.setWindowId(event.target.value)}\n size=\"small\"\n >\n {delivery.windows.map((window) => (\n <MenuItem key={window.id} value={window.id}>\n {window.label}\n </MenuItem>\n ))}\n </TextField>\n ) : (\n <Alert severity=\"info\">{'No delivery times are open right now.'}</Alert>\n )}\n {delivery.instructions ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {delivery.instructions}\n </Typography>\n ) : null}\n </>\n ) : null}\n </Box>\n )\n}\n"],"names":["Alert","Box","FormControl","FormControlLabel","FormLabel","MenuItem","Radio","RadioGroup","TextField","Typography","useCallback","useEffect","useMemo","useState","pickupReadyWithinLabel","EMPTY","pickup","delivery","useCartFulfillment","hostId","cartSignature","buyNow","options","buyNowKey","undefined","JSON","stringify","setOptions","method","setMethod","locationId","setLocationId","postalCode","setPostalCode","line1","setLine1","windowId","setWindowId","textPhone","setTextPhone","round","setRound","asked","setAsked","timer","setTimeout","trim","clearTimeout","live","wantsQuote","length","fetch","headers","body","address","then","response","ok","json","payload","next","Array","isArray","texts","Boolean","prior","some","location","id","windows","window","catch","offered","quote","deliverable","unavailable","shortfallCents","phone","request","windowStartMs","Number","ready","signature","reload","value","CartFulfillmentChoice","props","state","formatCents","find","entry","sx","display","flexDirection","gap","variant","component","aria-labelledby","onChange","event","target","control","size","label","name","select","map","hours","color","whiteSpace","readyWithinMinutes","instructions","helperText","slotProps","htmlInput","autoComplete","inputMode","maxLength","needsAddress","severity","minimumCents","feeCents","freeOverCents"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,OAAOA,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,sBAAsB,iCAAgC;AAC7D,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,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AM,CAAC;uCAGpD,MAACnE;wBAAWsF,SAAQ;;4BACjBtB,MAAMgD,QAAQ,GACX,CAAC,UAAU,EAAEjC,YAAYf,MAAMgD,QAAQ,GAAG,GAC1C;4BACHhD,MAAMiD,aAAa,IAAIjD,MAAMgD,QAAQ,GAClC,CAAC,YAAY,EAAEjC,YAAYf,MAAMiD,aAAa,EAAE,CAAC,CAAC,GAClD;;yBAGN;oBACHzG,SAASoD,OAAO,CAACnB,MAAM,iBACtB,KAAC1C;wBACCiG,MAAM;wBACNF,OAAM;wBACNnB,OAAOG,MAAMnD,QAAQ;wBACrB8D,UAAU,CAACC,QAAUZ,MAAMlD,WAAW,CAAC8D,MAAMC,MAAM,CAAChB,KAAK;wBACzDkB,MAAK;kCAEJrF,SAASoD,OAAO,CAACqC,GAAG,CAAC,CAACpC,uBACrB,KAACjE;gCAAyB+E,OAAOd,OAAOF,EAAE;0CACvCE,OAAOiC,KAAK;+BADAjC,OAAOF,EAAE;uCAM5B,KAACpE;wBAAMuH,UAAS;kCAAQ;;oBAEzBtG,SAAS8F,YAAY,iBACpB,KAACtG;wBAAWsF,SAAQ;wBAAUa,OAAM;kCACjC3F,SAAS8F,YAAY;yBAEtB;;iBAEJ;;;AAGV"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/components/cart-fulfillment.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport FormControl from '@mui/material/FormControl'\nimport FormControlLabel from '@mui/material/FormControlLabel'\nimport FormLabel from '@mui/material/FormLabel'\nimport MenuItem from '@mui/material/MenuItem'\nimport Radio from '@mui/material/Radio'\nimport RadioGroup from '@mui/material/RadioGroup'\nimport TextField from '@mui/material/TextField'\nimport Typography from '@mui/material/Typography'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport type { PickupLocationOption } from '../model/local-fulfillment-settings'\nimport type { ModifierSelection } from '../model/product-modifiers'\nimport { pickupReadyWithinLabel } from '../model/local-fulfillment-settings'\n\n/**\n * How the shopper receives the order (AGL-3624): shipped, picked up at one of\n * the store's locations, or brought by the store's own driver. Asked at the\n * cart because that is where the store still decides what the checkout\n * offers; `POST /api/commerce/local-fulfillment-options` answers what this\n * store and this basket can have, and the checkout decides the fee, the\n * minimum and the window again from the store's settings — nothing shown\n * here is trusted.\n *\n * A store with no pickup location and no local delivery gets an empty answer\n * and draws nothing: its cart is exactly what it was.\n */\n\nexport interface CartDeliveryWindow {\n id: string\n startMs: number\n endMs: number\n label: string\n}\n\nexport interface CartDeliveryQuote {\n zoneId?: string\n zoneName?: string\n feeCents?: number\n minimumCents?: number\n freeOverCents?: number\n shortfallCents?: number\n unavailable?: string\n}\n\nexport interface CartFulfillmentOptions {\n pickup: PickupLocationOption[]\n delivery: {\n country: string\n instructions?: string\n needsAddress: boolean\n windows: CartDeliveryWindow[]\n quote?: CartDeliveryQuote\n } | null\n /** Whether the store can text the buyer about the pickup or delivery. */\n texts?: boolean\n}\n\nexport type CartFulfillmentMethod = 'shipping' | 'pickup' | 'local_delivery'\n\nconst EMPTY: CartFulfillmentOptions = { pickup: [], delivery: null }\n\nexport function useCartFulfillment(\n hostId: string | undefined,\n cartSignature: string,\n /**\n * A product's Buy button asks for that product rather than the cart; `null`\n * asks nothing (a subscription, a download).\n */\n buyNow?: {\n productId: string\n variantId?: string\n quantity: number\n /** The add-ons chosen (AGL-4100): a delivery minimum counts them. */\n modifiers?: ModifierSelection[]\n } | null,\n) {\n const buyNowKey = buyNow === undefined ? '' : JSON.stringify(buyNow)\n const [options, setOptions] = useState<CartFulfillmentOptions>(EMPTY)\n const [method, setMethod] = useState<CartFulfillmentMethod>('shipping')\n const [locationId, setLocationId] = useState('')\n const [postalCode, setPostalCode] = useState('')\n const [line1, setLine1] = useState('')\n const [windowId, setWindowId] = useState('')\n const [textPhone, setTextPhone] = useState('')\n const [round, setRound] = useState(0)\n // The postal code and street the quote below was asked for, settled after\n // the shopper stops typing so a keystroke is not a request.\n const [asked, setAsked] = useState({ postalCode: '', line1: '' })\n useEffect(() => {\n const timer = setTimeout(() => setAsked({ postalCode: postalCode.trim(), line1: line1.trim() }), 400)\n return () => clearTimeout(timer)\n }, [postalCode, line1])\n\n // What the request asks beyond the basket: a delivery quote, only for a\n // postal code long enough to place. Keyed by its content, so the settle\n // above handing back an equal object, or a switch between shipping and\n // pickup, is not another request (AGL-4047: every cart load asked twice).\n const wantsQuote = method === 'local_delivery' && asked.postalCode.length >= 3\n const quoteFor = wantsQuote ? JSON.stringify([asked.postalCode, asked.line1]) : ''\n\n useEffect(() => {\n if (!hostId || cartSignature === '[]' || buyNow === null) {\n setOptions(EMPTY)\n return\n }\n let live = true\n const [quotePostal, quoteLine1] = quoteFor ? (JSON.parse(quoteFor) as [string, string]) : ['', '']\n fetch('/api/commerce/local-fulfillment-options', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n hostId,\n ...(buyNow ? buyNow : {}),\n ...(quoteFor ? { postalCode: quotePostal } : {}),\n ...(quoteFor && quoteLine1 ? { address: { line1: quoteLine1, postalCode: quotePostal } } : {}),\n }),\n })\n .then((response) => (response.ok ? response.json() : EMPTY))\n .then((payload: CartFulfillmentOptions) => {\n if (!live) return\n const next: CartFulfillmentOptions = {\n pickup: Array.isArray(payload?.pickup) ? payload.pickup : [],\n delivery: payload?.delivery ?? null,\n texts: Boolean(payload?.texts),\n }\n setOptions(next)\n // A choice the store no longer offers falls back to shipping.\n setMethod((prior) =>\n (prior === 'pickup' && !next.pickup.length) || (prior === 'local_delivery' && !next.delivery)\n ? 'shipping'\n : prior,\n )\n setLocationId((prior) =>\n next.pickup.some((location) => location.id === prior) ? prior : (next.pickup[0]?.id ?? ''),\n )\n setWindowId((prior) =>\n next.delivery?.windows.some((window) => window.id === prior) ? prior : '',\n )\n })\n .catch(() => live && setOptions(EMPTY))\n return () => {\n live = false\n }\n // `buyNow` is read through its key.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hostId, cartSignature, round, quoteFor, buyNowKey])\n\n const offered = options.pickup.length > 0 || Boolean(options.delivery)\n const quote = options.delivery?.quote\n const deliverable = Boolean(quote && !quote.unavailable && !(quote.shortfallCents && quote.shortfallCents > 0))\n /** What the checkout is sent; `null` for a shipped order. */\n const phone = options.texts && textPhone.trim() ? { textPhone: textPhone.trim() } : {}\n const request = useMemo(() => {\n if (method === 'pickup' && locationId) return { method: 'pickup' as const, locationId, ...phone }\n if (method === 'local_delivery') {\n return {\n method: 'local_delivery' as const,\n ...phone,\n postalCode: postalCode.trim(),\n ...(windowId ? { windowStartMs: Number(windowId) } : {}),\n ...(line1.trim() ? { address: { line1: line1.trim(), postalCode: postalCode.trim() } } : {}),\n }\n }\n return null\n // `phone` is derived from the two values listed.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [method, locationId, postalCode, windowId, line1, textPhone, options.texts])\n /** Whether the choice is complete enough to check out with. */\n const ready =\n method === 'shipping' ||\n (method === 'pickup' && Boolean(locationId)) ||\n // The quote is the server's answer for what was typed: a zone that\n // reaches it and an order that meets its minimum.\n (method === 'local_delivery' && Boolean(postalCode.trim()) && Boolean(windowId) && deliverable)\n const signature = JSON.stringify(request)\n const reload = useCallback(() => setRound((value) => value + 1), [])\n return {\n options,\n offered,\n method,\n setMethod,\n locationId,\n setLocationId,\n postalCode,\n setPostalCode,\n line1,\n setLine1,\n windowId,\n setWindowId,\n textPhone,\n setTextPhone,\n request,\n ready,\n signature,\n reload,\n }\n}\n\nexport type CartFulfillmentState = ReturnType<typeof useCartFulfillment>\n\nexport function CartFulfillmentChoice(props: {\n state: CartFulfillmentState\n formatCents: (cents: number) => string\n}) {\n const { state, formatCents } = props\n const { options, method } = state\n if (!state.offered) return null\n const location = options.pickup.find((entry) => entry.id === state.locationId)\n const delivery = options.delivery\n const quote = delivery?.quote\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>\n <FormControl>\n <FormLabel id=\"cart-fulfillment-method\">\n <Typography variant=\"subtitle2\" component=\"span\">\n {'How do you want your order?'}\n </Typography>\n </FormLabel>\n <RadioGroup\n aria-labelledby=\"cart-fulfillment-method\"\n value={method}\n onChange={(event) => state.setMethod(event.target.value as CartFulfillmentMethod)}\n >\n <FormControlLabel value=\"shipping\" control={<Radio size=\"small\" />} label=\"Ship it\" />\n {options.pickup.length ? (\n <FormControlLabel\n value=\"pickup\"\n control={<Radio size=\"small\" />}\n label={options.pickup.length === 1 ? `Pick up at ${options.pickup[0].name}` : 'Pick up in store'}\n />\n ) : null}\n {delivery ? (\n <FormControlLabel value=\"local_delivery\" control={<Radio size=\"small\" />} label=\"Local delivery\" />\n ) : null}\n </RadioGroup>\n </FormControl>\n {method === 'pickup' ? (\n <>\n {options.pickup.length > 1 ? (\n <TextField\n select\n label=\"Pickup location\"\n value={state.locationId}\n onChange={(event) => state.setLocationId(event.target.value)}\n size=\"small\"\n >\n {options.pickup.map((entry) => (\n <MenuItem key={entry.id} value={entry.id}>\n {entry.name}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n {location ? (\n <Box>\n {location.address ? (\n <Typography variant=\"body2\">{location.address}</Typography>\n ) : null}\n {location.hours ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ whiteSpace: 'pre-line' }}>\n {location.hours}\n </Typography>\n ) : null}\n {location.readyWithinMinutes ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {`${pickupReadyWithinLabel(location.readyWithinMinutes)}. We’ll email you when it’s ready.`}\n </Typography>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {'We’ll email you when it’s ready.'}\n </Typography>\n )}\n {location.instructions ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\">\n {location.instructions}\n </Typography>\n ) : null}\n </Box>\n ) : null}\n </>\n ) : null}\n {method !== 'shipping' && options.texts ? (\n <TextField\n label=\"Mobile number (optional)\"\n value={state.textPhone}\n onChange={(event) => state.setTextPhone(event.target.value)}\n size=\"small\"\n helperText={\n method === 'pickup'\n ? 'We’ll text you when your order is ready'\n : 'We’ll text you when your order is on its way'\n }\n slotProps={{ htmlInput: { autoComplete: 'tel', inputMode: 'tel', maxLength: 24 } }}\n />\n ) : null}\n {method === 'local_delivery' && delivery ? (\n <>\n <TextField\n label=\"Postal code\"\n value={state.postalCode}\n onChange={(event) => state.setPostalCode(event.target.value)}\n size=\"small\"\n slotProps={{ htmlInput: { autoComplete: 'shipping postal-code', maxLength: 12 } }}\n />\n {delivery.needsAddress ? (\n <TextField\n label=\"Street address\"\n value={state.line1}\n onChange={(event) => state.setLine1(event.target.value)}\n size=\"small\"\n helperText=\"Delivery depends on the distance from the store\"\n slotProps={{ htmlInput: { autoComplete: 'shipping address-line1', maxLength: 120 } }}\n />\n ) : null}\n {quote?.unavailable ? <Alert severity=\"info\">{quote.unavailable}</Alert> : null}\n {quote && !quote.unavailable ? (\n quote.shortfallCents && quote.shortfallCents > 0 ? (\n <Alert severity=\"info\">\n {`Delivery needs an order of at least ${formatCents(quote.minimumCents ?? 0)}. ` +\n `Add ${formatCents(quote.shortfallCents)} more.`}\n </Alert>\n ) : (\n <Typography variant=\"body2\">\n {quote.feeCents\n ? `Delivery: ${formatCents(quote.feeCents)}`\n : 'Delivery: free'}\n {quote.freeOverCents && quote.feeCents\n ? ` (free over ${formatCents(quote.freeOverCents)})`\n : ''}\n </Typography>\n )\n ) : null}\n {delivery.windows.length ? (\n <TextField\n select\n label=\"Delivery time\"\n value={state.windowId}\n onChange={(event) => state.setWindowId(event.target.value)}\n size=\"small\"\n >\n {delivery.windows.map((window) => (\n <MenuItem key={window.id} value={window.id}>\n {window.label}\n </MenuItem>\n ))}\n </TextField>\n ) : (\n <Alert severity=\"info\">{'No delivery times are open right now.'}</Alert>\n )}\n {delivery.instructions ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {delivery.instructions}\n </Typography>\n ) : null}\n </>\n ) : null}\n </Box>\n )\n}\n"],"names":["Alert","Box","FormControl","FormControlLabel","FormLabel","MenuItem","Radio","RadioGroup","TextField","Typography","useCallback","useEffect","useMemo","useState","pickupReadyWithinLabel","EMPTY","pickup","delivery","useCartFulfillment","hostId","cartSignature","buyNow","options","buyNowKey","undefined","JSON","stringify","setOptions","method","setMethod","locationId","setLocationId","postalCode","setPostalCode","line1","setLine1","windowId","setWindowId","textPhone","setTextPhone","round","setRound","asked","setAsked","timer","setTimeout","trim","clearTimeout","wantsQuote","length","quoteFor","live","quotePostal","quoteLine1","parse","fetch","headers","body","address","then","response","ok","json","payload","next","Array","isArray","texts","Boolean","prior","some","location","id","windows","window","catch","offered","quote","deliverable","unavailable","shortfallCents","phone","request","windowStartMs","Number","ready","signature","reload","value","CartFulfillmentChoice","props","state","formatCents","find","entry","sx","display","flexDirection","gap","variant","component","aria-labelledby","onChange","event","target","control","size","label","name","select","map","hours","color","whiteSpace","readyWithinMinutes","instructions","helperText","slotProps","htmlInput","autoComplete","inputMode","maxLength","needsAddress","severity","minimumCents","feeCents","freeOverCents"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,OAAOA,WAAW,sBAAqB;AACvC,OAAOC,SAAS,oBAAmB;AACnC,OAAOC,iBAAiB,4BAA2B;AACnD,OAAOC,sBAAsB,iCAAgC;AAC7D,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,cAAc,yBAAwB;AAC7C,OAAOC,WAAW,sBAAqB;AACvC,OAAOC,gBAAgB,2BAA0B;AACjD,OAAOC,eAAe,0BAAyB;AAC/C,OAAOC,gBAA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,EAAE,CAAC,GAC9E,CAAC,IAAI,EAAEe,YAAYf,MAAMG,cAAc,EAAE,MAAM,CAAC;uCAGpD,MAACvE;wBAAW0F,SAAQ;;4BACjBtB,MAAMgD,QAAQ,GACX,CAAC,UAAU,EAAEjC,YAAYf,MAAMgD,QAAQ,GAAG,GAC1C;4BACHhD,MAAMiD,aAAa,IAAIjD,MAAMgD,QAAQ,GAClC,CAAC,YAAY,EAAEjC,YAAYf,MAAMiD,aAAa,EAAE,CAAC,CAAC,GAClD;;yBAGN;oBACH7G,SAASwD,OAAO,CAACxB,MAAM,iBACtB,KAACzC;wBACCqG,MAAM;wBACNF,OAAM;wBACNnB,OAAOG,MAAMvD,QAAQ;wBACrBkE,UAAU,CAACC,QAAUZ,MAAMtD,WAAW,CAACkE,MAAMC,MAAM,CAAChB,KAAK;wBACzDkB,MAAK;kCAEJzF,SAASwD,OAAO,CAACqC,GAAG,CAAC,CAACpC,uBACrB,KAACrE;gCAAyBmF,OAAOd,OAAOF,EAAE;0CACvCE,OAAOiC,KAAK;+BADAjC,OAAOF,EAAE;uCAM5B,KAACxE;wBAAM2H,UAAS;kCAAQ;;oBAEzB1G,SAASkG,YAAY,iBACpB,KAAC1G;wBAAW0F,SAAQ;wBAAUa,OAAM;kCACjC/F,SAASkG,YAAY;yBAEtB;;iBAEJ;;;AAGV"}
|
|
@@ -33,6 +33,7 @@ import Badge from "@mui/material/Badge";
|
|
|
33
33
|
import Box from "@mui/material/Box";
|
|
34
34
|
import Button from "@mui/material/Button";
|
|
35
35
|
import Checkbox from "@mui/material/Checkbox";
|
|
36
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
|
36
37
|
import Drawer from "@mui/material/Drawer";
|
|
37
38
|
import FormControlLabel from "@mui/material/FormControlLabel";
|
|
38
39
|
import IconButton from "@mui/material/IconButton";
|
|
@@ -62,6 +63,34 @@ import { useStorefrontPurchaseEvent } from "../utils/use-storefront-purchase-eve
|
|
|
62
63
|
export const ID = 'cart';
|
|
63
64
|
/** Blocks dispatch this after mutating the cart so badges refresh. */ export { CART_UPDATED_EVENT };
|
|
64
65
|
const usd = (cents)=>`$${(cents / 100).toFixed(2)}`;
|
|
66
|
+
/**
|
|
67
|
+
* The stored cart's read: one URL for the preload hint and the fetch, so the
|
|
68
|
+
* browser hands the fetch the response it already has.
|
|
69
|
+
*/ function cartReadUrl(hostId) {
|
|
70
|
+
return `/api/commerce/cart?hostId=${encodeURIComponent(hostId)}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Starts the cart page's read while the HTML is still arriving (AGL-4047).
|
|
74
|
+
*
|
|
75
|
+
* The read is a client fetch, and a client effect runs only once the whole
|
|
76
|
+
* page has hydrated: on aglyn.com/cart that was 0.5–4.3 s after the HTML
|
|
77
|
+
* landed, and the cart's own request (0.3–0.75 s) only started then.
|
|
78
|
+
* Rendered on the server, this hint has the browser make the same request as
|
|
79
|
+
* soon as it parses the page, so when the cart mounts its fetch is answered
|
|
80
|
+
* from the response already in hand. `crossOrigin="anonymous"` is what lets a
|
|
81
|
+
* `fetch()` with its defaults (cors, same-origin cookies) match it; without it
|
|
82
|
+
* the browser would read the cart twice.
|
|
83
|
+
*
|
|
84
|
+
* The cart page only: a badge in a header is on every page of the store and
|
|
85
|
+
* has nothing on screen waiting for its count.
|
|
86
|
+
*/ function CartReadPreload({ hostId }) {
|
|
87
|
+
return /*#__PURE__*/ _jsx("link", {
|
|
88
|
+
rel: "preload",
|
|
89
|
+
as: "fetch",
|
|
90
|
+
href: cartReadUrl(hostId),
|
|
91
|
+
crossOrigin: "anonymous"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
65
94
|
/**
|
|
66
95
|
* The cart's lines as GA4 `items`.
|
|
67
96
|
*
|
|
@@ -82,7 +111,8 @@ const usd = (cents)=>`$${(cents / 100).toFixed(2)}`;
|
|
|
82
111
|
}));
|
|
83
112
|
}
|
|
84
113
|
function CartLines(props) {
|
|
85
|
-
|
|
114
|
+
var _cart_shippingCountries;
|
|
115
|
+
const { hostId, cart, load, showCoupon, checkoutLabel, emptyText, onMutate } = props;
|
|
86
116
|
const siteFetch = Aglyn.useSiteFetch();
|
|
87
117
|
const [coupon, setCoupon] = useState('');
|
|
88
118
|
const [email, setEmail] = useState('');
|
|
@@ -97,6 +127,11 @@ function CartLines(props) {
|
|
|
97
127
|
// itself the server's answer rather than a guess made here.
|
|
98
128
|
const [shipTo, setShipTo] = useState('');
|
|
99
129
|
const [shipCountries, setShipCountries] = useState(null);
|
|
130
|
+
// The cart itself can say so before any press, and then the field is shown
|
|
131
|
+
// from the start with the others; a checkout answer still wins.
|
|
132
|
+
const askedCountries = shipCountries != null ? shipCountries : (cart == null ? void 0 : cart.needsShippingCountry) ? ((_cart_shippingCountries = cart.shippingCountries) == null ? void 0 : _cart_shippingCountries.length) ? cart.shippingCountries : [
|
|
133
|
+
...CommerceModel.CHECKOUT_SHIPPING_COUNTRIES
|
|
134
|
+
] : null;
|
|
100
135
|
// Live carrier rates price by postal code (AGL-3612): asked only when the
|
|
101
136
|
// store prices that way and the server says so.
|
|
102
137
|
const [shipPostal, setShipPostal] = useState('');
|
|
@@ -112,6 +147,15 @@ function CartLines(props) {
|
|
|
112
147
|
// it latches the buy control off instead of inviting another click.
|
|
113
148
|
const [status, setStatus] = useState('idle');
|
|
114
149
|
const [message, setMessage] = useState('');
|
|
150
|
+
// The notice is about the destination ("Choose where you're shipping to.",
|
|
151
|
+
// a country not served, a postal code), so answering it clears it.
|
|
152
|
+
const [messageForShipping, setMessageForShipping] = useState(false);
|
|
153
|
+
const answerShipping = ()=>{
|
|
154
|
+
if (!messageForShipping) return;
|
|
155
|
+
setMessageForShipping(false);
|
|
156
|
+
setMessage('');
|
|
157
|
+
setStatus('idle');
|
|
158
|
+
};
|
|
115
159
|
// The terms of sale and business use, for card reader hardware (AGL-4038):
|
|
116
160
|
// asked when the cart says it holds some, or when a checkout was refused
|
|
117
161
|
// for want of them.
|
|
@@ -226,6 +270,7 @@ function CartLines(props) {
|
|
|
226
270
|
if (status === 'sending') return;
|
|
227
271
|
setStatus('sending');
|
|
228
272
|
setMessage('');
|
|
273
|
+
setMessageForShipping(false);
|
|
229
274
|
if (!attemptKey.current) {
|
|
230
275
|
var _ref;
|
|
231
276
|
var _globalThis_crypto_randomUUID, _globalThis_crypto;
|
|
@@ -381,6 +426,7 @@ function CartLines(props) {
|
|
|
381
426
|
...CommerceModel.CHECKOUT_SHIPPING_COUNTRIES
|
|
382
427
|
]);
|
|
383
428
|
setMessage(String((_ref7 = payload == null ? void 0 : payload.error) != null ? _ref7 : ''));
|
|
429
|
+
setMessageForShipping(true);
|
|
384
430
|
// An unserved destination is a real refusal and reads as one; being
|
|
385
431
|
// asked the first time is not.
|
|
386
432
|
setStatus(shipTo ? 'error' : 'ask');
|
|
@@ -417,6 +463,38 @@ function CartLines(props) {
|
|
|
417
463
|
hardwareTerms,
|
|
418
464
|
hardwareTermsAsked
|
|
419
465
|
]);
|
|
466
|
+
if (!cart && load === 'loading') {
|
|
467
|
+
return /*#__PURE__*/ _jsxs(Box, {
|
|
468
|
+
role: "status",
|
|
469
|
+
"aria-busy": "true",
|
|
470
|
+
sx: {
|
|
471
|
+
display: 'flex',
|
|
472
|
+
alignItems: 'center',
|
|
473
|
+
gap: 1.5,
|
|
474
|
+
p: 2
|
|
475
|
+
},
|
|
476
|
+
children: [
|
|
477
|
+
/*#__PURE__*/ _jsx(CircularProgress, {
|
|
478
|
+
size: 18
|
|
479
|
+
}),
|
|
480
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
481
|
+
variant: "body2",
|
|
482
|
+
color: "text.secondary",
|
|
483
|
+
children: 'Loading your cart…'
|
|
484
|
+
})
|
|
485
|
+
]
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
if (!cart && load === 'failed') {
|
|
489
|
+
return /*#__PURE__*/ _jsx(Typography, {
|
|
490
|
+
variant: "body2",
|
|
491
|
+
color: "text.secondary",
|
|
492
|
+
sx: {
|
|
493
|
+
p: 2
|
|
494
|
+
},
|
|
495
|
+
children: 'Your cart could not be loaded. Refresh the page to try again.'
|
|
496
|
+
});
|
|
497
|
+
}
|
|
420
498
|
if (!cart || cart.lines.length === 0) {
|
|
421
499
|
return /*#__PURE__*/ _jsx(Typography, {
|
|
422
500
|
variant: "body2",
|
|
@@ -617,14 +695,18 @@ function CartLines(props) {
|
|
|
617
695
|
}
|
|
618
696
|
}
|
|
619
697
|
}) : null,
|
|
620
|
-
|
|
698
|
+
askedCountries && fulfillment.method === 'shipping' ? /*#__PURE__*/ _jsx(TextField, {
|
|
621
699
|
select: true,
|
|
700
|
+
required: true,
|
|
622
701
|
label: "Ship to",
|
|
623
702
|
value: shipTo,
|
|
624
|
-
onChange: (event)=>
|
|
703
|
+
onChange: (event)=>{
|
|
704
|
+
setShipTo(event.target.value);
|
|
705
|
+
answerShipping();
|
|
706
|
+
},
|
|
625
707
|
size: "small",
|
|
626
708
|
helperText: "Shipping rates depend on where this is going",
|
|
627
|
-
children:
|
|
709
|
+
children: askedCountries.map((code)=>{
|
|
628
710
|
var _CommerceModel_CHECKOUT_SHIPPING_COUNTRY_NAMES_code;
|
|
629
711
|
return /*#__PURE__*/ _jsx(MenuItem, {
|
|
630
712
|
value: code,
|
|
@@ -635,7 +717,10 @@ function CartLines(props) {
|
|
|
635
717
|
askPostal && fulfillment.method === 'shipping' ? /*#__PURE__*/ _jsx(TextField, {
|
|
636
718
|
label: "Postal code",
|
|
637
719
|
value: shipPostal,
|
|
638
|
-
onChange: (event)=>
|
|
720
|
+
onChange: (event)=>{
|
|
721
|
+
setShipPostal(event.target.value);
|
|
722
|
+
answerShipping();
|
|
723
|
+
},
|
|
639
724
|
size: "small",
|
|
640
725
|
helperText: "Carrier rates depend on the postal code",
|
|
641
726
|
slotProps: {
|
|
@@ -664,7 +749,7 @@ function CartLines(props) {
|
|
|
664
749
|
// 501, so the control latches off rather than inviting a retry that
|
|
665
750
|
// cannot succeed (AGL-2019).
|
|
666
751
|
status === 'unconfigured' || // Asked but unanswered: the server would only refuse again.
|
|
667
|
-
fulfillment.method === 'shipping' &&
|
|
752
|
+
fulfillment.method === 'shipping' && askedCountries !== null && !shipTo || fulfillment.method === 'shipping' && askPostal && !shipPostal.trim() || // Pickup needs a location, delivery a zone and a time (AGL-3624).
|
|
668
753
|
!fulfillment.ready || // Card reader hardware: both boxes ticked (AGL-4038).
|
|
669
754
|
(Boolean(cart.hardwareTerms) || hardwareTermsAsked) && !hardwareTermsAnswered(hardwareTerms),
|
|
670
755
|
onClick: handleCheckout,
|
|
@@ -717,6 +802,7 @@ function CartLines(props) {
|
|
|
717
802
|
const { hostId } = Aglyn.useSite();
|
|
718
803
|
const siteFetch = Aglyn.useSiteFetch();
|
|
719
804
|
const [cart, setCart] = useState(null);
|
|
805
|
+
const [load, setLoad] = useState('loading');
|
|
720
806
|
const [open, setOpen] = useState(false);
|
|
721
807
|
// Closes the merchant's ecommerce funnel (AGL-1641). Stripe returns a cart
|
|
722
808
|
// checkout to the page it started on — this one — so the `purchase` that
|
|
@@ -727,10 +813,16 @@ function CartLines(props) {
|
|
|
727
813
|
const refresh = useCallback(async ()=>{
|
|
728
814
|
if (!hostId) return;
|
|
729
815
|
try {
|
|
730
|
-
const response = await fetch(
|
|
731
|
-
if (response.ok)
|
|
816
|
+
const response = await fetch(cartReadUrl(hostId));
|
|
817
|
+
if (response.ok) {
|
|
818
|
+
setCart(await response.json());
|
|
819
|
+
setLoad('loaded');
|
|
820
|
+
} else {
|
|
821
|
+
setLoad((current)=>current === 'loaded' ? current : 'failed');
|
|
822
|
+
}
|
|
732
823
|
} catch (unused) {
|
|
733
|
-
|
|
824
|
+
// Badge silently stays stale offline; a cart never read says so.
|
|
825
|
+
setLoad((current)=>current === 'loaded' ? current : 'failed');
|
|
734
826
|
}
|
|
735
827
|
}, [
|
|
736
828
|
hostId
|
|
@@ -825,6 +917,9 @@ function CartLines(props) {
|
|
|
825
917
|
ref: ref
|
|
826
918
|
}, rest, {
|
|
827
919
|
children: [
|
|
920
|
+
/*#__PURE__*/ _jsx(CartReadPreload, {
|
|
921
|
+
hostId: hostId
|
|
922
|
+
}),
|
|
828
923
|
/*#__PURE__*/ _jsx(CheckoutReturnNotice, {
|
|
829
924
|
hostId: hostId,
|
|
830
925
|
siteFetch: siteFetch
|
|
@@ -832,6 +927,7 @@ function CartLines(props) {
|
|
|
832
927
|
/*#__PURE__*/ _jsx(CartLines, {
|
|
833
928
|
hostId: hostId,
|
|
834
929
|
cart: cart,
|
|
930
|
+
load: load,
|
|
835
931
|
showCoupon: showCoupon,
|
|
836
932
|
checkoutLabel: checkoutLabel,
|
|
837
933
|
emptyText: emptyText,
|
|
@@ -891,6 +987,7 @@ function CartLines(props) {
|
|
|
891
987
|
/*#__PURE__*/ _jsx(CartLines, {
|
|
892
988
|
hostId: hostId,
|
|
893
989
|
cart: cart,
|
|
990
|
+
load: load,
|
|
894
991
|
showCoupon: showCoupon,
|
|
895
992
|
checkoutLabel: checkoutLabel,
|
|
896
993
|
emptyText: emptyText,
|