@endora-commerce/mod-catalog 0.107.0 → 0.108.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.
Files changed (105) hide show
  1. package/dist/admin/components/PackagingUnitsEditor.d.ts +3 -0
  2. package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
  3. package/dist/admin/components/PackagingUnitsEditor.js +51 -5
  4. package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
  5. package/dist/admin/components/ProductOrderRulesCard.d.ts +19 -0
  6. package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -0
  7. package/dist/admin/components/ProductOrderRulesCard.js +147 -0
  8. package/dist/admin/components/ProductOrderRulesCard.js.map +1 -0
  9. package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +1 -1
  10. package/dist/admin/components/ProductsBulkEditDialog.js +31 -3
  11. package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
  12. package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
  13. package/dist/admin/pages/ProductEditor.js +12 -33
  14. package/dist/admin/pages/ProductEditor.js.map +1 -1
  15. package/dist/backend/demo/reset.d.ts +1 -1
  16. package/dist/backend/demo/rows.d.ts +7 -3
  17. package/dist/backend/demo/rows.d.ts.map +1 -1
  18. package/dist/backend/demo/rows.js +7 -5
  19. package/dist/backend/demo/rows.js.map +1 -1
  20. package/dist/backend/demo/seed.d.ts.map +1 -1
  21. package/dist/backend/demo/seed.js +1 -4
  22. package/dist/backend/demo/seed.js.map +1 -1
  23. package/dist/backend/entities/product-packaging-unit.entity.d.ts +7 -1
  24. package/dist/backend/entities/product-packaging-unit.entity.d.ts.map +1 -1
  25. package/dist/backend/entities/product-packaging-unit.entity.js +10 -0
  26. package/dist/backend/entities/product-packaging-unit.entity.js.map +1 -1
  27. package/dist/backend/entities/product-variant.entity.d.ts +1 -2
  28. package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
  29. package/dist/backend/entities/product-variant.entity.js +0 -5
  30. package/dist/backend/entities/product-variant.entity.js.map +1 -1
  31. package/dist/backend/entities/product.entity.d.ts +25 -1
  32. package/dist/backend/entities/product.entity.d.ts.map +1 -1
  33. package/dist/backend/entities/product.entity.js +60 -0
  34. package/dist/backend/entities/product.entity.js.map +1 -1
  35. package/dist/backend/index.d.ts +3 -4
  36. package/dist/backend/index.d.ts.map +1 -1
  37. package/dist/backend/index.js +3 -4
  38. package/dist/backend/index.js.map +1 -1
  39. package/dist/backend/plugin.d.ts +2 -2
  40. package/dist/backend/plugin.d.ts.map +1 -1
  41. package/dist/backend/plugin.js.map +1 -1
  42. package/dist/backend/routes.admin.d.ts.map +1 -1
  43. package/dist/backend/routes.admin.js +39 -2
  44. package/dist/backend/routes.admin.js.map +1 -1
  45. package/dist/backend/routes.public.js +3 -3
  46. package/dist/backend/routes.public.js.map +1 -1
  47. package/dist/backend/services/catalog-admin.service.d.ts +14 -0
  48. package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
  49. package/dist/backend/services/catalog-admin.service.js +69 -22
  50. package/dist/backend/services/catalog-admin.service.js.map +1 -1
  51. package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
  52. package/dist/backend/services/catalog-bulk-update.service.js +8 -1
  53. package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
  54. package/dist/backend/services/catalog-org-price-decorator.d.ts +7 -3
  55. package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
  56. package/dist/backend/services/catalog-org-price-decorator.js +32 -23
  57. package/dist/backend/services/catalog-org-price-decorator.js.map +1 -1
  58. package/dist/backend/services/catalog-product-read.service.d.ts +45 -3
  59. package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
  60. package/dist/backend/services/catalog-product-read.service.js +133 -3
  61. package/dist/backend/services/catalog-product-read.service.js.map +1 -1
  62. package/dist/backend/services/catalog-query.service.d.ts +11 -3
  63. package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
  64. package/dist/backend/services/catalog-query.service.js +409 -81
  65. package/dist/backend/services/catalog-query.service.js.map +1 -1
  66. package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
  67. package/dist/backend/services/packaging-unit.service.js +39 -4
  68. package/dist/backend/services/packaging-unit.service.js.map +1 -1
  69. package/dist/backend/services/product-link.service.d.ts.map +1 -1
  70. package/dist/backend/services/product-link.service.js +16 -1
  71. package/dist/backend/services/product-link.service.js.map +1 -1
  72. package/dist/backend/services/product-value-resolver.service.d.ts +11 -1
  73. package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
  74. package/dist/backend/services/product-value-resolver.service.js +29 -9
  75. package/dist/backend/services/product-value-resolver.service.js.map +1 -1
  76. package/dist/backend/services/storefront-value-overrides.d.ts +31 -0
  77. package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -0
  78. package/dist/backend/services/storefront-value-overrides.js +48 -0
  79. package/dist/backend/services/storefront-value-overrides.js.map +1 -0
  80. package/dist/manifest.d.ts.map +1 -1
  81. package/dist/manifest.js +18 -3
  82. package/dist/manifest.js.map +1 -1
  83. package/dist/migrations/20261016T082008_catalog_order_rules.d.ts +22 -0
  84. package/dist/migrations/20261016T082008_catalog_order_rules.d.ts.map +1 -0
  85. package/dist/migrations/20261016T082008_catalog_order_rules.js +48 -0
  86. package/dist/migrations/20261016T082008_catalog_order_rules.js.map +1 -0
  87. package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts +26 -0
  88. package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts.map +1 -0
  89. package/dist/migrations/20261022T111811_catalog_price_fields_removed.js +32 -0
  90. package/dist/migrations/20261022T111811_catalog_price_fields_removed.js.map +1 -0
  91. package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts +38 -0
  92. package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts.map +1 -0
  93. package/dist/migrations/20261022T182523_catalog_admin_name_keys.js +89 -0
  94. package/dist/migrations/20261022T182523_catalog_admin_name_keys.js.map +1 -0
  95. package/dist/migrations/index.d.ts +4 -1
  96. package/dist/migrations/index.d.ts.map +1 -1
  97. package/dist/migrations/index.js +7 -1
  98. package/dist/migrations/index.js.map +1 -1
  99. package/docs/catalog/attributes.md +11 -6
  100. package/docs/catalog/packaging-units.md +44 -7
  101. package/docs/catalog/per-channel-per-language-overrides.md +36 -9
  102. package/docs/catalog.md +145 -3
  103. package/i18n/en.json +29 -5
  104. package/i18n/pl.json +29 -5
  105. package/package.json +9 -9
