@stacksjs/defaults 0.75.617 → 0.75.621
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/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auth/SKILL.md +12 -1
- package/ai/skills/stacks-auto-imports/SKILL.md +1 -1
- package/ai/skills/stacks-commerce/SKILL.md +78 -4
- package/ai/skills/stacks-dashboard/SKILL.md +2 -2
- package/ai/skills/stacks-database/SKILL.md +1 -1
- package/ai/skills/stacks-migrations/SKILL.md +10 -2
- package/ai/skills/stacks-mobile/SKILL.md +21 -2
- package/ai/skills/stacks-models/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +11 -11
- package/ai/skills/stacks-orm/SKILL.md +2 -2
- package/app/Actions/Dashboard/Commerce/CommerceDiscountDestroyAction.ts +27 -0
- package/app/Actions/Dashboard/Commerce/CommerceDiscountStoreAction.ts +28 -0
- package/app/Actions/Dashboard/Commerce/CommerceDiscountUpdateAction.ts +30 -0
- package/app/Actions/Dashboard/Commerce/CommerceDiscountsAction.ts +42 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellDestroyAction.ts +31 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellDetailAction.ts +28 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellStoreAction.ts +26 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellUpdateAction.ts +29 -0
- package/app/Actions/Dashboard/Commerce/CommerceUpsellsAction.ts +40 -0
- package/app/Actions/Dashboard/Commerce/commerce-discount-list.ts +204 -0
- package/app/Actions/Dashboard/Commerce/commerce-discount-write.ts +53 -0
- package/app/Actions/Dashboard/Commerce/commerce-discounts-upsells.test.ts +228 -0
- package/app/Actions/Dashboard/Commerce/commerce-upsell-list.ts +289 -0
- package/app/Actions/Dashboard/Commerce/discount-records.ts +392 -0
- package/app/Actions/Dashboard/Commerce/upsell-offer-records.ts +307 -0
- package/app/Actions/Dashboard/Models/ModelSaveAction.ts +6 -1
- package/app/Actions/Dashboard/Models/model-relations.ts +17 -7
- package/app/Actions/Dashboard/Models/model-row-writes.ts +9 -8
- package/app/Actions/Dashboard/Models/model-write.ts +51 -2
- package/app/Actions/Dashboard/Remote/RemoteCommandRunAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalCloseAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalInputAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalOpenAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalResizeAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/RemoteTerminalStreamAction.ts +1 -2
- package/app/Actions/Dashboard/Remote/remote-commands.test.ts +2 -2
- package/app/Actions/Dashboard/Remote/remote-commands.ts +4 -4
- package/app/Actions/Dashboard/Remote/remote-terminal.test.ts +45 -25
- package/app/Actions/Dashboard/Remote/remote-terminal.ts +9 -9
- package/app/Actions/Storefront/AcceptOrderOfferAction.ts +68 -0
- package/app/Actions/Storefront/ApplyDiscountCodeAction.ts +83 -0
- package/app/Actions/Storefront/DeclineOrderOfferAction.ts +25 -0
- package/app/Actions/Storefront/PlaceOrderAction.ts +135 -72
- package/app/Gates.ts +4 -4
- package/app/Mail/OrderConfirmation.ts +7 -1
- package/app/Models/commerce/Cart.ts +14 -0
- package/app/Models/commerce/Discount.ts +255 -0
- package/app/Models/commerce/PostPurchaseOffer.ts +175 -0
- package/app/Models/commerce/PostPurchaseOfferResponse.ts +145 -0
- package/app/Policies/PostPolicy.ts +11 -11
- package/app/Storefront/DiscountCodeMessages.ts +12 -0
- package/app/Storefront/OrderKey.ts +29 -0
- package/app/Storefront/StorefrontPricing.ts +211 -0
- package/app/Storefront/UpsellCharge.ts +43 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +7 -7
- package/resources/components/Dashboard/Commerce/CommerceDiscountBreakdown.stx +72 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountDeleteDialog.stx +19 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountDetailsDialog.stx +110 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountDialog.stx +353 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountsDashboard.stx +211 -0
- package/resources/components/Dashboard/Commerce/CommerceDiscountsTable.stx +105 -0
- package/resources/components/Dashboard/Commerce/CommerceProductPicker.stx +115 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellDeleteDialog.stx +21 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellDetailsDialog.stx +153 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellDialog.stx +191 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellsDashboard.stx +214 -0
- package/resources/components/Dashboard/Commerce/CommerceUpsellsTable.stx +91 -0
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +4 -19
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +5 -3
- package/resources/components/Dashboard/UI/SearchFilter.stx +7 -4
- package/resources/components/Storefront/OrderSummary.stx +17 -0
- package/resources/functions/dashboard/sidebar.ts +4 -1
- package/resources/views/cart.stx +50 -16
- package/resources/views/checkout/contact.stx +11 -5
- package/resources/views/checkout/payment.stx +11 -5
- package/resources/views/checkout/shipping.stx +11 -5
- package/resources/views/orders/[id].stx +227 -50
- package/routes/dashboard-api.ts +12 -0
- package/routes/dashboard.ts +2 -0
- package/routes/storefront.ts +8 -0
- package/views/dashboard/commerce/discounts/index.stx +10 -0
- package/views/dashboard/commerce/upsells/index.stx +10 -0
|
@@ -28,16 +28,17 @@ interface StorefrontLineItem { lineTotal: number }
|
|
|
28
28
|
const { verifyCartCookie } = require('../../../app/Storefront/CartCookie')
|
|
29
29
|
const { readStorefront } = require('../../../app/Storefront/StorefrontDatabase')
|
|
30
30
|
const { storefrontCurrency, storefrontMoney, storefrontSummary } = require('../../../app/Storefront/StorefrontMoney')
|
|
31
|
+
const { storefrontCartSummary } = require('../../../app/Storefront/StorefrontPricing')
|
|
31
32
|
|
|
32
33
|
// Signed by the storefront actions as the token, a dot and its HMAC. An
|
|
33
34
|
// unsigned or tampered cookie is no cart, and is never looked up.
|
|
34
35
|
const token = verifyCartCookie(requestContext.cookie('stacks_cart'))
|
|
35
36
|
|
|
36
37
|
const found = token
|
|
37
|
-
? readStorefront('views/checkout/payment.stx', { cart: null, items: [] }, (db: import('bun:sqlite').Database) => {
|
|
38
|
+
? readStorefront('views/checkout/payment.stx', { cart: null, items: [], summary: null }, (db: import('bun:sqlite').Database) => {
|
|
38
39
|
const row = db.query<CartRow, [string]>(`SELECT * FROM carts WHERE session_token = ?1 AND status = 'active' LIMIT 1`).get(token)
|
|
39
40
|
if (!row)
|
|
40
|
-
return { cart: null, items: [] }
|
|
41
|
+
return { cart: null, items: [], summary: null }
|
|
41
42
|
|
|
42
43
|
// Every amount below is integer minor units of the cart's currency.
|
|
43
44
|
const currency = storefrontCurrency(row.currency)
|
|
@@ -55,9 +56,10 @@ const found = token
|
|
|
55
56
|
}
|
|
56
57
|
})
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
// Priced with the store's automatic discounts, exactly as PlaceOrderAction charges.
|
|
60
|
+
return { cart: row, items: lines, summary: storefrontCartSummary(db, row.id, currency) }
|
|
59
61
|
})
|
|
60
|
-
: { cart: null, items: [] }
|
|
62
|
+
: { cart: null, items: [], summary: null }
|
|
61
63
|
|
|
62
64
|
const cart = found.cart
|
|
63
65
|
const items = found.items
|
|
@@ -66,7 +68,9 @@ const items = found.items
|
|
|
66
68
|
// (app/Actions/Storefront/_shipping.ts), in minor units, so the running
|
|
67
69
|
// totals on every checkout step match what gets charged.
|
|
68
70
|
const subtotal = items.reduce((s: number, i: StorefrontLineItem) => s + i.lineTotal, 0)
|
|
69
|
-
const summary = storefrontSummary(subtotal, storefrontCurrency(cart?.currency))
|
|
71
|
+
const summary = found.summary ?? { ...storefrontSummary(subtotal, storefrontCurrency(cart?.currency)), discountLabel: '', discountTitle: '' }
|
|
72
|
+
const discountLabel = summary.discountLabel
|
|
73
|
+
const discountTitle = summary.discountTitle
|
|
70
74
|
const subtotalLabel = summary.subtotalLabel
|
|
71
75
|
const shippingLabel = summary.shippingLabel
|
|
72
76
|
const totalLabel = summary.totalLabel
|
|
@@ -139,6 +143,8 @@ const formError = requestContext.formError()
|
|
|
139
143
|
shippingLabel="{{ shippingLabel }}"
|
|
140
144
|
totalLabel="{{ totalLabel }}"
|
|
141
145
|
freeShippingNote="{{ freeShippingNote }}"
|
|
146
|
+
discountLabel="{{ discountLabel }}"
|
|
147
|
+
discountTitle="{{ discountTitle }}"
|
|
142
148
|
:showItems="true"
|
|
143
149
|
/>
|
|
144
150
|
</div>
|
|
@@ -28,16 +28,17 @@ interface StorefrontLineItem { lineTotal: number }
|
|
|
28
28
|
const { verifyCartCookie } = require('../../../app/Storefront/CartCookie')
|
|
29
29
|
const { readStorefront } = require('../../../app/Storefront/StorefrontDatabase')
|
|
30
30
|
const { storefrontCurrency, storefrontMoney, storefrontSummary } = require('../../../app/Storefront/StorefrontMoney')
|
|
31
|
+
const { storefrontCartSummary } = require('../../../app/Storefront/StorefrontPricing')
|
|
31
32
|
|
|
32
33
|
// Signed by the storefront actions as the token, a dot and its HMAC. An
|
|
33
34
|
// unsigned or tampered cookie is no cart, and is never looked up.
|
|
34
35
|
const token = verifyCartCookie(requestContext.cookie('stacks_cart'))
|
|
35
36
|
|
|
36
37
|
const found = token
|
|
37
|
-
? readStorefront('views/checkout/shipping.stx', { cart: null, items: [] }, (db: import('bun:sqlite').Database) => {
|
|
38
|
+
? readStorefront('views/checkout/shipping.stx', { cart: null, items: [], summary: null }, (db: import('bun:sqlite').Database) => {
|
|
38
39
|
const row = db.query<CartRow, [string]>(`SELECT * FROM carts WHERE session_token = ?1 AND status = 'active' LIMIT 1`).get(token)
|
|
39
40
|
if (!row)
|
|
40
|
-
return { cart: null, items: [] }
|
|
41
|
+
return { cart: null, items: [], summary: null }
|
|
41
42
|
|
|
42
43
|
// Every amount below is integer minor units of the cart's currency.
|
|
43
44
|
const currency = storefrontCurrency(row.currency)
|
|
@@ -55,9 +56,10 @@ const found = token
|
|
|
55
56
|
}
|
|
56
57
|
})
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
// Priced with the store's automatic discounts, exactly as PlaceOrderAction charges.
|
|
60
|
+
return { cart: row, items: lines, summary: storefrontCartSummary(db, row.id, currency) }
|
|
59
61
|
})
|
|
60
|
-
: { cart: null, items: [] }
|
|
62
|
+
: { cart: null, items: [], summary: null }
|
|
61
63
|
|
|
62
64
|
const cart = found.cart
|
|
63
65
|
const items = found.items
|
|
@@ -66,7 +68,9 @@ const items = found.items
|
|
|
66
68
|
// (app/Actions/Storefront/_shipping.ts), in minor units, so the running
|
|
67
69
|
// totals on every checkout step match what gets charged.
|
|
68
70
|
const subtotal = items.reduce((s: number, i: StorefrontLineItem) => s + i.lineTotal, 0)
|
|
69
|
-
const summary = storefrontSummary(subtotal, storefrontCurrency(cart?.currency))
|
|
71
|
+
const summary = found.summary ?? { ...storefrontSummary(subtotal, storefrontCurrency(cart?.currency)), discountLabel: '', discountTitle: '' }
|
|
72
|
+
const discountLabel = summary.discountLabel
|
|
73
|
+
const discountTitle = summary.discountTitle
|
|
70
74
|
const subtotalLabel = summary.subtotalLabel
|
|
71
75
|
const shippingLabel = summary.shippingLabel
|
|
72
76
|
const totalLabel = summary.totalLabel
|
|
@@ -172,6 +176,8 @@ const formError = requestContext.formError()
|
|
|
172
176
|
shippingLabel="{{ shippingLabel }}"
|
|
173
177
|
totalLabel="{{ totalLabel }}"
|
|
174
178
|
freeShippingNote="{{ freeShippingNote }}"
|
|
179
|
+
discountLabel="{{ discountLabel }}"
|
|
180
|
+
discountTitle="{{ discountTitle }}"
|
|
175
181
|
:showItems="true"
|
|
176
182
|
/>
|
|
177
183
|
</div>
|
|
@@ -3,101 +3,265 @@
|
|
|
3
3
|
@section('title', 'Order confirmed')
|
|
4
4
|
|
|
5
5
|
<script server>
|
|
6
|
-
// The
|
|
7
|
-
//
|
|
6
|
+
// The order page a shopper lands on after checkout, and opens again from the
|
|
7
|
+
// receipt email. It authorises on the order's unguessable key
|
|
8
|
+
// (`orders.tracking_token`, passed as `?key=`): order ids are sequential, and
|
|
9
|
+
// without the key anyone could read another shopper's name, email and address
|
|
10
|
+
// by counting. A wrong or missing key reads exactly like a missing order.
|
|
11
|
+
//
|
|
12
|
+
// Under the summary sits the post-purchase offer, when the order qualifies
|
|
13
|
+
// for one (`commerce.upsells`): a discounted, one-time addition taken with one
|
|
14
|
+
// click, posted to `/api/orders/offers/accept` with the same key.
|
|
15
|
+
|
|
8
16
|
interface OrderItemRow {
|
|
9
17
|
quantity: number | string
|
|
10
18
|
price: number | string
|
|
11
|
-
name: string
|
|
19
|
+
name: string | null
|
|
12
20
|
image_url: string | null
|
|
13
|
-
slug: string
|
|
21
|
+
slug: string | null
|
|
14
22
|
weight_grams: number | null
|
|
15
23
|
}
|
|
16
24
|
|
|
17
|
-
interface
|
|
25
|
+
interface OfferVariantView { id: number, name: string, unitPrice: number, regularPrice: number, inStock: boolean }
|
|
26
|
+
interface OfferProductView {
|
|
27
|
+
productId: number
|
|
28
|
+
name: string
|
|
29
|
+
imageUrl: string | null
|
|
30
|
+
unitPrice: number
|
|
31
|
+
regularPrice: number
|
|
32
|
+
percentOff: number
|
|
33
|
+
variants: OfferVariantView[]
|
|
34
|
+
inStock: boolean
|
|
35
|
+
status: string | null
|
|
36
|
+
}
|
|
37
|
+
interface OfferView {
|
|
38
|
+
offerId: number
|
|
39
|
+
headline: string | null
|
|
40
|
+
message: string | null
|
|
41
|
+
minQuantity: number
|
|
42
|
+
defaultQuantity: number
|
|
43
|
+
maxQuantity: number | null
|
|
44
|
+
expiresAt: string
|
|
45
|
+
products: OfferProductView[]
|
|
46
|
+
}
|
|
18
47
|
|
|
19
|
-
const Database = require('bun:sqlite').Database
|
|
20
|
-
const path = require('path')
|
|
21
48
|
const { storefrontCurrency, storefrontMoney } = require('../../../app/Storefront/StorefrontMoney')
|
|
22
|
-
|
|
23
|
-
const dbPath = path.resolve(process.cwd(), process.env.DB_DATABASE_PATH || 'database/stacks.sqlite')
|
|
24
|
-
const db = new Database(dbPath, { readonly: true })
|
|
49
|
+
const { orderForKey } = require('../../../app/Storefront/OrderKey')
|
|
25
50
|
|
|
26
51
|
// From `params`, which is what stx puts in a server script's scope for a
|
|
27
|
-
// `[id]` route.
|
|
28
|
-
// was always false and this page rendered "order not found" for every order.
|
|
52
|
+
// `[id]` route.
|
|
29
53
|
const orderId = Number(params?.id ?? 0) || 0
|
|
54
|
+
const queryParams = typeof requestContext !== 'undefined' ? requestContext.query() : (typeof query !== 'undefined' ? query : {})
|
|
55
|
+
const key = String(queryParams?.key ?? '')
|
|
30
56
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
57
|
+
let order: Record<string, any> | null = null
|
|
58
|
+
let items: Array<Record<string, any>> = []
|
|
59
|
+
let offers: Array<Record<string, any>> = []
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
order = orderId ? await orderForKey(orderId, key) : null
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.warn(`[storefront] order page could not read order ${orderId}: ${error instanceof Error ? error.message : String(error)}`)
|
|
66
|
+
}
|
|
39
67
|
|
|
40
68
|
// Every amount is integer minor units of the order's currency (1999 is
|
|
41
|
-
// $19.99): `order_items.price`, `orders.delivery_fee
|
|
69
|
+
// $19.99): `order_items.price`, `orders.delivery_fee`, `orders.discount_amount`
|
|
70
|
+
// and `orders.total_amount`.
|
|
42
71
|
const currency = storefrontCurrency(order?.currency)
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
if (order) {
|
|
74
|
+
const { db } = await import('@stacksjs/database/runtime')
|
|
75
|
+
const customer = order.customer_id
|
|
76
|
+
? await (db as any).selectFrom('customers').where('id', '=', order.customer_id).select(['name', 'email']).executeTakeFirst()
|
|
77
|
+
: null
|
|
78
|
+
order.customer_name = customer?.name ?? ''
|
|
79
|
+
order.customer_email = customer?.email ?? ''
|
|
80
|
+
|
|
81
|
+
const rows = await (db as any)
|
|
82
|
+
.selectFrom('order_items')
|
|
83
|
+
.leftJoin('products', 'products.id', 'order_items.product_id')
|
|
84
|
+
.where('order_items.order_id', '=', order.id)
|
|
85
|
+
.select(['order_items.quantity as quantity', 'order_items.price as price', 'products.name as name', 'products.image_url as image_url', 'products.slug as slug', 'products.weight_grams as weight_grams'])
|
|
86
|
+
.orderBy('order_items.id', 'asc')
|
|
87
|
+
.execute() as OrderItemRow[]
|
|
88
|
+
|
|
89
|
+
items = rows.map((row: OrderItemRow) => ({
|
|
90
|
+
name: row.name ?? 'Item',
|
|
91
|
+
slug: row.slug,
|
|
92
|
+
image: row.image_url,
|
|
93
|
+
weight: row.weight_grams ? `${row.weight_grams}g · ` : '',
|
|
94
|
+
qty: Number(row.quantity),
|
|
95
|
+
lineTotal: Number(row.quantity) * Number(row.price),
|
|
96
|
+
lineTotalLabel: storefrontMoney(Number(row.quantity) * Number(row.price), currency),
|
|
97
|
+
}))
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const { upsells } = await import('@stacksjs/commerce')
|
|
101
|
+
const views = await upsells.presentOffers(Number(order.id)) as OfferView[]
|
|
102
|
+
offers = views.map((offer: OfferView) => ({
|
|
103
|
+
offerId: offer.offerId,
|
|
104
|
+
headline: offer.headline || 'One-time offer',
|
|
105
|
+
message: offer.message || '',
|
|
106
|
+
minQuantity: offer.minQuantity,
|
|
107
|
+
maxQuantity: offer.maxQuantity ?? '',
|
|
108
|
+
defaultQuantity: offer.defaultQuantity,
|
|
109
|
+
expiresLabel: new Date(offer.expiresAt).toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', timeZone: 'UTC', timeZoneName: 'short' }),
|
|
110
|
+
products: offer.products.map((product: OfferProductView) => ({
|
|
111
|
+
productId: product.productId,
|
|
112
|
+
name: product.name,
|
|
113
|
+
image: product.imageUrl || '',
|
|
114
|
+
priceLabel: storefrontMoney(product.unitPrice, currency),
|
|
115
|
+
regularLabel: product.regularPrice > product.unitPrice ? storefrontMoney(product.regularPrice, currency) : '',
|
|
116
|
+
percentLabel: product.percentOff > 0 ? `${product.percentOff}% off` : '',
|
|
117
|
+
hasVariants: product.variants.length > 0,
|
|
118
|
+
variants: product.variants.map((variant: OfferVariantView) => ({
|
|
119
|
+
id: variant.id,
|
|
120
|
+
label: `${variant.name} - ${storefrontMoney(variant.unitPrice, currency)}${variant.inStock ? '' : ' (sold out)'}`,
|
|
121
|
+
disabled: !variant.inStock,
|
|
122
|
+
})),
|
|
123
|
+
added: product.status === 'accepted',
|
|
124
|
+
pending: product.status === 'pending',
|
|
125
|
+
available: product.inStock && product.status !== 'accepted' && product.status !== 'pending' && product.status !== 'declined',
|
|
126
|
+
})),
|
|
60
127
|
}))
|
|
61
|
-
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
// The confirmation matters more than the offer: an offer that cannot be
|
|
131
|
+
// shown is left out, and the log says why.
|
|
132
|
+
console.warn(`[storefront] no post-purchase offer for order ${order.id}: ${error instanceof Error ? error.message : String(error)}`)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
62
135
|
|
|
63
|
-
const subtotal = items.reduce((s: number, i:
|
|
136
|
+
const subtotal = items.reduce((s: number, i: Record<string, any>) => s + Number(i.lineTotal), 0)
|
|
137
|
+
const discount = order ? Number(order.discount_amount || 0) : 0
|
|
64
138
|
const shipping = order ? Number(order.delivery_fee || 0) : 0
|
|
139
|
+
const tax = order ? Number(order.tax_amount || 0) : 0
|
|
65
140
|
const total = order ? Number(order.total_amount || 0) : 0
|
|
66
141
|
const subtotalLabel = storefrontMoney(subtotal, currency)
|
|
142
|
+
const discountLabel = discount > 0 ? `-${storefrontMoney(discount, currency)}` : ''
|
|
67
143
|
const shippingLabel = shipping === 0 ? 'Free' : storefrontMoney(shipping, currency)
|
|
144
|
+
const taxLabel = tax > 0 ? storefrontMoney(tax, currency) : ''
|
|
68
145
|
const totalLabel = storefrontMoney(total, currency)
|
|
146
|
+
const savingsLabel = discount > 0 ? storefrontMoney(discount, currency) : ''
|
|
147
|
+
|
|
148
|
+
const notice = typeof requestContext !== 'undefined' ? requestContext.notice() : ''
|
|
149
|
+
const formError = typeof requestContext !== 'undefined' ? requestContext.formError() : ''
|
|
69
150
|
</script>
|
|
70
151
|
|
|
71
152
|
@section('content')
|
|
72
|
-
<div class="mx-auto px-6 py-16 max-w-3xl">
|
|
153
|
+
<div class="mx-auto px-4 sm:px-6 py-16 max-w-3xl">
|
|
73
154
|
|
|
74
155
|
@if (!order)
|
|
75
156
|
<div class="py-16 text-center">
|
|
76
157
|
<h1 class="font-bold text-3xl text-stone-900 tracking-tight">Order not found</h1>
|
|
77
|
-
<p class="mt-3 text-stone-600">We couldn't find that order.
|
|
158
|
+
<p class="mt-3 text-stone-600">We couldn't find that order. Open it from the link in your receipt email, or try the shop instead.</p>
|
|
78
159
|
<a href="/products" class="inline-flex mt-6 px-6 py-3 font-semibold text-sm text-stone-50 bg-stone-900 hover:bg-stone-800 rounded-full">Back to the shop</a>
|
|
79
160
|
</div>
|
|
80
161
|
@else
|
|
81
162
|
<div class="text-center">
|
|
82
163
|
<div class="inline-flex items-center justify-center h-14 w-14 bg-emerald-100 rounded-full">
|
|
83
|
-
<
|
|
164
|
+
<span class="i-hugeicons-tick-02 h-7 w-7 text-emerald-700" aria-hidden="true"></span>
|
|
84
165
|
</div>
|
|
85
166
|
<p class="mt-5 font-medium text-stone-500 text-xs tracking-wider uppercase">Order #{{ order.id }}</p>
|
|
86
167
|
<h1 class="mt-2 font-bold text-4xl text-stone-900 tracking-tight">Order confirmed.</h1>
|
|
87
168
|
<p class="mt-3 text-stone-600">Thanks, {{ order.customer_name }}. We sent a receipt to {{ order.customer_email }}.</p>
|
|
88
169
|
</div>
|
|
89
170
|
|
|
171
|
+
@if (notice)
|
|
172
|
+
<p role="status" class="mt-8 px-4 py-3 font-medium text-emerald-800 text-sm bg-emerald-50 border border-emerald-200 rounded-xl">{{ notice }}</p>
|
|
173
|
+
@endif
|
|
174
|
+
@if (formError)
|
|
175
|
+
<p role="alert" class="mt-8 px-4 py-3 font-medium text-red-800 text-sm bg-red-50 border border-red-200 rounded-xl">{{ formError }}</p>
|
|
176
|
+
@endif
|
|
177
|
+
|
|
178
|
+
@foreach (offers as offer)
|
|
179
|
+
<section class="mt-10" aria-labelledby="offer-{{ offer.offerId }}">
|
|
180
|
+
<div class="flex gap-3 items-start p-5 bg-stone-100 border border-stone-200 rounded-2xl">
|
|
181
|
+
<span class="i-hugeicons-gift mt-0.5 h-5 w-5 flex-shrink-0 text-stone-700" aria-hidden="true"></span>
|
|
182
|
+
<div>
|
|
183
|
+
<h2 id="offer-{{ offer.offerId }}" class="font-semibold text-stone-900">{{ offer.headline }}</h2>
|
|
184
|
+
@if (offer.message)
|
|
185
|
+
<p class="mt-1 text-stone-700 text-sm">{{ offer.message }}</p>
|
|
186
|
+
@endif
|
|
187
|
+
<p class="mt-1 text-stone-500 text-xs">Only on this page, until {{ offer.expiresLabel }}. Charged to the payment method you just used.</p>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
<ul class="flex gap-4 overflow-x-auto mt-4 pb-3 snap-x snap-mandatory">
|
|
192
|
+
@foreach (offer.products as product)
|
|
193
|
+
<li class="flex flex-col flex-shrink-0 w-64 sm:w-72 snap-start">
|
|
194
|
+
<div class="overflow-hidden aspect-square bg-stone-100 border border-stone-200 rounded-2xl">
|
|
195
|
+
@if (product.image)
|
|
196
|
+
<img src="{{ product.image }}" alt="{{ product.name }}" class="object-cover h-full w-full" loading="lazy">
|
|
197
|
+
@endif
|
|
198
|
+
</div>
|
|
199
|
+
<h3 class="mt-3 font-semibold text-lg text-stone-900">{{ product.name }}</h3>
|
|
200
|
+
<p class="mt-1 text-base">
|
|
201
|
+
<span class="font-semibold text-stone-900">{{ product.priceLabel }}</span>
|
|
202
|
+
@if (product.regularLabel)
|
|
203
|
+
<s class="ml-2 text-stone-500">{{ product.regularLabel }}</s>
|
|
204
|
+
@endif
|
|
205
|
+
@if (product.percentLabel)
|
|
206
|
+
<span class="ml-2 font-medium text-emerald-700">({{ product.percentLabel }})</span>
|
|
207
|
+
@endif
|
|
208
|
+
</p>
|
|
209
|
+
|
|
210
|
+
@if (product.added)
|
|
211
|
+
<p class="mt-4 px-4 py-3 font-semibold text-center text-emerald-800 text-sm bg-emerald-50 rounded-xl">Added to your order</p>
|
|
212
|
+
@elseif (product.pending)
|
|
213
|
+
<p class="mt-4 px-4 py-3 font-semibold text-center text-stone-700 text-sm bg-stone-100 rounded-xl">Confirming payment</p>
|
|
214
|
+
@elseif (product.available)
|
|
215
|
+
<form method="POST" action="/api/orders/offers/accept" class="flex flex-col gap-3 mt-4">
|
|
216
|
+
<input type="hidden" name="order_id" value="{{ order.id }}">
|
|
217
|
+
<input type="hidden" name="key" value="{{ key }}">
|
|
218
|
+
<input type="hidden" name="offer_id" value="{{ offer.offerId }}">
|
|
219
|
+
<input type="hidden" name="product_id" value="{{ product.productId }}">
|
|
220
|
+
@if (product.hasVariants)
|
|
221
|
+
<label class="block px-4 pt-2 pb-2 border border-stone-300 rounded-xl focus-within:border-stone-900">
|
|
222
|
+
<span class="block text-stone-500 text-xs">Option</span>
|
|
223
|
+
<select name="variant_id" required class="block w-full text-stone-900 text-sm bg-transparent focus:outline-none">
|
|
224
|
+
@foreach (product.variants as variant)
|
|
225
|
+
<option value="{{ variant.id }}" {{ variant.disabled ? 'disabled' : '' }}>{{ variant.label }}</option>
|
|
226
|
+
@endforeach
|
|
227
|
+
</select>
|
|
228
|
+
</label>
|
|
229
|
+
@endif
|
|
230
|
+
<label class="block px-4 pt-2 pb-2 border border-stone-300 rounded-xl focus-within:border-stone-900">
|
|
231
|
+
<span class="block text-stone-500 text-xs">Quantity</span>
|
|
232
|
+
<input type="number" name="quantity" value="{{ offer.defaultQuantity }}" min="{{ offer.minQuantity }}" max="{{ offer.maxQuantity }}" step="1" required inputmode="numeric" class="block w-full text-stone-900 text-sm bg-transparent focus:outline-none">
|
|
233
|
+
</label>
|
|
234
|
+
<button type="submit" class="px-6 py-3 font-semibold text-sm text-stone-50 bg-stone-900 hover:bg-stone-800 active:scale-[0.98] rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-stone-900 transition">Add to order</button>
|
|
235
|
+
</form>
|
|
236
|
+
@else
|
|
237
|
+
<p class="mt-4 px-4 py-3 font-medium text-center text-stone-500 text-sm bg-stone-100 rounded-xl">Sold out</p>
|
|
238
|
+
@endif
|
|
239
|
+
</li>
|
|
240
|
+
@endforeach
|
|
241
|
+
</ul>
|
|
242
|
+
|
|
243
|
+
<form method="POST" action="/api/orders/offers/decline" class="mt-2 text-right">
|
|
244
|
+
<input type="hidden" name="order_id" value="{{ order.id }}">
|
|
245
|
+
<input type="hidden" name="key" value="{{ key }}">
|
|
246
|
+
<input type="hidden" name="offer_id" value="{{ offer.offerId }}">
|
|
247
|
+
<button type="submit" class="font-medium text-stone-500 text-sm hover:text-stone-900 underline underline-offset-4">No thanks</button>
|
|
248
|
+
</form>
|
|
249
|
+
</section>
|
|
250
|
+
@endforeach
|
|
251
|
+
|
|
90
252
|
<div class="mt-10 p-6 md:p-8 border border-stone-200 rounded-3xl">
|
|
91
253
|
<p class="font-semibold text-stone-500 text-xs tracking-wider uppercase">Items</p>
|
|
92
254
|
<ul class="mt-4 divide-stone-200 divide-y">
|
|
93
255
|
@foreach (items as item)
|
|
94
256
|
<li class="flex gap-4 items-center py-4">
|
|
95
257
|
<div class="overflow-hidden flex-shrink-0 h-16 w-16 bg-stone-200 rounded-xl">
|
|
96
|
-
|
|
258
|
+
@if (item.image)
|
|
259
|
+
<img src="{{ item.image }}" alt="{{ item.name }}" class="object-cover h-full w-full">
|
|
260
|
+
@endif
|
|
97
261
|
</div>
|
|
98
262
|
<div class="flex-1">
|
|
99
263
|
<p class="font-semibold text-stone-900">{{ item.name }}</p>
|
|
100
|
-
<p class="text-stone-500 text-xs">{{ item.weight }}
|
|
264
|
+
<p class="text-stone-500 text-xs">{{ item.weight }}qty {{ item.qty }}</p>
|
|
101
265
|
</div>
|
|
102
266
|
<p class="font-semibold text-stone-900">{{ item.lineTotalLabel }}</p>
|
|
103
267
|
</li>
|
|
@@ -108,10 +272,23 @@ const totalLabel = storefrontMoney(total, currency)
|
|
|
108
272
|
|
|
109
273
|
<dl class="space-y-2 text-sm">
|
|
110
274
|
<div class="flex justify-between"><dt class="text-stone-600">Subtotal</dt><dd class="font-semibold text-stone-900">{{ subtotalLabel }}</dd></div>
|
|
275
|
+
@if (discountLabel)
|
|
276
|
+
<div class="flex justify-between"><dt class="text-stone-600">Discount</dt><dd class="font-semibold text-emerald-700">{{ discountLabel }}</dd></div>
|
|
277
|
+
@endif
|
|
111
278
|
<div class="flex justify-between"><dt class="text-stone-600">Shipping</dt><dd class="font-semibold text-stone-900">{{ shippingLabel }}</dd></div>
|
|
279
|
+
@if (taxLabel)
|
|
280
|
+
<div class="flex justify-between"><dt class="text-stone-600">Tax</dt><dd class="font-semibold text-stone-900">{{ taxLabel }}</dd></div>
|
|
281
|
+
@endif
|
|
112
282
|
<div class="flex justify-between pt-2 text-base border-stone-200 border-t"><dt class="font-semibold text-stone-900">Total</dt><dd class="font-bold text-stone-900">{{ totalLabel }}</dd></div>
|
|
113
283
|
</dl>
|
|
114
284
|
|
|
285
|
+
@if (savingsLabel)
|
|
286
|
+
<p class="flex gap-2 items-center mt-4 font-semibold text-emerald-700 text-sm tracking-wide uppercase">
|
|
287
|
+
<span class="i-hugeicons-discount-tag-01 h-4 w-4" aria-hidden="true"></span>
|
|
288
|
+
Total savings {{ savingsLabel }}
|
|
289
|
+
</p>
|
|
290
|
+
@endif
|
|
291
|
+
|
|
115
292
|
<div class="mt-6 p-4 text-sm bg-stone-100 rounded-xl">
|
|
116
293
|
<p class="font-semibold text-stone-500 text-xs tracking-wider uppercase">Ship to</p>
|
|
117
294
|
<p class="mt-1 text-stone-900 whitespace-pre-line">{{ order.delivery_address }}</p>
|
|
@@ -121,31 +298,31 @@ const totalLabel = storefrontMoney(total, currency)
|
|
|
121
298
|
<div class="grid gap-4 sm:grid-cols-3 mt-10 text-sm">
|
|
122
299
|
<div class="p-5 border border-stone-200 rounded-2xl">
|
|
123
300
|
<div class="inline-flex items-center justify-center h-9 w-9 bg-stone-100 rounded-full">
|
|
124
|
-
<
|
|
301
|
+
<span class="i-hugeicons-mail-01 h-4 w-4 text-stone-700" aria-hidden="true"></span>
|
|
125
302
|
</div>
|
|
126
303
|
<p class="mt-3 font-semibold text-stone-900">Receipt sent</p>
|
|
127
304
|
<p class="mt-1 text-stone-600">Check your inbox at <span class="text-stone-900">{{ order.customer_email }}</span>.</p>
|
|
128
305
|
</div>
|
|
129
306
|
<div class="p-5 border border-stone-200 rounded-2xl">
|
|
130
307
|
<div class="inline-flex items-center justify-center h-9 w-9 bg-stone-100 rounded-full">
|
|
131
|
-
<
|
|
308
|
+
<span class="i-hugeicons-delivery-truck-01 h-4 w-4 text-stone-700" aria-hidden="true"></span>
|
|
132
309
|
</div>
|
|
133
|
-
<p class="mt-3 font-semibold text-stone-900">Ships in 1
|
|
310
|
+
<p class="mt-3 font-semibold text-stone-900">Ships in 1-2 days</p>
|
|
134
311
|
<p class="mt-1 text-stone-600">We'll email tracking the moment it leaves the warehouse.</p>
|
|
135
312
|
</div>
|
|
136
313
|
<div class="p-5 border border-stone-200 rounded-2xl">
|
|
137
314
|
<div class="inline-flex items-center justify-center h-9 w-9 bg-stone-100 rounded-full">
|
|
138
|
-
<
|
|
315
|
+
<span class="i-hugeicons-checkmark-badge-01 h-4 w-4 text-stone-700" aria-hidden="true"></span>
|
|
139
316
|
</div>
|
|
140
317
|
<p class="mt-3 font-semibold text-stone-900">100% guaranteed</p>
|
|
141
|
-
<p class="mt-1 text-stone-600">
|
|
318
|
+
<p class="mt-1 text-stone-600">Not right? We'll refund or replace it.</p>
|
|
142
319
|
</div>
|
|
143
320
|
</div>
|
|
144
321
|
|
|
145
322
|
<div class="flex flex-col gap-3 justify-center sm:flex-row mt-10">
|
|
146
323
|
<a href="/products" class="inline-flex gap-2 items-center justify-center px-6 py-3 font-semibold text-sm text-stone-50 bg-stone-900 hover:bg-stone-800 rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-stone-50 focus-visible:ring-stone-900 transition-colors">
|
|
147
324
|
Keep shopping
|
|
148
|
-
<
|
|
325
|
+
<span class="i-hugeicons-arrow-right-02 h-4 w-4" aria-hidden="true"></span>
|
|
149
326
|
</a>
|
|
150
327
|
<a href="/" class="inline-flex items-center justify-center px-6 py-3 font-semibold text-sm text-stone-900 border border-stone-300 rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-stone-50 focus-visible:ring-stone-900 hover:border-stone-900 transition-colors">Back home</a>
|
|
151
328
|
</div>
|
package/routes/dashboard-api.ts
CHANGED
|
@@ -128,6 +128,18 @@ route.group({ prefix: '/api/dashboard', apiResponse: true }, () => {
|
|
|
128
128
|
guard(route.post('/commerce/coupons', 'Actions/Commerce/CouponStoreAction'))
|
|
129
129
|
guard(route.patch('/commerce/coupons/{id}', 'Actions/Commerce/CouponUpdateAction'))
|
|
130
130
|
guard(route.delete('/commerce/coupons/{id}', 'Actions/Commerce/CouponDestroyAction'))
|
|
131
|
+
// Automatic and code discounts (buy X get Y, volume tiers, free shipping),
|
|
132
|
+
// written through the discount engine so a saved rule always prices.
|
|
133
|
+
guard(route.get('/commerce/discounts', 'Actions/Dashboard/Commerce/CommerceDiscountsAction'))
|
|
134
|
+
guard(route.post('/commerce/discounts', 'Actions/Dashboard/Commerce/CommerceDiscountStoreAction'))
|
|
135
|
+
guard(route.patch('/commerce/discounts/{id}', 'Actions/Dashboard/Commerce/CommerceDiscountUpdateAction'))
|
|
136
|
+
guard(route.delete('/commerce/discounts/{id}', 'Actions/Dashboard/Commerce/CommerceDiscountDestroyAction'))
|
|
137
|
+
// Post-purchase offers with their funnel, and one offer's latest responses.
|
|
138
|
+
guard(route.get('/commerce/upsells', 'Actions/Dashboard/Commerce/CommerceUpsellsAction'))
|
|
139
|
+
guard(route.get('/commerce/upsells/{id}', 'Actions/Dashboard/Commerce/CommerceUpsellDetailAction'))
|
|
140
|
+
guard(route.post('/commerce/upsells', 'Actions/Dashboard/Commerce/CommerceUpsellStoreAction'))
|
|
141
|
+
guard(route.patch('/commerce/upsells/{id}', 'Actions/Dashboard/Commerce/CommerceUpsellUpdateAction'))
|
|
142
|
+
guard(route.delete('/commerce/upsells/{id}', 'Actions/Dashboard/Commerce/CommerceUpsellDestroyAction'))
|
|
131
143
|
guard(route.get('/commerce/gift-cards', 'Actions/Dashboard/Commerce/CommerceGiftCardsAction'))
|
|
132
144
|
guard(route.get('/commerce/gift-cards/export', 'Actions/Dashboard/Commerce/CommerceGiftCardsExportAction'))
|
|
133
145
|
guard(route.post('/commerce/gift-cards', 'Actions/Commerce/GiftCardStoreAction'))
|
package/routes/dashboard.ts
CHANGED
|
@@ -627,6 +627,8 @@ if (feature('commerce')) {
|
|
|
627
627
|
route.get('/orders', 'Actions/Dashboard/Commerce/CommerceOrdersAction')
|
|
628
628
|
route.get('/products', 'Actions/Dashboard/Commerce/CommerceProductsAction')
|
|
629
629
|
route.get('/coupons', 'Actions/Dashboard/Commerce/CommerceCouponsAction')
|
|
630
|
+
route.get('/discounts', 'Actions/Dashboard/Commerce/CommerceDiscountsAction')
|
|
631
|
+
route.get('/upsells', 'Actions/Dashboard/Commerce/CommerceUpsellsAction')
|
|
630
632
|
route.get('/gift-cards', 'Actions/Dashboard/Commerce/CommerceGiftCardsAction')
|
|
631
633
|
route.get('/payments', 'Actions/Dashboard/Commerce/CommercePaymentsAction')
|
|
632
634
|
route.get('/delivery', 'Actions/Dashboard/Commerce/CommerceDeliveryAction')
|
package/routes/storefront.ts
CHANGED
|
@@ -20,10 +20,18 @@ import { route } from '@stacksjs/router'
|
|
|
20
20
|
route.get('/api/cart', 'Actions/Storefront/GetCartAction').skipCsrf()
|
|
21
21
|
route.post('/api/cart/add', 'Actions/Storefront/AddToCartAction').skipCsrf()
|
|
22
22
|
route.post('/api/cart/update', 'Actions/Storefront/UpdateCartItemAction').skipCsrf()
|
|
23
|
+
route.post('/api/cart/discount', 'Actions/Storefront/ApplyDiscountCodeAction').skipCsrf()
|
|
23
24
|
route.post('/api/checkout/contact', 'Actions/Storefront/CheckoutContactAction').skipCsrf()
|
|
24
25
|
route.post('/api/checkout/shipping', 'Actions/Storefront/CheckoutShippingAction').skipCsrf()
|
|
25
26
|
route.post('/api/checkout/place', 'Actions/Storefront/PlaceOrderAction').skipCsrf()
|
|
26
27
|
|
|
28
|
+
// Post-purchase offers on the order confirmation page: add a discounted item
|
|
29
|
+
// to the order just placed, or turn the offer down. Authorised by the order's
|
|
30
|
+
// unguessable key (`orders.tracking_token`), which the confirmation link and
|
|
31
|
+
// the forms carry, so CSRF adds nothing an attacker without the key could use.
|
|
32
|
+
route.post('/api/orders/offers/accept', 'Actions/Storefront/AcceptOrderOfferAction').skipCsrf()
|
|
33
|
+
route.post('/api/orders/offers/decline', 'Actions/Storefront/DeclineOrderOfferAction').skipCsrf()
|
|
34
|
+
|
|
27
35
|
// Buyer-submitted product review. Tied to a shipped order via order_id + email
|
|
28
36
|
// match (the SubmitReviewAction verifies ownership and stamps
|
|
29
37
|
// is_verified_purchase=1). Stored as is_approved=0 for admin moderation through
|