@endora-commerce/mod-catalog 0.106.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.
- package/dist/admin/components/PackagingUnitsEditor.d.ts +3 -0
- package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
- package/dist/admin/components/PackagingUnitsEditor.js +51 -5
- package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
- package/dist/admin/components/ProductOrderRulesCard.d.ts +19 -0
- package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -0
- package/dist/admin/components/ProductOrderRulesCard.js +147 -0
- package/dist/admin/components/ProductOrderRulesCard.js.map +1 -0
- package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +1 -1
- package/dist/admin/components/ProductsBulkEditDialog.js +31 -3
- package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
- package/dist/admin/pages/CategoriesTree.d.ts.map +1 -1
- package/dist/admin/pages/CategoriesTree.js +21 -4
- package/dist/admin/pages/CategoriesTree.js.map +1 -1
- package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
- package/dist/admin/pages/ProductEditor.js +12 -33
- package/dist/admin/pages/ProductEditor.js.map +1 -1
- package/dist/admin/pages/ProductsList.d.ts.map +1 -1
- package/dist/admin/pages/ProductsList.js +36 -3
- package/dist/admin/pages/ProductsList.js.map +1 -1
- package/dist/backend/admin-search-provider.d.ts +56 -0
- package/dist/backend/admin-search-provider.d.ts.map +1 -0
- package/dist/backend/admin-search-provider.js +109 -0
- package/dist/backend/admin-search-provider.js.map +1 -0
- package/dist/backend/demo/reset.d.ts +1 -1
- package/dist/backend/demo/rows.d.ts +7 -3
- package/dist/backend/demo/rows.d.ts.map +1 -1
- package/dist/backend/demo/rows.js +7 -5
- package/dist/backend/demo/rows.js.map +1 -1
- package/dist/backend/demo/seed.d.ts.map +1 -1
- package/dist/backend/demo/seed.js +1 -4
- package/dist/backend/demo/seed.js.map +1 -1
- package/dist/backend/entities/product-list-saved-view.entity.d.ts +31 -0
- package/dist/backend/entities/product-list-saved-view.entity.d.ts.map +1 -0
- package/dist/backend/entities/product-list-saved-view.entity.js +75 -0
- package/dist/backend/entities/product-list-saved-view.entity.js.map +1 -0
- package/dist/backend/entities/product-packaging-unit.entity.d.ts +7 -1
- package/dist/backend/entities/product-packaging-unit.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-packaging-unit.entity.js +10 -0
- package/dist/backend/entities/product-packaging-unit.entity.js.map +1 -1
- package/dist/backend/entities/product-variant.entity.d.ts +1 -2
- package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
- package/dist/backend/entities/product-variant.entity.js +0 -5
- package/dist/backend/entities/product-variant.entity.js.map +1 -1
- package/dist/backend/entities/product.entity.d.ts +25 -1
- package/dist/backend/entities/product.entity.d.ts.map +1 -1
- package/dist/backend/entities/product.entity.js +60 -0
- package/dist/backend/entities/product.entity.js.map +1 -1
- package/dist/backend/index.d.ts +5 -5
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +24 -4
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/plugin.d.ts +7 -2
- package/dist/backend/plugin.d.ts.map +1 -1
- package/dist/backend/plugin.js +4 -0
- package/dist/backend/plugin.js.map +1 -1
- package/dist/backend/routes.admin.d.ts +6 -0
- package/dist/backend/routes.admin.d.ts.map +1 -1
- package/dist/backend/routes.admin.js +68 -2
- package/dist/backend/routes.admin.js.map +1 -1
- package/dist/backend/routes.public.d.ts.map +1 -1
- package/dist/backend/routes.public.js +13 -8
- package/dist/backend/routes.public.js.map +1 -1
- package/dist/backend/saved-view-actor.d.ts +16 -0
- package/dist/backend/saved-view-actor.d.ts.map +1 -0
- package/dist/backend/saved-view-actor.js +24 -0
- package/dist/backend/saved-view-actor.js.map +1 -0
- package/dist/backend/services/catalog-admin-search.service.d.ts +32 -0
- package/dist/backend/services/catalog-admin-search.service.d.ts.map +1 -0
- package/dist/backend/services/catalog-admin-search.service.js +141 -0
- package/dist/backend/services/catalog-admin-search.service.js.map +1 -0
- package/dist/backend/services/catalog-admin.service.d.ts +14 -0
- package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-admin.service.js +69 -22
- package/dist/backend/services/catalog-admin.service.js.map +1 -1
- package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-bulk-update.service.js +8 -1
- package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
- package/dist/backend/services/catalog-org-price-decorator.d.ts +7 -3
- package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
- package/dist/backend/services/catalog-org-price-decorator.js +32 -23
- package/dist/backend/services/catalog-org-price-decorator.js.map +1 -1
- package/dist/backend/services/catalog-product-read.service.d.ts +52 -3
- package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-product-read.service.js +153 -3
- package/dist/backend/services/catalog-product-read.service.js.map +1 -1
- package/dist/backend/services/catalog-query.service.d.ts +19 -3
- package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
- package/dist/backend/services/catalog-query.service.js +416 -89
- package/dist/backend/services/catalog-query.service.js.map +1 -1
- package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
- package/dist/backend/services/packaging-unit.service.js +39 -4
- package/dist/backend/services/packaging-unit.service.js.map +1 -1
- package/dist/backend/services/product-link.service.d.ts +5 -0
- package/dist/backend/services/product-link.service.d.ts.map +1 -1
- package/dist/backend/services/product-link.service.js +18 -6
- package/dist/backend/services/product-link.service.js.map +1 -1
- package/dist/backend/services/product-list-view-service.d.ts +53 -0
- package/dist/backend/services/product-list-view-service.d.ts.map +1 -0
- package/dist/backend/services/product-list-view-service.js +191 -0
- package/dist/backend/services/product-list-view-service.js.map +1 -0
- package/dist/backend/services/product-value-resolver.service.d.ts +11 -1
- package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
- package/dist/backend/services/product-value-resolver.service.js +29 -9
- package/dist/backend/services/product-value-resolver.service.js.map +1 -1
- package/dist/backend/services/storefront-value-overrides.d.ts +31 -0
- package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -0
- package/dist/backend/services/storefront-value-overrides.js +48 -0
- package/dist/backend/services/storefront-value-overrides.js.map +1 -0
- package/dist/manifest.d.ts +6 -2
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +39 -3
- package/dist/manifest.js.map +1 -1
- package/dist/migrations/20261014T170531_catalog_product_list_saved_views.d.ts +22 -0
- package/dist/migrations/20261014T170531_catalog_product_list_saved_views.d.ts.map +1 -0
- package/dist/migrations/20261014T170531_catalog_product_list_saved_views.js +38 -0
- package/dist/migrations/20261014T170531_catalog_product_list_saved_views.js.map +1 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.d.ts +22 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.d.ts.map +1 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.js +48 -0
- package/dist/migrations/20261016T082008_catalog_order_rules.js.map +1 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts +26 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts.map +1 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.js +32 -0
- package/dist/migrations/20261022T111811_catalog_price_fields_removed.js.map +1 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts +38 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts.map +1 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.js +89 -0
- package/dist/migrations/20261022T182523_catalog_admin_name_keys.js.map +1 -0
- package/dist/migrations/index.d.ts +5 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +9 -1
- package/dist/migrations/index.js.map +1 -1
- package/docs/catalog/attributes.md +11 -6
- package/docs/catalog/packaging-units.md +44 -7
- package/docs/catalog/per-channel-per-language-overrides.md +36 -9
- package/docs/catalog.md +276 -4
- package/i18n/en.json +41 -5
- package/i18n/pl.json +41 -5
- 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 {
|
|
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 =
|
|
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,
|
|
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
|
-
if (!(
|
|
377
|
+
if (!(ctx.resolvedChannel.isPublic ?? true))
|
|
330
378
|
return new Map();
|
|
331
|
-
|
|
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(
|
|
384
|
+
context: context ?? (await this.#viewerPricingContext(ctx)),
|
|
334
385
|
});
|
|
335
386
|
}
|
|
336
387
|
/**
|
|
@@ -343,16 +394,21 @@ export class CatalogQueryService {
|
|
|
343
394
|
* prevent, and it would be one forgotten argument away if each seam built its
|
|
344
395
|
* own context.
|
|
345
396
|
*/
|
|
346
|
-
async #viewerPricingContext(
|
|
397
|
+
async #viewerPricingContext(ctx) {
|
|
398
|
+
const { audience } = ctx;
|
|
347
399
|
const organization = audience.organizationId === null
|
|
348
400
|
? null
|
|
349
401
|
: await viewerOrganizationFor(this.#requireOrganizationDetails(), audience);
|
|
350
402
|
return {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
defaultCurrency: channel?.defaultCurrency ?? 'PLN',
|
|
354
|
-
},
|
|
403
|
+
// Issue #249 — the currency the route resolved, or the channel default.
|
|
404
|
+
...listingPriceChannelContext(ctx.resolvedChannel, ctx.currency),
|
|
355
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
|
+
: {}),
|
|
356
412
|
};
|
|
357
413
|
}
|
|
358
414
|
/**
|
|
@@ -361,8 +417,25 @@ export class CatalogQueryService {
|
|
|
361
417
|
* the chain's `none` arm — the wire field has one spelling for "no price".
|
|
362
418
|
*/
|
|
363
419
|
#summaryPrice(resolved, productId) {
|
|
364
|
-
const
|
|
365
|
-
return
|
|
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
|
+
};
|
|
366
439
|
}
|
|
367
440
|
/**
|
|
368
441
|
* {@link ListingCardReads} for a page, in a fixed number of statements
|
|
@@ -379,10 +452,12 @@ export class CatalogQueryService {
|
|
|
379
452
|
* that index in that order. Writing it down is what keeps the array the same
|
|
380
453
|
* array now that a page-wide `in (…)` may reach the rows by another plan.
|
|
381
454
|
*/
|
|
382
|
-
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) {
|
|
383
458
|
const categorySlugsByProduct = new Map();
|
|
384
459
|
if (productIds.length === 0) {
|
|
385
|
-
return { assetUrlByProduct: new Map(), categorySlugsByProduct };
|
|
460
|
+
return { assetUrlByProduct: new Map(), categorySlugsByProduct, overridesByProduct: new Map() };
|
|
386
461
|
}
|
|
387
462
|
// Primary asset — for listings prefer the gallery's Thumbnail (US3),
|
|
388
463
|
// then Base Image, then any first gallery item, finally the legacy
|
|
@@ -399,12 +474,19 @@ export class CatalogQueryService {
|
|
|
399
474
|
slugs.push(row.slug);
|
|
400
475
|
categorySlugsByProduct.set(row.product_id, slugs);
|
|
401
476
|
}
|
|
402
|
-
|
|
477
|
+
const overridesByProduct = await loadChannelOverridesByProduct(em, ids, channelId);
|
|
478
|
+
return { assetUrlByProduct, categorySlugsByProduct, overridesByProduct };
|
|
403
479
|
}
|
|
404
480
|
// ------------------------------------------------------------------
|
|
405
481
|
// Products
|
|
406
482
|
// ------------------------------------------------------------------
|
|
407
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);
|
|
408
490
|
const em = this.emFactory();
|
|
409
491
|
const channel = ctx.resolvedChannel;
|
|
410
492
|
// --- Filter validation: any filter[attr.<key>] where the attribute is
|
|
@@ -455,7 +537,7 @@ export class CatalogQueryService {
|
|
|
455
537
|
// chunked and both are bounded; everything else takes the single fetch it
|
|
456
538
|
// always took.
|
|
457
539
|
if (isPriceSort(params.sort)) {
|
|
458
|
-
return this.#listByViewerPrice(em, params, ctx, where, params.sort);
|
|
540
|
+
return this.#listByViewerPrice(em, params, ctx, where, params.sort, priceCursor);
|
|
459
541
|
}
|
|
460
542
|
if (params.minPrice !== undefined || params.maxPrice !== undefined) {
|
|
461
543
|
return this.#listWithPriceRange(em, params, ctx, where);
|
|
@@ -518,8 +600,8 @@ export class CatalogQueryService {
|
|
|
518
600
|
// Its asset and its category slugs are resolved the same way and for the
|
|
519
601
|
// same reason (issue #263): both helpers took an id list already, and both
|
|
520
602
|
// were being handed one id at a time from inside the loop.
|
|
521
|
-
const resolvedPrices = await this.#listingPricesFor(priceable,
|
|
522
|
-
const cardReads = await this.#listingCardReadsFor(em, priceable.map((p) => p.id));
|
|
603
|
+
const resolvedPrices = await this.#listingPricesFor(priceable, ctx);
|
|
604
|
+
const cardReads = await this.#listingCardReadsFor(em, priceable.map((p) => p.id), channel.id);
|
|
523
605
|
const summaries = priceable.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads));
|
|
524
606
|
return {
|
|
525
607
|
data: summaries,
|
|
@@ -668,13 +750,13 @@ export class CatalogQueryService {
|
|
|
668
750
|
}
|
|
669
751
|
return true;
|
|
670
752
|
}
|
|
671
|
-
/** The two range bounds as decimal strings
|
|
753
|
+
/** The two range bounds as four-place decimal strings ({@link amountBound}), for every price path. */
|
|
672
754
|
#amountRange(params) {
|
|
673
755
|
if (params.minPrice === undefined && params.maxPrice === undefined)
|
|
674
756
|
return undefined;
|
|
675
757
|
return {
|
|
676
|
-
...(params.minPrice !== undefined ? { min: params.minPrice
|
|
677
|
-
...(params.maxPrice !== undefined ? { max: params.maxPrice
|
|
758
|
+
...(params.minPrice !== undefined ? { min: amountBound(params.minPrice, 'min') } : {}),
|
|
759
|
+
...(params.maxPrice !== undefined ? { max: amountBound(params.maxPrice, 'max') } : {}),
|
|
678
760
|
};
|
|
679
761
|
}
|
|
680
762
|
/**
|
|
@@ -702,27 +784,28 @@ export class CatalogQueryService {
|
|
|
702
784
|
* place the answer is exclusion, and it is exclusion from a filter the buyer
|
|
703
785
|
* typed rather than from the catalogue.
|
|
704
786
|
*
|
|
705
|
-
* **
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* the priced stream is the price-list relation, and everything else is the
|
|
709
|
-
* tail. Measured incidence of a product carrying that attribute *and* priced
|
|
710
|
-
* by no active list: zero. Interleaving it would mean ordering across
|
|
711
|
-
* `price_list_price_brackets` and `products.attribute_values` in one
|
|
712
|
-
* statement — two modules' tables, which `check:module-boundary` refuses — and
|
|
713
|
-
* the operator's remedy is one action: price the product on the default list.
|
|
714
|
-
* The decision is expressed here, in which set feeds which stream, and
|
|
715
|
-
* 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.
|
|
716
790
|
*/
|
|
717
|
-
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) {
|
|
718
794
|
const channel = ctx.resolvedChannel;
|
|
719
795
|
const direction = sort === 'price' ? 'asc' : 'desc';
|
|
720
|
-
|
|
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
|
+
}
|
|
721
807
|
const amountRange = this.#amountRange(params);
|
|
722
|
-
const restrictToProductIds =
|
|
723
|
-
? [...(await this.productIdsInCategoryTree(em, params.categorySlug))]
|
|
724
|
-
: undefined;
|
|
725
|
-
const decoded = params.cursor ? decodeObjectCursor(params.cursor) : null;
|
|
808
|
+
const restrictToProductIds = scope.categoryIds ? [...scope.categoryIds] : undefined;
|
|
726
809
|
// A cursor issued under another sort is discarded rather than
|
|
727
810
|
// reinterpreted: the existing behaviour for a cursor that does not parse.
|
|
728
811
|
const startInTail = decoded?.stream === 'tail';
|
|
@@ -740,6 +823,8 @@ export class CatalogQueryService {
|
|
|
740
823
|
const collected = [];
|
|
741
824
|
const cursors = [];
|
|
742
825
|
let pricedExhausted = startInTail;
|
|
826
|
+
// The price order went missing after this page had collected from it.
|
|
827
|
+
let orderLost = false;
|
|
743
828
|
// --- the priced stream -------------------------------------------------
|
|
744
829
|
while (!pricedExhausted && collected.length < target) {
|
|
745
830
|
if (spent >= budget) {
|
|
@@ -754,6 +839,26 @@ export class CatalogQueryService {
|
|
|
754
839
|
...(restrictToProductIds !== undefined ? { restrictToProductIds } : {}),
|
|
755
840
|
...(amountRange ? { amountRange } : {}),
|
|
756
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
|
+
}
|
|
757
862
|
spent += Math.max(chunk.sourceRowsRead, chunk.rows.length);
|
|
758
863
|
pricedExhausted = chunk.exhausted;
|
|
759
864
|
if (chunk.rows.length === 0) {
|
|
@@ -780,9 +885,7 @@ export class CatalogQueryService {
|
|
|
780
885
|
// not imply, because the provider may have stopped on its own bound.
|
|
781
886
|
const wantsTail = amountRange === undefined && pricedExhausted && !bound;
|
|
782
887
|
if (wantsTail) {
|
|
783
|
-
const categoryIds =
|
|
784
|
-
? new Set(restrictToProductIds ?? [])
|
|
785
|
-
: null;
|
|
888
|
+
const categoryIds = scope.categoryIds;
|
|
786
889
|
while (collected.length < target) {
|
|
787
890
|
if (spent >= budget) {
|
|
788
891
|
bound = true;
|
|
@@ -839,11 +942,23 @@ export class CatalogQueryService {
|
|
|
839
942
|
if (bound) {
|
|
840
943
|
this.log?.warn({ budget, spent, limit: params.limit, sort }, 'catalog: price-ordered page hit its scan budget and is returning short');
|
|
841
944
|
}
|
|
842
|
-
|
|
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).
|
|
843
950
|
const page = collected.slice(0, params.limit);
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
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);
|
|
847
962
|
return {
|
|
848
963
|
data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, resolvedPrices, cardReads)),
|
|
849
964
|
// No total count, no rank, no "showing 51–100 of 4 213" (FR-015): an
|
|
@@ -852,6 +967,74 @@ export class CatalogQueryService {
|
|
|
852
967
|
pagination: { cursor: nextCursor, hasMore, limit: params.limit },
|
|
853
968
|
};
|
|
854
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
|
+
}
|
|
855
1038
|
/**
|
|
856
1039
|
* A price **range** under an ordering that is not a price ordering (research
|
|
857
1040
|
* §R12).
|
|
@@ -869,18 +1052,87 @@ export class CatalogQueryService {
|
|
|
869
1052
|
* a price-list figure, and a range is a claim about one.
|
|
870
1053
|
*/
|
|
871
1054
|
async #listWithPriceRange(em, params, ctx, where) {
|
|
872
|
-
const
|
|
873
|
-
const min = params.minPrice;
|
|
874
|
-
const max = params.maxPrice;
|
|
875
|
-
const categoryFilteredIds = params.categorySlug
|
|
876
|
-
? await this.productIdsInCategoryTree(em, params.categorySlug)
|
|
877
|
-
: null;
|
|
1055
|
+
const range = this.#amountRange(params);
|
|
878
1056
|
// The chunk walk and the page it hands back page by the same keyset, and
|
|
879
1057
|
// that keyset is the one this ordering sorts on — `keysetFor`.
|
|
880
1058
|
const keyset = this.keysetFor(params.sort);
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
: 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;
|
|
884
1136
|
const budget = PRICE_PAGE_SCAN_BUDGET_MULTIPLE * params.limit;
|
|
885
1137
|
const target = params.limit + 1;
|
|
886
1138
|
// Over-fetch by one, for the same reason the price path does: a full page
|
|
@@ -898,7 +1150,7 @@ export class CatalogQueryService {
|
|
|
898
1150
|
const chunkWhere = cursor ? { $and: [where, keyset.after(cursor)] } : where;
|
|
899
1151
|
const rows = await em.find(Product, chunkWhere, {
|
|
900
1152
|
limit: chunkSize,
|
|
901
|
-
orderBy: this.orderForSort(
|
|
1153
|
+
orderBy: this.orderForSort(walk.sort),
|
|
902
1154
|
});
|
|
903
1155
|
spent += rows.length;
|
|
904
1156
|
if (rows.length === 0)
|
|
@@ -909,20 +1161,26 @@ export class CatalogQueryService {
|
|
|
909
1161
|
const candidates = rows.filter((r) => visibleIds.has(r.id) &&
|
|
910
1162
|
this.#passesPageFilters(r, params, ctx) &&
|
|
911
1163
|
(categoryFilteredIds === null || categoryFilteredIds.has(r.id)));
|
|
912
|
-
|
|
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
|
+
});
|
|
913
1176
|
for (const product of candidates) {
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
const amount = Number(price.amount);
|
|
918
|
-
if (!Number.isFinite(amount))
|
|
919
|
-
continue;
|
|
920
|
-
if (min !== undefined && amount < min)
|
|
921
|
-
continue;
|
|
922
|
-
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))
|
|
923
1180
|
continue;
|
|
924
1181
|
collected.push(product);
|
|
925
|
-
|
|
1182
|
+
if (detail !== undefined)
|
|
1183
|
+
prices.set(product.id, detail);
|
|
926
1184
|
if (collected.length >= target)
|
|
927
1185
|
break;
|
|
928
1186
|
}
|
|
@@ -930,15 +1188,24 @@ export class CatalogQueryService {
|
|
|
930
1188
|
break;
|
|
931
1189
|
}
|
|
932
1190
|
if (bound) {
|
|
933
|
-
this.log?.warn({ budget, spent, limit: params.limit, sort: params.sort ?? 'relevance' },
|
|
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`);
|
|
934
1192
|
}
|
|
935
|
-
|
|
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;
|
|
936
1199
|
const page = collected.slice(0, params.limit);
|
|
937
1200
|
const last = page[page.length - 1];
|
|
938
|
-
const
|
|
939
|
-
const
|
|
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();
|
|
940
1207
|
return {
|
|
941
|
-
data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage,
|
|
1208
|
+
data: page.map((p) => this.toSummary(p, channel, ctx.preferredLanguage, shown, cardReads)),
|
|
942
1209
|
pagination: { cursor: nextCursor, hasMore, limit: params.limit },
|
|
943
1210
|
};
|
|
944
1211
|
}
|
|
@@ -990,7 +1257,11 @@ export class CatalogQueryService {
|
|
|
990
1257
|
if (!isProductVisibleTo(product, ctx.audience)) {
|
|
991
1258
|
throw new HttpError(404, ERROR_CODES.PRODUCT_NOT_FOUND, 'Product not found.');
|
|
992
1259
|
}
|
|
993
|
-
const
|
|
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);
|
|
994
1265
|
// Categories
|
|
995
1266
|
const categoryRows = await em.execute(`select category_id from product_categories where product_id = ?`, [product.id]);
|
|
996
1267
|
const categoryIds = categoryRows.map((r) => r.category_id);
|
|
@@ -1049,19 +1320,30 @@ export class CatalogQueryService {
|
|
|
1049
1320
|
for (const a of aAssets)
|
|
1050
1321
|
attachmentAssetsById.set(a.id, a);
|
|
1051
1322
|
}
|
|
1052
|
-
const descriptionText = this.pickLang(product.description, ctx.preferredLanguage, channel);
|
|
1053
|
-
|
|
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
|
+
])));
|
|
1054
1336
|
// Feature 012 / FR-030 — "Parametry produktu" tab projection.
|
|
1055
1337
|
// Resolve every attribute that is flagged isVisibleOnProductPage
|
|
1056
1338
|
// AND has a non-empty value on this product. Render the value per
|
|
1057
1339
|
// the active locale (option label for select / enum / multiselect,
|
|
1058
1340
|
// formatted scalar otherwise). Sorted by AttributeSetAttribute
|
|
1059
1341
|
// position when assigned, by attribute key otherwise.
|
|
1060
|
-
const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, ctx.preferredLanguage, channel);
|
|
1342
|
+
const visibleAttributes = await this.buildVisibleAttributesProjection(em, product, attributeValues, ctx.preferredLanguage, channel, listAttributeViews);
|
|
1061
1343
|
const detail = {
|
|
1062
1344
|
...summary,
|
|
1063
1345
|
description: descriptionText,
|
|
1064
|
-
attributeValues: this.coerceAttributeValues(
|
|
1346
|
+
attributeValues: this.coerceAttributeValues(attributeValues),
|
|
1065
1347
|
assets: assets.map((a) => ({
|
|
1066
1348
|
id: a.id,
|
|
1067
1349
|
kind: a.kind,
|
|
@@ -1072,7 +1354,6 @@ export class CatalogQueryService {
|
|
|
1072
1354
|
id: v.id,
|
|
1073
1355
|
sku: v.sku,
|
|
1074
1356
|
variantAttributeValues: v.variantAttributeValues,
|
|
1075
|
-
priceOverride: v.priceOverride != null ? Number(v.priceOverride) : null,
|
|
1076
1357
|
stockLevel: v.stockLevel ?? null,
|
|
1077
1358
|
})),
|
|
1078
1359
|
categories: categories.map((c) => ({
|
|
@@ -1260,6 +1541,8 @@ export class CatalogQueryService {
|
|
|
1260
1541
|
baseQuantity: u.baseQuantity,
|
|
1261
1542
|
position: u.position,
|
|
1262
1543
|
isDefault: u.isDefault,
|
|
1544
|
+
// Feature 155 (FR-016) — the unit's own minimum; `null` = none.
|
|
1545
|
+
minOrderUnits: u.minOrderUnits ?? null,
|
|
1263
1546
|
}));
|
|
1264
1547
|
}
|
|
1265
1548
|
}
|
|
@@ -1281,14 +1564,17 @@ export class CatalogQueryService {
|
|
|
1281
1564
|
// -> legacy product_assets first row. One helper, shared with `toSummary`
|
|
1282
1565
|
// and `ProductLinkService`, so the chain and the port call have one home.
|
|
1283
1566
|
const assetUrlByProduct = await resolvePrimaryAssetUrls(em, this.#requireAssets(), ids);
|
|
1284
|
-
const resolvedPrices = await this.#listingPricesFor(products,
|
|
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);
|
|
1285
1571
|
for (const p of products) {
|
|
1286
1572
|
const price = this.#summaryPrice(resolvedPrices, p.id);
|
|
1287
1573
|
result.set(p.id, {
|
|
1288
1574
|
id: p.id,
|
|
1289
1575
|
sku: p.sku,
|
|
1290
1576
|
slug: p.slug,
|
|
1291
|
-
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)),
|
|
1292
1578
|
primaryAssetUrl: assetUrlByProduct.get(p.id) ?? null,
|
|
1293
1579
|
price,
|
|
1294
1580
|
});
|
|
@@ -1551,8 +1837,11 @@ export class CatalogQueryService {
|
|
|
1551
1837
|
* Sorted by AttributeSetAttribute.position when the product has an
|
|
1552
1838
|
* Attribute Set, else by attribute key ASC for determinism.
|
|
1553
1839
|
*/
|
|
1554
|
-
async buildVisibleAttributesProjection(em, product,
|
|
1555
|
-
|
|
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) {
|
|
1556
1845
|
const valueKeys = Object.keys(values).filter((k) => {
|
|
1557
1846
|
const v = values[k];
|
|
1558
1847
|
return v !== undefined && v !== null && v !== '';
|
|
@@ -1561,7 +1850,7 @@ export class CatalogQueryService {
|
|
|
1561
1850
|
return [];
|
|
1562
1851
|
// Feature 061 — attribute metadata + options come from the composed view.
|
|
1563
1852
|
const valueKeySet = new Set(valueKeys);
|
|
1564
|
-
const allViews = await
|
|
1853
|
+
const allViews = await listAttributeViews();
|
|
1565
1854
|
const attrs = allViews.filter((a) => valueKeySet.has(a.key) && a.isVisibleOnProductPage);
|
|
1566
1855
|
if (attrs.length === 0)
|
|
1567
1856
|
return [];
|
|
@@ -1742,9 +2031,7 @@ export class CatalogQueryService {
|
|
|
1742
2031
|
const op = slugDirection === 'asc' ? '$gt' : '$lt';
|
|
1743
2032
|
return {
|
|
1744
2033
|
of: (product) => ({ slug: product.slug, id: product.id }),
|
|
1745
|
-
parse: (decoded) => isRecord(decoded) &&
|
|
1746
|
-
typeof decoded['slug'] === 'string' &&
|
|
1747
|
-
typeof decoded['id'] === 'string'
|
|
2034
|
+
parse: (decoded) => isRecord(decoded) && typeof decoded['slug'] === 'string' && isUuidText(decoded['id'])
|
|
1748
2035
|
? { slug: decoded['slug'], id: decoded['id'] }
|
|
1749
2036
|
: null,
|
|
1750
2037
|
after: (cursor) => afterKeysetCursor(cursor, op),
|
|
@@ -1755,9 +2042,11 @@ export class CatalogQueryService {
|
|
|
1755
2042
|
// one is — it has nothing to read.
|
|
1756
2043
|
return {
|
|
1757
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.
|
|
1758
2047
|
parse: (decoded) => isRecord(decoded) &&
|
|
1759
2048
|
typeof decoded['createdAt'] === 'string' &&
|
|
1760
|
-
|
|
2049
|
+
isUuidText(decoded['id']) &&
|
|
1761
2050
|
!Number.isNaN(new Date(decoded['createdAt']).getTime())
|
|
1762
2051
|
? { createdAt: decoded['createdAt'], id: decoded['id'] }
|
|
1763
2052
|
: null,
|
|
@@ -1868,7 +2157,9 @@ export class CatalogQueryService {
|
|
|
1868
2157
|
// underneath is one a price list stands behind rather than the catalogue's
|
|
1869
2158
|
// own legacy attribute.
|
|
1870
2159
|
const price = this.#summaryPrice(resolvedPrices, product.id);
|
|
1871
|
-
|
|
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));
|
|
1872
2163
|
return {
|
|
1873
2164
|
id: product.id,
|
|
1874
2165
|
sku: product.sku,
|
|
@@ -1880,6 +2171,42 @@ export class CatalogQueryService {
|
|
|
1880
2171
|
price,
|
|
1881
2172
|
stockIndicator: null,
|
|
1882
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),
|
|
1883
2210
|
};
|
|
1884
2211
|
}
|
|
1885
2212
|
pickLang(blob, preferred, channel) {
|