@@ -13,11 +13,14 @@ import { BundleSlot } from '../entities/bundle-slot.entity.js';
13
13
  import { BundleSlotOption } from '../entities/bundle-slot-option.entity.js';
14
14
  import { resolvePrimaryAssetUrls } from './primary-asset-url.js';
15
15
  import { viewerOrganizationFor } from './viewer-organization.js';
16
- import { ERROR_CODES, isPriceSort, isProductVisibleTo, listingPriceChannelContext, listingPriceMoney, } from '@endora-commerce/contracts';
16
+ import { effectiveAttributeValues, effectiveSystemText, loadChannelOverridesByProduct, overrideLanguages, } from './storefront-value-overrides.js';
17
+ import { ERROR_CODES, compareDecimal, decimalText, formatUnits, isOrderMinimumEligibleType, normaliseAmount, isPriceSort, isProductVisibleTo, listingPriceChannelContext, listingPriceMoney, } from '@endora-commerce/contracts';
17
18
  import { HttpError } from '@endora-commerce/platform/http';
18
19
  import { encodeCursor, decodeCursor } from '@endora-commerce/platform/http';
20
+ /** A uuid as the database spells one — anything else is a 404 or a discarded cursor, not a query. */
21
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
19
22
  /** A category id as the database spells one — anything else is a 404, not a query. */
20
- const CATEGORY_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
23
+ const CATEGORY_ID_RE = UUID_RE;
21
24
  /** The deepest ancestor chain {@link CatalogQueryService.getCategoryPageContent} walks. */
22
25
  const MAX_CATEGORY_DEPTH = 64;
23
26
  /**
@@ -51,6 +54,25 @@ function decodeObjectCursor(cursor) {
51
54
  function isRecord(value) {
52
55
  return typeof value === 'object' && value !== null;
53
56
  }
57
+ function isUuidText(value) {
58
+ return typeof value === 'string' && UUID_RE.test(value);
59
+ }
60
+ /**
61
+ * A price a cursor carries, normalised to four places, or `null` when it is not
62
+ * one. Read with the contracts' own decimal parser — the grammar
63
+ * `compareDecimal` reads and the price order writes — rather than with a
64
+ * second pattern that can drift from it (review 3 of release 0.108.0, A4).
65
+ */
66
+ function cursorAmount(value) {
67
+ if (typeof value !== 'string')
68
+ return null;
69
+ try {
70
+ return normaliseAmount(value);
71
+ }
72
+ catch {
73
+ return null;
74
+ }
75
+ }
54
76
  /**
55
77
  * How many source rows a price-ordered or price-filtered page may read before it
56
78
  * returns short — FR-019, stated as the specification requires and **not** as a
@@ -61,7 +83,9 @@ function isRecord(value) {
61
83
  * an operator restricts most of a catalogue from most viewers, and the answer
62
84
  * there is a short page — the two price paths narrow each chunk they fetch by
63
85
  * channel and audience, where the default path has those in its statement
64
- * (issue #151) — rather than an unbounded scan.
86
+ * (issue #151) — rather than an unbounded scan. A short page, even an empty
87
+ * one, has `hasMore: true` and a cursor at the position its scan reached, so
88
+ * the budget shortens pages and never ends a walk.
65
89
  *
66
90
  * A setting was rejected because nobody has the number yet: the value it should
67
91
  * take is a function of how much of a catalogue a deployment hides, and shipping
@@ -70,6 +94,28 @@ function isRecord(value) {
70
94
  * is additive.
71
95
  */
72
96
  export const PRICE_PAGE_SCAN_BUDGET_MULTIPLE = 8;
97
+ function amountBound(value, side) {
98
+ const [whole = '0', fraction = ''] = decimalText(value).split('.');
99
+ let units = BigInt(whole) * 10000n + BigInt(fraction.slice(0, 4).padEnd(4, '0'));
100
+ if (side === 'min' && /[1-9]/.test(fraction.slice(4)))
101
+ units += 1n;
102
+ return formatUnits(units);
103
+ }
104
+ /** Whether a resolved amount lies in the range, compared as decimals; an amount that does not parse does not. */
105
+ function withinAmountRange(amount, range) {
106
+ if (range === undefined)
107
+ return true;
108
+ try {
109
+ if (range.min !== undefined && compareDecimal(amount, range.min) < 0)
110
+ return false;
111
+ if (range.max !== undefined && compareDecimal(amount, range.max) > 0)
112
+ return false;
113
+ return true;
114
+ }
115
+ catch {
116
+ return false;
117
+ }
118
+ }
73
119
  /**
74
120
  * The "everything strictly after this row" predicate, over whichever column the
75
121
  * cursor names and in the direction that column is ordered in.
@@ -323,14 +369,19 @@ export class CatalogQueryService {
323
369
  * for, so the anonymous request issues exactly the resolution it issued
324
370
  * before and lands on exactly the cache entry it landed on before.
325
371
  */
326
- async #listingPricesFor(products, ctx) {
372
+ async #listingPricesFor(products, ctx,
373
+ /** The viewer's pricing context, when the caller has built it already for this request. */
374
+ context) {
327
375
  if (products.length === 0)
328
376
  return new Map();
329
377
  if (!(ctx.resolvedChannel.isPublic ?? true))
330
378
  return new Map();
331
- return this.#requireListingPrices().resolveListingPrices({
379
+ // D-287 P0 — the details call: one resolution answers both `price` and
380
+ // `resolvedPrice` (base / sale / display mode), so the product page and the
381
+ // home page's cards need no second, per-product resolution.
382
+ return this.#requireListingPrices().resolveListingPriceDetails({
332
383
  products,
333
- context: await this.#viewerPricingContext(ctx),
384
+ context: context ?? (await this.#viewerPricingContext(ctx)),
334
385
  });
335
386
  }
