@eldrajs/theme-cli 0.2.5 → 0.2.6

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.
Files changed (90) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/block-types.d.ts +1 -1
  3. package/template/.eldra/manifest.json +30 -2
  4. package/template/.eldra/previews.json +35 -35
  5. package/template/app/app.vue +15 -0
  6. package/template/app/composables/useStorefront.ts +7 -2
  7. package/template/app/plugins/eldra-storefront.ts +9 -0
  8. package/template/app/storefront/analytics.ts +15 -7
  9. package/template/app/storefront/cart.ts +228 -51
  10. package/template/app/storefront/commerce.ts +8 -2
  11. package/template/app/storefront/currency.ts +205 -0
  12. package/template/app/storefront/demo.ts +10 -2
  13. package/template/app/storefront/feedback.ts +2 -0
  14. package/template/app/storefront/gateway.ts +153 -35
  15. package/template/app/storefront/money.ts +6 -18
  16. package/template/app/storefront/structuredData.ts +16 -5
  17. package/template/app/storefront/toProductCard.ts +14 -14
  18. package/template/app/storefront/types.ts +13 -0
  19. package/template/app/storefront/volatile.ts +4 -0
  20. package/template/app/utils/seoInput.ts +4 -3
  21. package/template/blocks/announcement-bar/preview.png +0 -0
  22. package/template/blocks/article/preview.png +0 -0
  23. package/template/blocks/article-list/preview.png +0 -0
  24. package/template/blocks/breadcrumbs/preview.png +0 -0
  25. package/template/blocks/cart/Block.vue +41 -22
  26. package/template/blocks/cart/__tests__/Block.spec.ts +2 -3
  27. package/template/blocks/cart/__tests__/loadFailed.spec.ts +135 -0
  28. package/template/blocks/cart/__tests__/notSold.spec.ts +109 -0
  29. package/template/blocks/cart/parts/CartLines.vue +14 -2
  30. package/template/blocks/cart/parts/CheckoutButton.vue +45 -0
  31. package/template/blocks/cart/parts/LoadFailed.vue +37 -0
  32. package/template/blocks/cart/parts/NotSoldNotice.vue +69 -0
  33. package/template/blocks/cart/parts/Summary.vue +9 -21
  34. package/template/blocks/cart/parts/notSold.ts +19 -0
  35. package/template/blocks/cart/preview.png +0 -0
  36. package/template/blocks/collection-grid/Block.vue +15 -2
  37. package/template/blocks/collection-grid/__tests__/Block.spec.ts +14 -0
  38. package/template/blocks/collection-grid/preview.png +0 -0
  39. package/template/blocks/collection-header/preview.png +0 -0
  40. package/template/blocks/contact/preview.png +0 -0
  41. package/template/blocks/cta/preview.png +0 -0
  42. package/template/blocks/faq/preview.png +0 -0
  43. package/template/blocks/feature-grid/preview.png +0 -0
  44. package/template/blocks/footer/Block.vue +20 -45
  45. package/template/blocks/footer/preview.png +0 -0
  46. package/template/blocks/form/preview.png +0 -0
  47. package/template/blocks/gallery/preview.png +0 -0
  48. package/template/blocks/hero/preview.png +0 -0
  49. package/template/blocks/image/preview.png +0 -0
  50. package/template/blocks/logo-cloud/preview.png +0 -0
  51. package/template/blocks/navigation/Block.vue +39 -3
  52. package/template/blocks/navigation/preview.png +0 -0
  53. package/template/blocks/newsletter/preview.png +0 -0
  54. package/template/blocks/order-status/Block.vue +15 -6
  55. package/template/blocks/order-status/preview.png +0 -0
  56. package/template/blocks/pricing-table/preview.png +0 -0
  57. package/template/blocks/product-carousel/Block.vue +5 -2
  58. package/template/blocks/product-carousel/preview.png +0 -0
  59. package/template/blocks/product-detail/Block.vue +46 -10
  60. package/template/blocks/product-detail/__tests__/Block.spec.ts +78 -1
  61. package/template/blocks/product-detail/preview.png +0 -0
  62. package/template/blocks/quote/preview.png +0 -0
  63. package/template/blocks/rich-text/preview.png +0 -0
  64. package/template/blocks/search/Block.vue +8 -2
  65. package/template/blocks/search/TypeSection.vue +8 -2
  66. package/template/blocks/search/preview.png +0 -0
  67. package/template/blocks/search/results.ts +5 -2
  68. package/template/blocks/split-content/preview.png +0 -0
  69. package/template/blocks/stats/preview.png +0 -0
  70. package/template/blocks/tabs/preview.png +0 -0
  71. package/template/blocks/team/preview.png +0 -0
  72. package/template/blocks/testimonials/preview.png +0 -0
  73. package/template/blocks/timeline/preview.png +0 -0
  74. package/template/blocks/trust-strip/preview.png +0 -0
  75. package/template/blocks/video-embed/preview.png +0 -0
  76. package/template/blocks/wishlist/Block.vue +5 -1
  77. package/template/blocks/wishlist/preview.png +0 -0
  78. package/template/i18n/en-US.json +19 -3
  79. package/template/i18n/is-IS.json +19 -3
  80. package/template/test/currencyPicker.spec.ts +66 -0
  81. package/template/test/seoInput.spec.ts +22 -0
  82. package/template/test/storefront/analytics.spec.ts +15 -0
  83. package/template/test/storefront/cart.spec.ts +4 -4
  84. package/template/test/storefront/currency.spec.ts +549 -0
  85. package/template/test/storefront/currencyStore.spec.ts +845 -0
  86. package/template/test/storefront/gateway.spec.ts +22 -0
  87. package/template/test/storefront/money.spec.ts +2 -8
  88. package/template/test/storefront/structuredData.spec.ts +45 -0
  89. package/template/test/storefront/toProductCard.spec.ts +1 -1
  90. package/template/test/storefront/volatile.spec.ts +11 -0