336
387
  /**
@@ -352,6 +403,12 @@ export class CatalogQueryService {
352
403
  // Issue #249 — the currency the route resolved, or the channel default.
353
404
  ...listingPriceChannelContext(ctx.resolvedChannel, ctx.currency),
354
405
  organization,
406
+ // D-287 P0 — the customer's own group overrides the organisation's; the
407
+ // engine resolves it from the account. Named only beside the account's
408
+ // organisation, so an anonymous page asks exactly what it asked before.
409
+ ...(organization && audience.customerAccountId
410
+ ? { customerAccountId: audience.customerAccountId }
411
+ : {}),
355
412
  };
356
413
  }
357
414
  /**
@@ -360,8 +417,25 @@ export class CatalogQueryService {
360
417
  * the chain's `none` arm — the wire field has one spelling for "no price".
361
418
  */
362
419
  #summaryPrice(resolved, productId) {
363
- const price = resolved.get(productId);
364
- return price === undefined ? null : listingPriceMoney(price);
420
+ const detail = resolved.get(productId);
421
+ return detail === undefined ? null : listingPriceMoney(detail.price);
422
+ }
423
+ /**
424
+ * `ProductSummary.resolvedPrice` — base, sale and display mode from the same
425
+ * resolution as `price` (D-287 P0), and the list price beside a lower buyer
426
+ * price when the engine answered one (161 G14). `null` where the channel
427
+ * withholds prices. One mapping for the listing cards and the product detail.
428
+ */
429
+ #summaryResolvedPrice(resolved, productId) {
430
+ const detail = resolved.get(productId);
431
+ if (detail === undefined)
432
+ return null;
433
+ return {
434
+ basePrice: detail.basePrice,
435
+ salePrice: detail.salePrice,
436
+ displayMode: detail.displayMode,
437
+ ...(detail.listPrice ? { listPrice: { amount: detail.listPrice.amount, currency: detail.listPrice.currency } } : {}),
438
+ };
365
439
  }
366
440
  /**
367
441
  * {@link ListingCardReads} for a page, in a fixed number of statements
@@ -378,10 +452,12 @@ export class CatalogQueryService {
378
452
  * that index in that order. Writing it down is what keeps the array the same
379
453
  * array now that a page-wide `in (…)` may reach the rows by another plan.
380
454
  */
381
- async #listingCardReadsFor(em, productIds) {
455
+ async #listingCardReadsFor(em, productIds,
456
+ /** The request's resolved sales channel — the override rows are read for it alone. */
457
+ channelId) {
382
458
  const categorySlugsByProduct = new Map();
383
459
  if (productIds.length === 0) {
384
- return { assetUrlByProduct: new Map(), categorySlugsByProduct };
460
+ return { assetUrlByProduct: new Map(), categorySlugsByProduct, overridesByProduct: new Map() };
385
461
  }
386
462
  // Primary asset — for listings prefer the gallery's Thumbnail (US3),
387
463
  // then Base Image, then any first gallery item, finally the legacy
@@ -398,12 +474,19 @@ export class CatalogQueryService {
398
474
  slugs.push(row.slug);
399
475
  categorySlugsByProduct.set(row.product_id, slugs);
400
476
  }
401
- return { assetUrlByProduct, categorySlugsByProduct };
477
+ const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channelId);
478
+ return { assetUrlByProduct, categorySlugsByProduct, overridesByProduct };
402
479
  }
403
480
  // ------------------------------------------------------------------
404
481
  // Products
405
482
  // ------------------------------------------------------------------
406
483
  async listProducts(params, ctx) {
484
+ // A price walk that began in the default order, for want of a price order,
485
+ // continues in it to its end — the default listing's page, so nothing the
486
+ // price path would read first is read (review 2, finding 7).
487
+ const priceCursor = isPriceSort(params.sort) && params.cursor ? this.#priceCursor(params.cursor) : null;
488
+ if (priceCursor?.stream === 'unordered')
489
+ return this.#listUnordered(params, ctx, priceCursor.cursor);
407
490
  const em = this.emFactory();
408
491
  const channel = ctx.resolvedChannel;
409
492
  // --- Filter validation: any filter[attr.<key>] where the attribute is
@@ -454,7 +537,7 @@ export class CatalogQueryService {
454
537
  // chunked and both are bounded; everything else takes the single fetch it
455
538
  // always took.
456
539
  if (isPriceSort(params.sort)) {
457
- return this.#listByViewerPrice(em, params, ctx, where, params.sort);
540
+ return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor);
458
541
  }
459
542
  if (params.minPrice !== undefined || params.maxPrice !== undefined) {
460
543
  return this.#listWithPriceRange(em, params, ctx, where);
@@ -518,7 +601,7 @@ export class CatalogQueryService {
518
601
  // same reason (issue #263): both helpers took an id list already, and both
519
602
  // were being handed one id at a time from inside the loop.
520
603
  const resolvedPrices = await this.#listingPricesFor(priceable, ctx);
521
- const cardReads = await this.#listingCardReadsFor(em, priceable.map((p) => p.id));
604
+ const cardReads = await this.#listingCardReadsFor(em, priceable.map((p) => p.id), channel.id);
522
605
  const summaries = priceable.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads));
523
606
  return {
524
607
  data: summaries,
@@ -667,13 +750,13 @@ export class CatalogQueryService {
667
750
  }
668
751
  return true;
669
752
  }
670
- /** The two range bounds as decimal strings — the comparison happens in `numeric`. */
753
+ /** The two range bounds as four-place decimal strings ({@link amountBound}), for every price path. */
671
754
  #amountRange(params) {
672
755
  if (params.minPrice === undefined && params.maxPrice === undefined)
673
756
  return undefined;
674
757
  return {
675
- ...(params.minPrice !== undefined ? { min: params.minPrice.toFixed(4) } : {}),
676
- ...(params.maxPrice !== undefined ? { max: params.maxPrice.toFixed(4) } : {}),
758
+ ...(params.minPrice !== undefined ? { min: amountBound(params.minPrice, 'min') } : {}),
759
+ ...(params.maxPrice !== undefined ? { max: amountBound(params.maxPrice, 'max') } : {}),
677
760
  };
678
761
  }
679
762
  /**
@@ -701,27 +784,28 @@ export class CatalogQueryService {
701
784
  * place the answer is exclusion, and it is exclusion from a filter the buyer
702
785
  * typed rather than from the catalogue.
703
786
  *
704
- * **The legacy product price attribute joins the tail rather than
705
- * interleaving** (spec 086, clarification 1). `listingPriceFrom`'s second arm
706
- * — the price assigned directly to the Product — is not part of the ordering:
707
- * the priced stream is the price-list relation, and everything else is the
708
- * tail. Measured incidence of a product carrying that attribute *and* priced
709
- * by no active list: zero. Interleaving it would mean ordering across
710
- * `price_list_price_brackets` and `products.attribute_values` in one
711
- * statement — two modules' tables, which `check:module-boundary` refuses — and
712
- * the operator's remedy is one action: price the product on the default list.
713
- * The decision is expressed here, in which set feeds which stream, and
714
- * nowhere else.
787
+ * **A product has no price of its own** (feature 160, FR-042): the priced
788
+ * stream is the price surface — every price a book gives this viewer — and
789
+ * everything else is the tail.
715
790
  */
716
- async #listByViewerPrice(em, params, ctx, where, sort) {
791
+ async #listByViewerPrice(em, params, ctx, where, sort,
792
+ /** The request's cursor as `#priceCursor` read it: `null` starts the walk. */
793
+ decoded) {
717
794
  const channel = ctx.resolvedChannel;
718
795
  const direction = sort === 'price' ? 'asc' : 'desc';
719
- const context = await this.#viewerPricingContext(ctx);
796
+ // The viewer's pricing context and the category tree, read once for the
797
+ // page and handed to whichever walk serves it — every chunk of it (review
798
+ // 3, A5). An `unordered` walk is decided earlier, in `listProducts`, and
799
+ // reads neither (review 2, finding 7).
800
+ const scope = await this.#priceWalkScope(em, params, ctx);
801
+ const { context } = scope;
802
+ // A walk whose price order went missing carries on in the default order
803
+ // from the last price it served, to its end.
804
+ if (decoded?.stream === 'rest') {
805
+ return this.#listRemainder(em, params, ctx, where, direction, scope, decoded, decoded.after);
806
+ }
720
807
  const amountRange = this.#amountRange(params);
721
- const restrictToProductIds = params.categorySlug
722
- ? [...(await this.productIdsInCategoryTree(em, params.categorySlug))]
723
- : undefined;
724
- const decoded = params.cursor ? decodeObjectCursor(params.cursor) : null;
808
+ const restrictToProductIds = scope.categoryIds ? [...scope.categoryIds] : undefined;
725
809
  // A cursor issued under another sort is discarded rather than
726
810
  // reinterpreted: the existing behaviour for a cursor that does not parse.
727
811
  const startInTail = decoded?.stream === 'tail';
@@ -739,6 +823,8 @@ export class CatalogQueryService {
739
823
  const collected = [];
740
824
  const cursors = [];
741
825
  let pricedExhausted = startInTail;
826
+ // The price order went missing after this page had collected from it.
827
+ let orderLost = false;
742
828
  // --- the priced stream -------------------------------------------------
743
829
  while (!pricedExhausted && collected.length < target) {
744
830
  if (spent >= budget) {
@@ -753,6 +839,26 @@ export class CatalogQueryService {
753
839
  ...(restrictToProductIds !== undefined ? { restrictToProductIds } : {}),
754
840
  ...(amountRange ? { amountRange } : {}),
755
841
  });
842
+ // Feature 160 (`specs/160-pricing-model-v2/contracts/price-surface.md` §3)
843
+ // — no price order exists yet for this channel and currency, and none is
844
+ // built for a request: the page is served in the default order, cards
845
+ // priced live, until the worker has built one. Its cursor is the default
846
+ // listing's, wrapped so the next page continues that walk.
847
+ //
848
+ // Review 2, finding 6 — a walk that is already **on** the price order
849
+ // (a `priced` cursor, or a chunk of this page) and finds it gone does not
850
+ // start again: page 1 of the default order would repeat what it served.
851
+ // It carries on from the last price read (`#listRemainder`); a page that
852
+ // has collected some rows ends with them, its cursor naming the last.
853
+ if (chunk.unordered) {
854
+ if (collected.length > 0) {
855
+ orderLost = true;
856
+ break;
857
+ }
858
+ if (priceCursor === null)
859
+ return this.#listUnordered(params, ctx, null);
860
+ return this.#listRemainder(em, params, ctx, where, direction, scope, priceCursor, null);
861
+ }
756
862
  spent += Math.max(chunk.sourceRowsRead, chunk.rows.length);
757
863
  pricedExhausted = chunk.exhausted;
758
864
  if (chunk.rows.length === 0) {
@@ -779,9 +885,7 @@ export class CatalogQueryService {
779
885
  // not imply, because the provider may have stopped on its own bound.
780
886
  const wantsTail = amountRange === undefined && pricedExhausted && !bound;
781
887
  if (wantsTail) {
782
- const categoryIds = params.categorySlug
783
- ? new Set(restrictToProductIds ?? [])
784
- : null;
888
+ const categoryIds = scope.categoryIds;
785
889
  while (collected.length < target) {
786
890
  if (spent >= budget) {
787
891
  bound = true;
@@ -838,11 +942,23 @@ export class CatalogQueryService {
838
942
  if (bound) {
839
943
  this.log?.warn({ budget, spent, limit: params.limit, sort }, 'catalog: price-ordered page hit its scan budget and is returning short');
840
944
  }
841
- const hasMore = collected.length > params.limit;
945
+ // A page cut by the scan budget continues from where its scan stopped —
946
+ // in the tail once the tail has been read, else in the priced stream,
947
+ // whose exhaustion the next page then finds and goes on into the tail —
948
+ // never from its last card, and never ends the walk (review 3 of release
949
+ // 0.108.0, A1).
842
950
  const page = collected.slice(0, params.limit);
843
- const nextCursor = hasMore && page.length > 0 ? encodeObjectCursor(cursors[params.limit - 1]) : null;
844
- const resolvedPrices = await this.#listingPricesFor(page, ctx);
845
- const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id));
951
+ let resumeAt = null;
952
+ if (collected.length > params.limit || orderLost)
953
+ resumeAt = cursors[page.length - 1] ?? null;
954
+ else if (bound && tailCursor)
955
+ resumeAt = { stream: 'tail', ...tailCursor };
956
+ else if (bound && priceCursor)
957
+ resumeAt = { stream: 'priced', ...priceCursor };
958
+ const hasMore = resumeAt !== null;
959
+ const nextCursor = resumeAt === null ? null : encodeObjectCursor(resumeAt);
960
+ const resolvedPrices = await this.#listingPricesFor(page, ctx, context);
961
+ const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id), channel.id);
846
962
  return {
847
963
  data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads)),
848
964
  // No total count, no rank, no "showing 51–100 of 4 213" (FR-015): an
@@ -851,6 +967,74 @@ export class CatalogQueryService {
851
967
  pagination: { cursor: nextCursor, hasMore, limit: params.limit },
852
968
  };
853
969
  }
970
+ /**
971
+ * What every chunk of a price walk reads for the same viewer: built once per
972
+ * page and passed down, never per chunk (review 3 of release 0.108.0, A5 — a
973
+ * page reads up to eight chunks, and each used to look the organization up
974
+ * again and, on the remainder, re-read the category tree).
975
+ */
976
+ async #priceWalkScope(em, params, ctx) {
977
+ return {
978
+ context: await this.#viewerPricingContext(ctx),
979
+ categoryIds: params.categorySlug ? await this.productIdsInCategoryTree(em, params.categorySlug) : null,
980
+ };
981
+ }
982
+ /**
983
+ * The cursor of a price-sorted page, every field checked, or `null` — which
984
+ * starts the walk at its first page, as the default listing does with a
985
+ * cursor it cannot read (review 3 of release 0.108.0, A4). A price is read
986
+ * with the contracts' decimal parser, an id must be a uuid and a position
987
+ * the default listing's keyset; an `unordered` cursor wraps the default
988
+ * listing's own, which that listing checks.
989
+ */
990
+ #priceCursor(cursor) {
991
+ const decoded = decodeObjectCursor(cursor);
992
+ if (!isRecord(decoded))
993
+ return null;
994
+ const keyset = this.keysetFor(undefined);
995
+ switch (decoded['stream']) {
996
+ case 'priced': {
997
+ const amount = cursorAmount(decoded['amount']);
998
+ const productId = decoded['productId'];
999
+ return amount !== null && isUuidText(productId) ? { stream: 'priced', amount, productId } : null;
1000
+ }
1001
+ case 'tail': {
1002
+ const at = keyset.parse(decoded);
1003
+ return at !== null && 'createdAt' in at ? { stream: 'tail', createdAt: at.createdAt, id: at.id } : null;
1004
+ }
1005
+ case 'rest': {
1006
+ const amount = cursorAmount(decoded['amount']);
1007
+ const productId = decoded['productId'];
1008
+ const after = keyset.parse(decoded['after']);
1009
+ return amount !== null && isUuidText(productId) && after !== null
1010
+ ? { stream: 'rest', amount, productId, after }
1011
+ : null;
1012
+ }
1013
+ case 'unordered':
1014
+ return typeof decoded['cursor'] === 'string' ? { stream: 'unordered', cursor: decoded['cursor'] } : null;
1015
+ default:
1016
+ return null;
1017
+ }
1018
+ }
1019
+ /**
1020
+ * A price-sorted page served in the default order, because no price order
1021
+ * exists for the viewer yet (`contracts/price-surface.md` §3): the default
1022
+ * listing's page, with its cursor wrapped as an `unordered` price cursor so
1023
+ * the walk pages through every product once and ends (review finding 3 of
1024
+ * release 0.108.0 — dropping the cursor served page 1 forever).
1025
+ */
1026
+ async #listUnordered(params, ctx, cursor) {
1027
+ const { sort: _sort, cursor: _cursor, ...rest } = params;
1028
+ const page = await this.listProducts(cursor ? { ...rest, cursor } : rest, ctx);
1029
+ const next = page.pagination.cursor;
1030
+ return {
1031
+ ...page,
1032
+ pagination: {
1033
+ ...page.pagination,
1034
+ cursor: next ? encodeObjectCursor({ stream: 'unordered', cursor: next }) : null,
1035
+ },
1036
+ };
1037
+ }
854
1038
  /**
855
1039
  * A price **range** under an ordering that is not a price ordering (research
856
1040
  * §R12).
@@ -868,18 +1052,87 @@ export class CatalogQueryService {
868
1052
  * a price-list figure, and a range is a claim about one.
869
1053
  */