@@ -7,6 +7,7 @@ import {
7
7
  } from '@eldrajs/sdk';
8
8
  import { safeHref } from '../utils/links';
9
9
  import { createCartStore, type CartOps, type CartSnapshot } from './cart';
10
+ import { createCurrencyStore, type CurrencyStore } from './currency';
10
11
  import { createHistoryStore, createWishlistStore } from './history';
11
12
  import {
12
13
  localizeFormDefinition,
@@ -14,7 +15,8 @@ import {
14
15
  submitFailure,
15
16
  toSubmitResult,
16
17
  } from './forms';
17
- import { fromMinorUnits, roundMoney, toMinorUnits } from './money';
18
+ import { toMinorUnits } from '@eldrajs/ui';
19
+ import { fromMinorUnits, roundMoney } from './money';
18
20
  import { chunkIds, collectVolatileTargets } from './volatile';
19
21
  import { canonicalAvailabilityValues, OPTION_SOURCE_PREFIX } from './facets';
20
22
 
@@ -42,6 +44,7 @@ import type {
42
44
  StorefrontMedia,
43
45
  StorefrontOrder,
44
46
  StorefrontOrders,
47
+ StorefrontPrice,
45
48
  StorefrontProduct,
46
49
  StorefrontProductListItem,
47
50
  StorefrontResult,
@@ -90,6 +93,8 @@ interface RawProductListItem {
90
93
  compareAtPrice?: number;
91
94
  thumbnail?: RawThumbnail;
92
95
  totalVariants: number;
96
+ currency?: string;
97
+ soldInCurrency?: boolean;
93
98
  /**
94
99
  * **Declared, and read when it is there.** The catalogue's product *list* answers no options
95
100
  * today — a row carries `totalVariants` and nothing about what the variants differ by — so the
@@ -207,6 +212,8 @@ interface RawProductVariant {
207
212
  barcode?: string | null;
208
213
  price: number;
209
214
  compareAtPrice?: number;
215
+ currency?: string;
216
+ soldInCurrency?: boolean;
210
217
  status: string;
211
218
  media?: RawMediaItem[] | null;
212
219
  optionValues?: Array<{
@@ -251,6 +258,8 @@ interface RawStockAvailability {
251
258
  available: boolean;
252
259
  allowBackorder: boolean;
253
260
  availableQuantity: number;
261
+ /** `false`: the store does not count this variant's units; `availableQuantity` is then 0 and means nothing. */
262
+ tracked?: boolean;
254
263
  }
255
264
 
256
265
  interface RawCollectionItem {
@@ -313,6 +322,7 @@ interface RawCartItem {
313
322
  price: number;
314
323
  quantity: number;
315
324
  thumbnail?: { assetId: string; url: string };
325
+ soldInCurrency?: boolean;
316
326
  optionSnapshots?: Array<{ optionName?: string; optionValueName?: string }> | null;
317
327
  }
318
328
 
@@ -348,6 +358,7 @@ interface RawOrderLine {
348
358
 
349
359
  interface RawOrder {
350
360
  id: string;
361
+ currency?: string;
351
362
  orderNumber: number;
352
363
  status: string;
353
364
  createdAt: string;
@@ -404,6 +415,16 @@ function listItemColours(raw: RawProductListItem): StorefrontProductListItem['co
404
415
  .map((value) => ({ name: value.name, swatch: value.swatch! }));
405
416
  }
406
417
 
418
+ function currencyFields(raw: {
419
+ currency?: string;
420
+ soldInCurrency?: boolean;
421
+ }): Pick<StorefrontPrice, 'currency' | 'soldInCurrency'> {
422
+ return {
423
+ ...(raw.currency ? { currency: raw.currency } : {}),
424
+ ...(raw.soldInCurrency === false ? { soldInCurrency: false } : {}),
425
+ };
426
+ }
427
+
407
428
  function mapProductListItem(raw: RawProductListItem): StorefrontProductListItem {
408
429
  const colours = listItemColours(raw);
409
430
  return {
@@ -415,6 +436,7 @@ function mapProductListItem(raw: RawProductListItem): StorefrontProductListItem
415
436
  amount: raw.minPrice,
416
437
  compareAt: raw.compareAtPrice ?? null,
417
438
  from: raw.minPrice !== raw.maxPrice,
439
+ ...currencyFields(raw),
418
440
  },
419
441
  ...(colours === undefined ? {} : { colours }),
420
442
  // A card stays on the product's published status, not on inventory: the availability read is
@@ -483,6 +505,12 @@ function variantBuyable(variant: RawProductVariant, stock: StockByVariant | null
483
505
  return known === undefined || known.available || known.allowBackorder;
484
506
  }
485
507
 
508
+ /** The units on hand the page may show, or `null` when the store does not count them. */
509
+ function unitsOf(answer: RawStockAvailability | undefined): number | null {
510
+ if (answer === undefined || answer.tracked === false) return null;
511
+ return answer.availableQuantity;
512
+ }
513
+
486
514
  /** The product-level stock signal `deriveStockLine` reads, for the variant the page shows. */
487
515
  function variantStock(
488
516
  variant: RawProductVariant | undefined,
@@ -506,17 +534,19 @@ function mapProductDetails(
506
534
  categories: CategoryIndex | null
507
535
  ): StorefrontProduct {
508
536
  const variants = raw.variants ?? [];
537
+ const soldVariants = variants.filter((variant) => variant.soldInCurrency !== false);
538
+ const priced = soldVariants.length > 0 ? soldVariants : variants;
509
539
  // Spec Do/Don't, "Don't pre-select a sold-out variant": the variant the page opens on is the
510
540
  // first one a shopper could actually buy, and only when none can does it fall back to the first
511
541
  // published one — which is the variant whose sold-out line the shopper then reads.
512
542
  const firstAvailable =
513
- variants.find((variant) => variantBuyable(variant, stock)) ??
514
- variants.find((variant) => variant.status === 'ACTIVE') ??
515
- variants[0];
543
+ priced.find((variant) => variantBuyable(variant, stock)) ??
544
+ priced.find((variant) => variant.status === 'ACTIVE') ??
545
+ priced[0];
516
546
  /** The variant whose unit count is unambiguously *the* count: there is only one thing to buy. */
517
547
  const countableVariant =
518
548
  variants.length === 1 || (raw.options ?? []).length === 0 ? firstAvailable : undefined;
519
- const prices = variants.map((variant) => variant.price);
549
+ const prices = priced.map((variant) => variant.price);
520
550
  const minPrice = prices.length > 0 ? Math.min(...prices) : 0;
521
551
  const images = (raw.mediaLinks ?? [])
522
552
  .slice()
@@ -533,6 +563,7 @@ function mapProductDetails(
533
563
  price: {
534
564
  amount: firstAvailable?.price ?? minPrice,
535
565
  compareAt: firstAvailable?.compareAtPrice ?? null,
566
+ ...currencyFields(firstAvailable ?? {}),
536
567
  },
537
568
  // **The merchant's "Display as" choice is what decides the control**, never the option's name.
538
569
  // Every option used to map to `pills`, and the only way a theme could have drawn the colour
@@ -550,7 +581,7 @@ function mapProductDetails(
550
581
  // would mean a gateway that populates the swatch before it populates the kind silently loses
551
582
  // the store's colours.
552
583
  ...(value.swatch ? { swatch: value.swatch } : {}),
553
- available: variants.some(
584
+ available: priced.some(
554
585
  (variant) =>
555
586
  variantBuyable(variant, stock) &&
556
587
  (variant.optionValues ?? []).some((ov) => ov.optionValueId === value.id)
@@ -596,9 +627,7 @@ function mapProductDetails(
596
627
  // stock). Reporting per-variant counts means carrying every variant's availability on the product
597
628
  // and resolving the shopper's selection against it, which is also what the buy box would need to
598
629
  // add the variant it is showing rather than the first buyable one.
599
- inventory: countableVariant
600
- ? (stock?.get(countableVariant.id)?.availableQuantity ?? null)
601
- : null,
630
+ inventory: countableVariant ? unitsOf(stock?.get(countableVariant.id)) : null,
602
631
  stock: variantStock(firstAvailable, stock),
603
632
  // Each variant's own price and stock state, for the page's structured data: the same
604
633
  // `variantStock` rule the buy box's line uses, so the markup and the page cannot disagree.
@@ -607,6 +636,7 @@ function mapProductDetails(
607
636
  barcode: variant.barcode ?? null,
608
637
  price: variant.price,
609
638
  compareAt: variant.compareAtPrice ?? null,
639
+ ...currencyFields(variant),
610
640
  stock: variantStock(variant, stock),
611
641
  })),
612
642
  available: raw.status === 'ACTIVE',
@@ -649,6 +679,7 @@ function mapCartLine(raw: RawCartItem): StorefrontCartLine {
649
679
  lineTotal: roundMoney(raw.price * raw.quantity),
650
680
  image: raw.thumbnail ? { src: raw.thumbnail.url, alt: raw.title } : null,
651
681
  max: null,
682
+ ...(raw.soldInCurrency === false ? { soldInCurrency: false } : {}),
652
683
  };
653
684
  }
654
685
 
@@ -667,6 +698,7 @@ function mapCart(raw: RawCart): CartSnapshot {
667
698
  return {
668
699
  lines: (raw.items ?? []).map(mapCartLine),
669
700
  totals: mapCartTotals(raw.totals, raw.discountCode),
701
+ ...(raw.currency ? { currency: raw.currency } : {}),
670
702
  };
671
703
  }
672
704
 
@@ -742,6 +774,7 @@ function mapOrder(raw: RawOrder): StorefrontOrder {
742
774
  ? [raw.shipping.customer.name, raw.shipping.customer.address, raw.shipping.customer.town]
743
775
  : [],
744
776
  payment: { brand: '', last4: '' },
777
+ ...(raw.currency ? { currency: raw.currency } : {}),
745
778
  };
746
779
  }
747
780
 
@@ -897,6 +930,8 @@ interface GatewayResultOptions {
897
930
  * for the tick both pages are mounted, the two would fight over one entry.
898
931
  */
899
932
  locale?: () => string | undefined;
933
+ /** The currency catalog reads ask for; part of the key and a reason to reload. `undefined`: the store's own. */
934
+ currency?: Readonly<Ref<string | undefined>>;
900
935
  /** Arguments that are not reactive sources but still name a different read (`related`'s limit). */
901
936
  keyArgs?: readonly unknown[];
902
937
  /** Omitted for a result that is not about products (a collection's own info, an order). */
@@ -982,6 +1017,7 @@ function createGatewayResult<T>(
982
1017
  ...sources.map((source) => source.value),
983
1018
  ...(options.keyArgs ?? []),
984
1019
  ...(options.locale?.() === undefined ? [] : [options.locale()]),
1020
+ ...(options.currency?.value === undefined ? [] : [options.currency.value]),
985
1021
  ]),
986
1022
  // The framework owns this read — it is keyed, deduplicated and awaited by the render
987
1023
  // itself — so it is deliberately given a controller nothing aborts. A watcher-scoped
@@ -1031,7 +1067,10 @@ function createGatewayResult<T>(
1031
1067
  }
1032
1068
  }
1033
1069
 
1034
- watch(sources, load, { immediate: true, deep: true });
1070
+ watch(options.currency === undefined ? sources : [...sources, options.currency], load, {
1071
+ immediate: true,
1072
+ deep: true,
1073
+ });
1035
1074
 
1036
1075
  const volatile = options.volatile;
1037
1076
  // Only a result whose first load went through the prerender takes part in the volatile refresh.
@@ -1075,7 +1114,17 @@ function createGatewayResult<T>(
1075
1114
  * cart id is browser state (`createCartSession` reads `localStorage`, which the server has none
1076
1115
  * of), so there is no cart to resolve a URL for until the page is in a browser.
1077
1116
  */
1078
- function createGatewayCartOps(client: EldraClient): CartOps {
1117
+ function cartGone(caught: unknown): boolean {
1118
+ return (
1119
+ caught instanceof EldraHttpError &&
1120
+ (caught.status === 404 || caught.status === 410 || caught.errorId === 'CART_NOT_FOUND')
1121
+ );
1122
+ }
1123
+
1124
+ function createGatewayCartOps(
1125
+ client: EldraClient,
1126
+ requestedCurrency: () => string | undefined
1127
+ ): CartOps {
1079
1128
  const session = createCartSession();
1080
1129
  let cartId = session.read();
1081
1130
  const checkoutUrl = ref<string | null>(null);
@@ -1124,31 +1173,37 @@ function createGatewayCartOps(client: EldraClient): CartOps {
1124
1173
  lines: [],
1125
1174
  totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
1126
1175
  };
1176
+ const asked = cartId;
1127
1177
  try {
1128
- const raw = (await client.cart.get(cartId)) as unknown as RawCart;
1129
- return mapCart(raw);
1130
- } catch {
1131
- // A remembered cart id the gateway no longer recognises (expired, cleared server-side).
1132
- session.forget();
1133
- cartId = null;
1134
- askedFor = null;
1135
- checkoutUrl.value = null;
1136
- return {
1137
- lines: [],
1138
- totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
1139
- };
1178
+ const raw = (await client.cart.get(asked)) as unknown as RawCart | null;
1179
+ if (raw !== null && typeof raw === 'object' && 'id' in raw) return mapCart(raw);
1180
+ } catch (caught) {
1181
+ // Only a cart the gateway says is gone is forgotten; a timeout or a 5xx keeps the basket.
1182
+ if (!cartGone(caught)) throw caught;
1140
1183
  }
1184
+ // A newer cart may have taken this one's place meanwhile; only the cart asked about is forgotten.
1185
+ if (cartId !== asked) throw new Error('The cart changed while it was being read.');
1186
+ session.forget();
1187
+ cartId = null;
1188
+ askedFor = null;
1189
+ checkoutUrl.value = null;
1190
+ return {
1191
+ lines: [],
1192
+ totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
1193
+ };
1141
1194
  },
1142
1195
  // `productId` and `variantId` are two different ids and the gateway needs both: its cart
1143
1196
  // service reads the pair together (one lookup of "this variant, of this product") and answers
1144
1197
  // 500 for a pair that does not exist. Sending the variant id as both — which is what this did
1145
1198
  // while a list row's `variantId` was really a product id — made every add fail that way.
1146
1199
  async add({ productId, variantId, quantity }) {
1200
+ const currency = cartId ? undefined : requestedCurrency();
1147
1201
  const raw = (await client.cart.addItem({
1148
1202
  cartId: cartId ?? undefined,
1149
1203
  productId,
1150
1204
  variantId,
1151
1205
  quantity,
1206
+ ...(currency === undefined ? {} : { currency }),
1152
1207
  })) as unknown as RawCart;
1153
1208
  remember(raw.id);
1154
1209
  return mapCart(raw);
@@ -1160,6 +1215,10 @@ function createGatewayCartOps(client: EldraClient): CartOps {
1160
1215
  })) as unknown as RawCart;
1161
1216
  return mapCart(raw);
1162
1217
  },
1218
+ async setCurrency(code) {
1219
+ if (!cartId) throw new Error('No cart to update yet.');
1220
+ return mapCart((await client.cart.setCurrency(cartId, code)) as unknown as RawCart);
1221
+ },
1163
1222
  async remove(lineId) {
1164
1223
  if (!cartId) throw new Error('No cart to update yet.');
1165
1224
  const raw = (await client.cart.removeItem(cartId, lineId)) as unknown as RawCart;
@@ -1363,6 +1422,15 @@ function scopeCategoryIds(
1363
1422
  }
1364
1423
 
1365
1424
  /** `"<min>-<max>"` in whole major units → one bound in minor units, or nothing to send. */
1425
+ /** The catalog filters prices in the store's own currency only, so another currency sends no price filter. */
1426
+ function withoutPrice(
1427
+ filters: Record<string, string[]> | undefined
1428
+ ): Record<string, string[]> | undefined {
1429
+ if (filters?.price === undefined) return filters;
1430
+ const { price: _price, ...rest } = filters;
1431
+ return rest;
1432
+ }
1433
+
1366
1434
  function priceParam(raw: string | undefined, currency: string | undefined): number | undefined {
1367
1435
  if (raw === undefined || raw === '') return undefined;
1368
1436
  const amount = Number(raw);
@@ -1948,6 +2016,33 @@ export interface GatewayStorefrontOptions {
1948
2016
  locale?: () => string | undefined;
1949
2017
  }
1950
2018
 
2019
+ /** `options` with `name` set to `value`, unless the caller set it or there is no value. */
2020
+ function withReadParam<T extends object | undefined>(
2021
+ options: T,
2022
+ name: string,
2023
+ value: string | undefined
2024
+ ): T {
2025
+ return (value === undefined ? options : { [name]: value, ...(options ?? {}) }) as T;
2026
+ }
2027
+
2028
+ /** Every catalog read that answers prices asks for them in the visitor's currency (`currency`). */
2029
+ function withCurrency(client: EldraClient, currency: () => string | undefined): EldraClient {
2030
+ const q = <T extends object | undefined>(options: T): T =>
2031
+ withReadParam(options, 'currency', currency());
2032
+ const catalog = client.catalog;
2033
+ return {
2034
+ ...client,
2035
+ catalog: {
2036
+ ...catalog,
2037
+ listProducts: (options, context) => catalog.listProducts(q(options), context),
2038
+ getProduct: (productId, options, context) =>
2039
+ catalog.getProduct(productId, q(options), context),
2040
+ listCollectionProducts: (slug, options, context) =>
2041
+ catalog.listCollectionProducts(slug, q(options), context),
2042
+ },
2043
+ };
2044
+ }
2045
+
1951
2046
  /**
1952
2047
  * The same client, with the active content locale on every read whose answer is **text a merchant
1953
2048
  * wrote**: products, collections, categories, search, an order's line titles.
@@ -1961,10 +2056,8 @@ export interface GatewayStorefrontOptions {
1961
2056
  * `inventory` is deliberately untouched: stock counts carry no language.
1962
2057
  */
1963
2058
  function withContentLocale(client: EldraClient, locale: () => string | undefined): EldraClient {
1964
- const q = <T extends object | undefined>(options: T): T => {
1965
- const value = locale();
1966
- return (value === undefined ? options : { locale: value, ...(options ?? {}) }) as T;
1967
- };
2059
+ const q = <T extends object | undefined>(options: T): T =>
2060
+ withReadParam(options, 'locale', locale());
1968
2061
  const catalog = client.catalog;
1969
2062
  const orders = client.orders;
1970
2063
  return {
@@ -1996,7 +2089,19 @@ export function createGatewayStorefront(
1996
2089
  const locale = options.locale;
1997
2090
  // Every read below — and every module-level helper it hands this client to — carries the page's
1998
2091
  // content locale. See `withContentLocale`.
1999
- const client = locale === undefined ? rawClient : withContentLocale(rawClient, locale);
2092
+ // The cart and the catalog ask for the currency the store they help build will show.
2093
+ const built: { currency?: CurrencyStore } = {};
2094
+ const requestedNow = (): string | undefined => built.currency?.requested.value;
2095
+ const client = withCurrency(
2096
+ locale === undefined ? rawClient : withContentLocale(rawClient, locale),
2097
+ requestedNow
2098
+ );
2099
+ const following = createCurrencyStore(
2100
+ options.commerce ?? null,
2101
+ createCartStore(createGatewayCartOps(client, requestedNow))
2102
+ );
2103
+ built.currency = following.currency;
2104
+ const requested = following.currency.requested;
2000
2105
  // What the store sells in, which is the scale every price parameter and the facets' own span are
2001
2106
  // expressed in (`CatalogFilterQuery`, `mapFacets`). `undefined` for a store that published none —
2002
2107
  // the same answer `<Price>` renders a plain number for, and the same two-decimal fallback.
@@ -2096,7 +2201,7 @@ export function createGatewayStorefront(
2096
2201
  // and — with `facets=true` — the counts the panel draws its groups from, over the whole
2097
2202
  // scope rather than the rows this read could reach.
2098
2203
  const filterQuery = await catalogFilterQuery(
2099
- filters,
2204
+ requested.value === undefined ? filters : withoutPrice(filters),
2100
2205
  currency,
2101
2206
  categoriesOnce,
2102
2207
  scope.collectionIdsFor
@@ -2132,7 +2237,11 @@ export function createGatewayStorefront(
2132
2237
  // filter such a gateway cannot honour, and the panel keeps that family flat instead (see
2133
2238
  // `parts/groups.ts`'s `rawValuesFor`). The only thing the category read is spent on is a
2134
2239
  // `category` *filter*'s slug→id lookup and a product's breadcrumb trail.
2135
- const facets = mapFacets(raw.facets, currency);
2240
+ const mapped = mapFacets(raw.facets, currency);
2241
+ const facets =
2242
+ mapped === undefined || requested.value === undefined
2243
+ ? mapped
2244
+ : { ...mapped, price: undefined };
2136
2245
  return {
2137
2246
  items: (raw.data ?? []).map(mapProductListItem),
2138
2247
  total: raw.meta.total,
@@ -2141,7 +2250,7 @@ export function createGatewayStorefront(
2141
2250
  ...(facets === undefined ? {} : { facets }),
2142
2251
  };
2143
2252
  },
2144
- { method: scope.method, runtime, locale, volatile: 'batch' }
2253
+ { method: scope.method, runtime, locale, currency: requested, volatile: 'batch' }
2145
2254
  );
2146
2255
 
2147
2256
  const catalog: StorefrontCatalog = {
@@ -2170,6 +2279,7 @@ export function createGatewayStorefront(
2170
2279
  method: 'catalog.product',
2171
2280
  runtime,
2172
2281
  locale,
2282
+ currency: requested,
2173
2283
  volatile: (current) => detailSnapshots(client, handle.value, current),
2174
2284
  }
2175
2285
  ),
@@ -2237,7 +2347,14 @@ export function createGatewayStorefront(
2237
2347
  createGatewayResult(
2238
2348
  [handle],
2239
2349
  (signal) => relatedProducts(client, handle.value, limit, signal),
2240
- { method: 'catalog.related', runtime, locale, keyArgs: [limit], volatile: 'batch' }
2350
+ {
2351
+ method: 'catalog.related',
2352
+ runtime,
2353
+ locale,
2354
+ currency: requested,
2355
+ keyArgs: [limit],
2356
+ volatile: 'batch',
2357
+ }
2241
2358
  ),
2242
2359
  byHandles: (handles) =>
2243
2360
  createGatewayResult(
@@ -2251,7 +2368,7 @@ export function createGatewayStorefront(
2251
2368
  )) as unknown as RawProductList;
2252
2369
  return (raw.data ?? []).map(mapProductListItem);
2253
2370
  },
2254
- { method: 'catalog.byHandles', runtime, locale, volatile: 'batch' }
2371
+ { method: 'catalog.byHandles', runtime, locale, currency: requested, volatile: 'batch' }
2255
2372
  ),
2256
2373
  volatileByIds: (ids) => volatileSnapshots(client, ids),
2257
2374
  notifyBackInStock: (input) =>
@@ -2281,7 +2398,7 @@ export function createGatewayStorefront(
2281
2398
  // both from the catalogue before this result is published. See its own comment.
2282
2399
  return await enrichedSearchResponse(client, mapSearchResponse(raw, query.value), signal);
2283
2400
  },
2284
- { method: 'search.run', runtime, locale }
2401
+ { method: 'search.run', runtime, locale, currency: requested }
2285
2402
  ),
2286
2403
  };
2287
2404
 
@@ -2372,7 +2489,8 @@ export function createGatewayStorefront(
2372
2489
  commerce: options.commerce ?? null,
2373
2490
  route: options.route,
2374
2491
  catalog,
2375
- cart: createCartStore(createGatewayCartOps(client)),
2492
+ cart: following.cart,
2493
+ currency: following.currency,
2376
2494
  search,
2377
2495
  orders,
2378
2496
  forms,
@@ -4,6 +4,7 @@ import {
4
4
  currencyFractionDigits,
5
5
  currencySymbol,
6
6
  formatCurrency,
7
+ toMinorUnits,
7
8
  useEldraUiCurrency,
8
9
  useEldraUiLocale,
9
10
  } from '@eldrajs/ui';
@@ -164,20 +165,6 @@ export function currencyLabel(code: string, locale: string = DEFAULT_LOCALE): st
164
165
  return symbol === code ? code : `${code} ${symbol}`;
165
166
  }
166
167
 
167
- /**
168
- * Major units → the minor units `@eldrajs/ui`'s `Price`/`ProductCard` expect, using the currency's
169
- * own minor-unit count rather than a hard-coded ×100 (`ISK` has none: 28 krónur stays 28). With no
170
- * currency it uses `DEFAULT_FRACTION_DIGITS`, which is what the `<Price>` reading the result falls
171
- * back to as well.
172
- */
173
- export function toMinorUnits(
174
- amount: number,
175
- currency: string | undefined,
176
- locale: string = DEFAULT_LOCALE
177
- ): number {
178
- return Math.round(amount * 10 ** resolveFormat(currency, locale).digits);
179
- }
180
-
181
168
  /**
182
169
  * The minor units the **platform's own facets** count in, back to the major units every money field
183
170
  * in `types.ts` carries — the exact inverse of `toMinorUnits`, over the same currency's own
@@ -234,15 +221,16 @@ export function useStoreCurrency(): ComputedRef<string | undefined> {
234
221
  * pure result mapper takes a formatter built from it).
235
222
  */
236
223
  export function useMoney(): {
237
- format: (amount: number) => string;
238
- minor: (amount: number) => number;
224
+ /** `currency` is the amount's own (`StorefrontPrice.currency`, a cart's or an order's); absent, the store's. */
225
+ format: (amount: number, currency?: string) => string;
226
+ minor: (amount: number, currency?: string) => number;
239
227
  currency: ComputedRef<string | undefined>;
240
228
  } {
241
229
  const currency = useStoreCurrency();
242
230
  const locale = useEldraUiLocale();
243
231
  return {
244
- format: (amount) => formatMoney(amount, currency.value, locale.value),
245
- minor: (amount) => toMinorUnits(amount, currency.value, locale.value),
232
+ format: (amount, own) => formatMoney(amount, own ?? currency.value, locale.value),
233
+ minor: (amount, own) => toMinorUnits(amount, own ?? currency.value, locale.value),
246
234
  currency,
247
235
  };
248
236
  }
@@ -81,9 +81,16 @@ const AVAILABILITY: Record<StorefrontProduct['stock'], LdAvailability> = {
81
81
  };
82
82
 
83
83
  /** One offer per variant; a source without variants gets one from the product's own price. */
84
- function variantsOf(product: StorefrontProduct, url: string): ProductLdVariant[] {
85
- if (product.variants !== undefined && product.variants.length > 0) {
86
- return product.variants.map((variant) => ({
84
+ function variantsOf(
85
+ product: StorefrontProduct,
86
+ url: string,
87
+ currency: string | undefined
88
+ ): ProductLdVariant[] {
89
+ const shown = product.variants?.filter(
90
+ (variant) => (variant.currency ?? currency) === (product.price.currency ?? currency)
91
+ );
92
+ if (shown !== undefined && shown.length > 0) {
93
+ return shown.map((variant) => ({
87
94
  sku: variant.sku,
88
95
  gtin: variant.barcode,
89
96
  price: variant.price,
@@ -161,8 +168,12 @@ export function pageStructuredData(parts: PageLdParts): StructuredDataEntry[] {
161
168
  images: product.images.map((image) => image.src),
162
169
  // Products carry no brand of their own: they are sold under the shop's name.
163
170
  brand: parts.profile.name,
164
- variants: variantsOf(product, parts.currentUrl),
165
- currency: parts.currency,
171
+ variants: variantsOf(product, parts.currentUrl, parts.currency),
172
+ // An offer needs a price the page shows; a product not sold in this currency shows none.
173
+ currency:
174
+ product.price.soldInCurrency === false
175
+ ? undefined
176
+ : (product.price.currency ?? parts.currency),
166
177
  ratings: product.rating,
167
178
  }),
168
179
  });
@@ -1,6 +1,6 @@
1
1
  import type { ProductCardProduct } from '@eldrajs/ui';
2
2
  import { isInternalHref, safeHref } from '../utils/links';
3
- import { toMinorUnits } from './money';
3
+ import { toMinorUnits } from '@eldrajs/ui';
4
4
  import type { StorefrontProductListItem, StorefrontSearchProduct } from './types';
5
5
 
6
6
  /**
@@ -9,13 +9,6 @@ import type { StorefrontProductListItem, StorefrontSearchProduct } from './types
9
9
  */
10
10
  export type ProductCardSource = StorefrontProductListItem | StorefrontSearchProduct;
11
11
 
12
- /**
13
- * The conversion a caller outside a component gets: no currency, so ISO 4217's default two digits —
14
- * the same scale the `<ProductCard>` reading the value falls back to. Module level, so the fallback
15
- * path allocates nothing per call and the case has a name.
16
- */
17
- const NO_CURRENCY_MINOR_UNITS = (amount: number): number => toMinorUnits(amount, undefined);
18
-
19
12
  /**
20
13
  * `StorefrontProductListItem` → `@eldrajs/ui`'s `ProductCardProduct` — the one mapping
21
14
  * `collection-grid`, `product-carousel` and `search` all build their cards through, so the three
@@ -74,18 +67,20 @@ export function toProductCard(
74
67
  // — never one reading the store's own "$0.00". The suggestion panel is the other half of that
75
68
  // decision: `SearchResultItem.price` *is* optional, so a row there keeps the product.
76
69
  if (item.price === null) return null;
77
- const minor = opts?.minorUnits ?? NO_CURRENCY_MINOR_UNITS;
78
- const { amount, compareAt, from } = item.price;
70
+ const minor = opts?.minorUnits ?? toMinorUnits;
71
+ const { amount, compareAt, from, currency } = item.price;
72
+ const notSoldIn = item.price.soldInCurrency === false ? (opts?.shopperCurrency ?? null) : null;
79
73
  const isSale = compareAt != null && compareAt > amount;
80
74
  return {
81
75
  title: item.title,
82
76
  url,
83
77
  featuredImage: item.featuredImage ?? null,
84
78
  price: {
85
- amount: minor(amount),
86
- compareAt: compareAt == null ? compareAt : minor(compareAt),
79
+ amount: minor(amount, currency),
80
+ compareAt: compareAt == null ? compareAt : minor(compareAt, currency),
87
81
  from,
88
82
  },
83
+ ...(notSoldIn === null ? {} : { notSoldIn }),
89
84
  rating: item.rating,
90
85
  colours: item.colours,
91
86
  badge: isSale ? { variant: 'sale' } : null,
@@ -97,8 +92,10 @@ export function toProductCard(
97
92
  /** What a block can tell the card builder beyond the item itself. */
98
93
  export interface ToProductCardOptions {
99
94
  ratio?: '4x5' | '1x1' | '3x4';
100
- /** Major → minor units, bound to the block's own currency/locale. Defaults to `toMinorUnits`. */
101
- minorUnits?: (amount: number) => number;
95
+ /** Major → minor units in the amount's own currency (absent: the block's). Defaults to `toMinorUnits`. */
96
+ minorUnits?: (amount: number, currency?: string) => number;
97
+ /** The currency the shopper picked, named on a card with no price in it. */
98
+ shopperCurrency?: string;
102
99
  /**
103
100
  * The card's price and stock line are on screen but fresher ones are on their way — the
104
101
  * prerendered page's volatile refresh (`StorefrontResult.revalidating`), or a reload of the list
@@ -116,6 +113,8 @@ export interface ProductCardEntry {
116
113
  product: ProductCardProduct;
117
114
  /** `opts.revalidating`, per card — `<ProductCard :revalidating="entry.revalidating">`. */
118
115
  revalidating: boolean;
116
+ /** The price's own currency, for `<ProductCard :currency>`; absent, the store's. */
117
+ currency?: string;
119
118
  /**
120
119
  * `true` when the destination is same-site, i.e. when the card's link should be routed by
121
120
  * passing `app/components/EldraRouterLink.vue` as `link-as`. An off-site product URL (a gateway
@@ -147,6 +146,7 @@ export function toProductCardEntries(
147
146
  item: item.url === product.url ? item : { ...item, url: product.url },
148
147
  product,
149
148
  revalidating,
149
+ ...(item.price?.currency === undefined ? {} : { currency: item.price.currency }),
150
150
  internal: isInternalHref(product.url),
151
151
  });
152
152
  }
@@ -4,6 +4,7 @@ import type { EldraClient } from '@eldrajs/sdk';
4
4
  // `node:fs`) can reach an app bundle or a Storybook story through this import.
5
5
  import type { StoreCommerce } from '@eldrajs/theme-nuxt/commerce';
6
6
  import type { CartStore } from './cart';
7
+ import type { CurrencyStore } from './currency';
7
8
 
8
9
  /**
9
10
  * The theme's own view types for commerce data. `@eldrajs/sdk`'s
@@ -56,6 +57,10 @@ export interface StorefrontPrice {
56
57
  compareAt?: number | null;
57
58
  /** "From $X" for a product whose variants span more than one price. */
58
59
  from?: boolean;
60
+ /** The currency `amount` is in. Absent: the store's own (`StorefrontCommerce.currency`). */
61
+ currency?: string;
62
+ /** `false`: no price in the visitor's currency; `amount` is then the price in `currency`. */
63
+ soldInCurrency?: boolean;
59
64
  }
60
65
 
61
66
  export interface StorefrontProductListItem {
@@ -194,6 +199,9 @@ export interface StorefrontProductVariant {
194
199
  /** Major units, like every amount in this file. */
195
200
  price: number;
196
201
  compareAt: number | null;
202
+ /** As on `StorefrontPrice`. */
203
+ currency?: string;
204
+ soldInCurrency?: boolean;
197
205
  /** `variantStock`'s four states for this variant: `out` for an unpublished one. */
198
206
  stock: 'in' | 'low' | 'out' | 'preorder';
199
207
  }
@@ -479,6 +487,8 @@ export interface StorefrontCartLine {
479
487
  lineTotal: number;
480
488
  image?: StorefrontMedia | null;
481
489
  max: number | null;
490
+ /** `false`: no price in the cart's currency; the line is left out of the totals until removed. */
491
+ soldInCurrency?: boolean;
482
492
  }
483
493
 
484
494
  export interface StorefrontCartTotals {
@@ -522,6 +532,8 @@ export interface StorefrontOrder {
522
532
  totals: StorefrontCartTotals;
523
533
  shippingAddress: string[];
524
534
  payment: { brand: string; last4: string };
535
+ /** The order's own currency; every amount on it is in this. */
536
+ currency?: string;
525
537
  }
526
538
 
527
539
  export interface StorefrontSearchResponse {
@@ -892,6 +904,7 @@ export interface StorefrontSource {
892
904
  route: StorefrontRoute;
893
905
  catalog: StorefrontCatalog;
894
906
  cart: CartStore;
907
+ currency: CurrencyStore;
895
908
  search: StorefrontSearch;
896
909
  orders: StorefrontOrders;
897
910
  forms: StorefrontForms;