870
1054
  async #listWithPriceRange(em, params, ctx, where) {
871
- const channel = ctx.resolvedChannel;
872
- const min = params.minPrice;
873
- const max = params.maxPrice;
874
- const categoryFilteredIds = params.categorySlug
875
- ? await this.productIdsInCategoryTree(em, params.categorySlug)
876
- : null;
1055
+ const range = this.#amountRange(params);
877
1056
  // The chunk walk and the page it hands back page by the same keyset, and
878
1057
  // that keyset is the one this ordering sorts on — `keysetFor`.
879
1058
  const keyset = this.keysetFor(params.sort);
880
- let cursor = params.cursor
881
- ? keyset.parse(decodeObjectCursor(params.cursor))
882
- : null;
1059
+ return this.#walkKeepingByPrice(em, params, ctx, where, await this.#priceWalkScope(em, params, ctx), {
1060
+ sort: params.sort,
1061
+ start: params.cursor ? keyset.parse(decodeObjectCursor(params.cursor)) : null,
1062
+ keep: (price) => price !== null && withinAmountRange(price.amount, range),
1063
+ cursorOf: (after) => encodeObjectCursor(after),
1064
+ what: 'price-filtered',
1065
+ });
1066
+ }
1067
+ /**
1068
+ * The rest of a price-ordered walk whose price order went missing midway
1069
+ * (review 2, finding 6 of release 0.108.0): the surface was retired or is
1070
+ * being rebuilt, and nothing on this request can rebuild it
1071
+ * (`contracts/price-surface.md` §3).
1072
+ *
1073
+ * What the walk has served is, by price, every priced product up to the last
1074
+ * price it served, `boundary`, in the walk's direction and `(amount,
1075
+ * productId)` keyset — the price order's own — and none of the unpriced
1076
+ * tail, which comes after every priced product. So the rest is every product
1077
+ * the listing shows whose live price (the figure its card is rendered with,
1078
+ * and the one the order is built from) sorts **after** `boundary`, and every
1079
+ * unpriced one unless a price range excludes them (FR-012), walked in the
1080
+ * default order — the order of the rest is the one thing there is no
1081
+ * surface to give.
1082
+ *
1083
+ * **The guarantee, stated honestly** (review 3 of release 0.108.0, A2): the
1084
+ * boundary is a price the order held, compared with a price resolved now.
1085
+ * A product whose price changed while the walk was under way — and an order
1086
+ * usually goes missing *because* pricing changed — can sort onto the other
1087
+ * side of the boundary, so it may be met twice or not at all. That is true
1088
+ * of any keyset walk over a live price, the surface walk included: the
1089
+ * surface follows a repricing too. Every product whose price did not change
1090
+ * is met exactly once, scan budget or not (`#walkKeepingByPrice`).
1091
+ *
1092
+ * Chosen over answering "the order changed, start again" because neither the
1093
+ * listing contract nor the storefront can carry that signal: `pagination` is
1094
+ * `{ cursor, hasMore, limit }`, the storefront's pages are server-rendered
1095
+ * links that hold only the cursor, and a restart is a repeat by definition.
1096
+ * Continuing from the last served position needs no wire change, and a walk
1097
+ * started this way stays on it to its end, like an `unordered` one.
1098
+ */
1099
+ async #listRemainder(em, params, ctx, where, direction, scope, boundary, after) {
1100
+ const range = this.#amountRange(params);
1101
+ const sign = direction === 'asc' ? 1 : -1;
1102
+ const afterBoundary = (amount, productId) => {
1103
+ const byAmount = compareDecimal(amount, boundary.amount);
1104
+ const byId = productId < boundary.productId ? -1 : productId > boundary.productId ? 1 : 0;
1105
+ return sign * (byAmount || byId) > 0;
1106
+ };
1107
+ return this.#walkKeepingByPrice(em, params, ctx, where, scope, {
1108
+ sort: undefined,
1109
+ start: after,
1110
+ keep: (price, product) => {
1111
+ if (price === null)
1112
+ return range === undefined;
1113
+ return withinAmountRange(price.amount, range) && afterBoundary(price.amount, product.id);
1114
+ },
1115
+ cursorOf: (next) => encodeObjectCursor({
1116
+ stream: 'rest',
1117
+ amount: boundary.amount,
1118
+ productId: boundary.productId,
1119
+ after: next,
1120
+ }),
1121
+ what: 'price-ordered (order lost)',
1122
+ });
1123
+ }
1124
+ /**
1125
+ * A listing walked in a keyset ordering, chunk by chunk, each chunk narrowed
1126
+ * by everything a page is narrowed by and then by the live listing price its
1127
+ * cards are rendered with — `keep` decides on that price. Bounded by the scan
1128
+ * budget; a bound answers a short, possibly empty, page whose cursor
1129
+ * continues from the scan position.
1130
+ */
1131
+ async #walkKeepingByPrice(em, params, ctx, where, scope, walk) {
1132
+ const channel = ctx.resolvedChannel;
1133
+ const categoryFilteredIds = scope.categoryIds;
1134
+ const keyset = this.keysetFor(walk.sort);
1135
+ let cursor = walk.start;
883
1136
  const budget = PRICE_PAGE_SCAN_BUDGET_MULTIPLE * params.limit;
884
1137
  const target = params.limit + 1;
885
1138
  // Over-fetch by one, for the same reason the price path does: a full page
@@ -897,7 +1150,7 @@ export class CatalogQueryService {
897
1150
  const chunkWhere = cursor ? { $and: [where, keyset.after(cursor)] } : where;
898
1151
  const rows = await em.find(Product, chunkWhere, {
899
1152
  limit: chunkSize,
900
- orderBy: this.orderForSort(params.sort),
1153
+ orderBy: this.orderForSort(walk.sort),
901
1154
  });
902
1155
  spent += rows.length;
903
1156
  if (rows.length === 0)
@@ -908,20 +1161,26 @@ export class CatalogQueryService {
908
1161
  const candidates = rows.filter((r) => visibleIds.has(r.id) &&
909
1162
  this.#passesPageFilters(r, params, ctx) &&
910
1163
  (categoryFilteredIds === null || categoryFilteredIds.has(r.id)));
911
- const chunkPrices = await this.#listingPricesFor(candidates, ctx);
1164
+ // The walk decides on the viewer's own price — the figure the price
1165
+ // order is made of — whether or not the channel publishes it; the cards
1166
+ // below withhold it where the channel does. `#listingPricesFor` answers
1167
+ // no price at all on a non-public channel, which read here as "no
1168
+ // detail" and dropped every product, priced and unpriced alike (review 3
1169
+ // of release 0.108.0, A3).
1170
+ const chunkPrices = candidates.length === 0
1171
+ ? new Map()
1172
+ : await this.#requireListingPrices().resolveListingPriceDetails({
1173
+ products: candidates,
1174
+ context: scope.context,
1175
+ });
912
1176
  for (const product of candidates) {
913
- const price = chunkPrices.get(product.id);
914
- if (price === undefined || price.source !== 'price_list')
915
- continue;
916
- const amount = Number(price.amount);
917
- if (!Number.isFinite(amount))
918
- continue;
919
- if (min !== undefined && amount < min)
920
- continue;
921
- if (max !== undefined && amount > max)
1177
+ const detail = chunkPrices.get(product.id);
1178
+ const price = detail?.price.source === 'price_list' ? detail.price : null;
1179
+ if (!walk.keep(price, product))
922
1180
  continue;
923
1181
  collected.push(product);
924
- prices.set(product.id, price);
1182
+ if (detail !== undefined)
1183
+ prices.set(product.id, detail);
925
1184
  if (collected.length >= target)
926
1185
  break;
927
1186
  }
@@ -929,15 +1188,24 @@ export class CatalogQueryService {
929
1188
  break;
930
1189
  }
931
1190
  if (bound) {
932
- this.log?.warn({ budget, spent, limit: params.limit, sort: params.sort ?? 'relevance' }, 'catalog: price-filtered page hit its scan budget and is returning short');
1191
+ this.log?.warn({ budget, spent, limit: params.limit, sort: params.sort ?? 'relevance' }, `catalog: ${walk.what} page hit its scan budget and is returning short`);
933
1192
  }
934
- const hasMore = collected.length > params.limit;
1193
+ // A page cut by the scan budget has more after it, and continues from
1194
+ // where its scan stopped — not from its last card, which would read the
1195
+ // same rows again — so a budget makes a page short, or empty, but never
1196
+ // ends the walk (review 3 of release 0.108.0, A1). The scan moves forward
1197
+ // by at least one chunk a page, so the walk still ends.
1198
+ const full = collected.length > params.limit;
935
1199
  const page = collected.slice(0, params.limit);
936
1200
  const last = page[page.length - 1];
937
- const nextCursor = hasMore && last ? encodeObjectCursor(keyset.of(last)) : null;
938
- const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id));
1201
+ const resumeAt = full && last ? keyset.of(last) : bound ? cursor : null;
1202
+ const hasMore = resumeAt !== null;
1203
+ const nextCursor = resumeAt === null ? null : walk.cursorOf(resumeAt);
1204
+ const cardReads = await this.#listingCardReadsFor(em, page.map((p) => p.id), channel.id);
1205
+ // A channel that publishes no prices renders none, as `#listingPricesFor` would.
1206
+ const shown = (channel.isPublic ?? true) ? prices : new Map();
939
1207
  return {
940
- data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, prices, cardReads)),
1208
+ data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, shown, cardReads)),
941
1209
  pagination: { cursor: nextCursor, hasMore, limit: params.limit },
942
1210
  };
943
1211
  }
@@ -989,7 +1257,11 @@ export class CatalogQueryService {
989
1257
  if (!isProductVisibleTo(product, ctx.audience)) {
990
1258
  throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
991
1259
  }
992
- const summary = this.toSummary(product, channel, ctx.preferredLanguage, await this.#listingPricesFor([product], ctx), await this.#listingCardReadsFor(em, [product.id]));
1260
+ const cardReads = await this.#listingCardReadsFor(em, [product.id], channel.id);
1261
+ const summary = this.toSummary(product, channel, ctx.preferredLanguage, await this.#listingPricesFor([product], ctx), cardReads);
1262
+ // Issue #384 — the product's override rows, already read for the summary.
1263
+ const overrides = cardReads.overridesByProduct.get(product.id);
1264
+ const overrideCtx = this.#overrideContext(channel, ctx.preferredLanguage);
993
1265
  // Categories
994
1266
  const categoryRows = await em.execute(`select category_id from product_categories where product_id = ?`, [product.id]);
995
1267
  const categoryIds = categoryRows.map((r) => r.category_id);
@@ -1048,19 +1320,30 @@ export class CatalogQueryService {
1048
1320
  for (const a of aAssets)
1049
1321
  attachmentAssetsById.set(a.id, a);
1050
1322
  }
1051
- const descriptionText = this.pickLang(product.description, ctx.preferredLanguage, channel);
1052
- const nameText = this.pickLang(product.name, ctx.preferredLanguage, channel);
1323
+ const descriptionText = effectiveSystemText(overrides, 'description', overrideCtx, product.description, this.pickLang(product.description, ctx.preferredLanguage, channel));
1324
+ // The summary's name went through the same resolution.
1325
+ const nameText = summary.name;
1326
+ // Issue #384 — channel-scoped user attributes carry their override for
1327
+ // this (channel, language); the scope lookup runs only when the product
1328
+ // has a user-attribute override row at all. The attribute views are read
1329
+ // at most once for this page, and only by whichever step needs them first.
1330
+ let attributeViews;
1331
+ const listAttributeViews = () => (attributeViews ??= this.#requireAttributeRead().listAll());
1332
+ const attributeValues = await effectiveAttributeValues(product.attributeValues ?? {}, overrides, overrideCtx, async () => new Map((await listAttributeViews()).map((a) => [
1333
+ a.key,
1334
+ { channelScoped: a.channelScoped, languageScoped: a.languageScoped },
1335
+ ])));
1053
1336
  // Feature 012 / FR-030 — "Parametry produktu" tab projection.
1054
1337
  // Resolve every attribute that is flagged isVisibleOnProductPage
1055
1338
  // AND has a non-empty value on this product. Render the value per
1056
1339
  // the active locale (option label for select / enum / multiselect,
1057
1340
  // formatted scalar otherwise). Sorted by AttributeSetAttribute
1058
1341
  // position when assigned, by attribute key otherwise.
1059
- const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, ctx.preferredLanguage, channel);
1342
+ const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, attributeValues, ctx.preferredLanguage, channel, listAttributeViews);
1060
1343
  const detail = {
1061
1344
  ...summary,
1062
1345
  description: descriptionText,
1063
- attributeValues: this.coerceAttributeValues(product.attributeValues),
1346
+ attributeValues: this.coerceAttributeValues(attributeValues),
1064
1347
  assets: assets.map((a) => ({
1065
1348
  id: a.id,
1066
1349
  kind: a.kind,
@@ -1071,7 +1354,6 @@ export class CatalogQueryService {
1071
1354
  id: v.id,
1072
1355
  sku: v.sku,
1073
1356
  variantAttributeValues: v.variantAttributeValues,
1074
- priceOverride: v.priceOverride != null ? Number(v.priceOverride) : null,
1075
1357
  stockLevel: v.stockLevel ?? null,
1076
1358
  })),
1077
1359
  categories: categories.map((c) => ({
@@ -1259,6 +1541,8 @@ export class CatalogQueryService {
1259
1541
  baseQuantity: u.baseQuantity,
1260
1542
  position: u.position,
1261
1543
  isDefault: u.isDefault,
1544
+ // Feature 155 (FR-016) — the unit's own minimum; `null` = none.
1545
+ minOrderUnits: u.minOrderUnits ?? null,
1262
1546
  }));
1263
1547
  }
1264
1548
  }
@@ -1281,13 +1565,16 @@ export class CatalogQueryService {
1281
1565
  // and `ProductLinkService`, so the chain and the port call have one home.
1282
1566
  const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids);
1283
1567
  const resolvedPrices = await this.#listingPricesFor(products, ctx);
1568
+ // Issue #384 — one statement for every child's override rows on this channel.
1569
+ const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channel.id);
1570
+ const overrideCtx = this.#overrideContext(channel, ctx.preferredLanguage);
1284
1571
  for (const p of products) {
1285
1572
  const price = this.#summaryPrice(resolvedPrices, p.id);
1286
1573
  result.set(p.id, {
1287
1574
  id: p.id,
1288
1575
  sku: p.sku,
1289
1576
  slug: p.slug,
1290
- name: this.pickLang(p.name, ctx.preferredLanguage, channel),
1577
+ name: effectiveSystemText(overridesByProduct.get(p.id), 'name', overrideCtx, p.name, this.pickLang(p.name, ctx.preferredLanguage, channel)),
1291
1578
  primaryAssetUrl: assetUrlByProduct.get(p.id) ?? null,
1292
1579
  price,
1293
1580
  });
@@ -1550,8 +1837,11 @@ export class CatalogQueryService {
1550
1837
  * Sorted by AttributeSetAttribute.position when the product has an
1551
1838
  * Attribute Set, else by attribute key ASC for determinism.
1552
1839
  */
1553
- async buildVisibleAttributesProjection(em, product, preferredLanguage, channel) {
1554
- const values = product.attributeValues ?? {};
1840
+ async buildVisibleAttributesProjection(em, product,
1841
+ /** The product's effective attribute values for the request (issue #384). */
1842
+ values, preferredLanguage, channel,
1843
+ /** The page's attribute-view read, shared with the override step (issue #384). */
1844
+ listAttributeViews) {
1555
1845
  const valueKeys = Object.keys(values).filter((k) => {
1556
1846
  const v = values[k];
1557
1847
  return v !== undefined && v !== null && v !== '';
@@ -1560,7 +1850,7 @@ export class CatalogQueryService {
1560
1850
  return [];
1561
1851
  // Feature 061 — attribute metadata + options come from the composed view.
1562
1852
  const valueKeySet = new Set(valueKeys);
1563
- const allViews = await this.#requireAttributeRead().listAll();
1853
+ const allViews = await listAttributeViews();
1564
1854
  const attrs = allViews.filter((a) => valueKeySet.has(a.key) && a.isVisibleOnProductPage);
1565
1855
  if (attrs.length === 0)
1566
1856
  return [];
@@ -1741,9 +2031,7 @@ export class CatalogQueryService {
1741
2031
  const op = slugDirection === 'asc' ? '$gt' : '$lt';
1742
2032
  return {
1743
2033
  of: (product) => ({ slug: product.slug, id: product.id }),
1744
- parse: (decoded) => isRecord(decoded) &&
1745
- typeof decoded['slug'] === 'string' &&
1746
- typeof decoded['id'] === 'string'
2034
+ parse: (decoded) => isRecord(decoded) && typeof decoded['slug'] === 'string' && isUuidText(decoded['id'])
1747
2035
  ? { slug: decoded['slug'], id: decoded['id'] }
1748
2036
  : null,
1749
2037
  after: (cursor) => afterKeysetCursor(cursor, op),
@@ -1754,9 +2042,11 @@ export class CatalogQueryService {
1754
2042
  // one is — it has nothing to read.
1755
2043
  return {
1756
2044
  of: (product) => ({ createdAt: product.createdAt.toISOString(), id: product.id }),
2045
+ // The id is compared with a uuid column: a cursor naming anything else is
2046
+ // discarded here rather than refused by the database as a 500.
1757
2047
  parse: (decoded) => isRecord(decoded) &&
1758
2048
  typeof decoded['createdAt'] === 'string' &&
1759
- typeof decoded['id'] === 'string' &&
2049
+ isUuidText(decoded['id']) &&
1760
2050
  !Number.isNaN(new Date(decoded['createdAt']).getTime())
1761
2051
  ? { createdAt: decoded['createdAt'], id: decoded['id'] }
1762
2052
  : null,
@@ -1867,7 +2157,9 @@ export class CatalogQueryService {
1867
2157
  // underneath is one a price list stands behind rather than the catalogue's
1868
2158
  // own legacy attribute.
1869
2159
  const price = this.#summaryPrice(resolvedPrices, product.id);
1870
- const nameText = this.pickLang(product.name, preferredLanguage, channel);
2160
+ // Issue #384 — the channel's override when one applies, else the baseline
2161
+ // language pick, out of the page's pre-read override rows.
2162
+ const nameText = effectiveSystemText(cardReads.overridesByProduct.get(product.id), 'name', this.#overrideContext(channel, preferredLanguage), product.name, this.pickLang(product.name, preferredLanguage, channel));
1871
2163
  return {
1872
2164
  id: product.id,
1873
2165
  sku: product.sku,
@@ -1879,6 +2171,42 @@ export class CatalogQueryService {
1879
2171
  price,
1880
2172
  stockIndicator: null,
1881
2173
  stockLevel: null,
2174
+ // Feature 155 (FR-014) — emitted for the types the minimum applies to only.
2175
+ minOrderQuantity: isOrderMinimumEligibleType(product.type)
2176
+ ? (product.minOrderQuantity ?? null)
2177
+ : null,
2178
+ resolvedPrice: this.#summaryResolvedPrice(resolvedPrices, product.id),
2179
+ ...this.#summaryPriceBookFields(resolvedPrices, product.id),
2180
+ };
2181
+ }
2182
+ /**
2183
+ * Feature 160 (FR-024, FR-025) — the compare-at price of a charged sale and
2184
+ * the "from" flag of a product whose variants differ, from the same
2185
+ * resolution as `price`. Present only when the price books answered them.
2186
+ */
2187
+ #summaryPriceBookFields(resolved, productId) {
2188
+ const price = resolved.get(productId)?.price;
2189
+ if (!price || price.source !== 'price_list')
2190
+ return {};
2191
+ const compareAt = price.compareAtAmount !== undefined ? Number(price.compareAtAmount) : null;
2192
+ return {
2193
+ ...(compareAt !== null && Number.isFinite(compareAt)
2194
+ ? { compareAtPrice: { amount: compareAt, currency: price.currency } }
2195
+ : {}),
2196
+ ...(price.variesByVariant ? { priceVariesByVariant: true } : {}),
2197
+ };
2198
+ }
2199
+ /**
2200
+ * Issue #384 — the language chain an override is walked over: exactly the
2201
+ * legs `pickLang` walks over the baseline (request language, channel
2202
+ * default, `en-US`, `en`), so a (channel, language) override answers for
2203
+ * whichever language the baseline text would have come from and never for
2204
+ * a later one.
2205
+ */
2206
+ #overrideContext(channel, preferredLanguage) {
2207
+ return {
2208
+ channelId: channel.id,
2209
+ languages: overrideLanguages(preferredLanguage, channel.defaultLanguage),
1882
2210
  };
1883
2211
  }
1884
2212
  pickLang(blob, preferred, channel) {