@revenexx/cover 0.1.23 → 0.2.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 (38) hide show
  1. package/app/api/offers.ts +3 -0
  2. package/app/components/account/directorder/AccountDirectOrder.vue +8 -4
  3. package/app/components/cart/item/CartItem.vue +5 -3
  4. package/app/components/cart/position/CartPosition.vue +5 -3
  5. package/app/components/cart/quickadd/CartQuickAdd.vue +6 -3
  6. package/app/components/cart/recommend/CartCrossSell.vue +7 -4
  7. package/app/components/category/info/CategoryPrice.vue +12 -3
  8. package/app/components/category/info/CategoryStock.vue +13 -3
  9. package/app/components/category/view/GridView.vue +1 -4
  10. package/app/components/category/view/ListView.vue +1 -4
  11. package/app/components/layout/footer/Footer.vue +7 -5
  12. package/app/components/layout/header/MainNav.vue +10 -3
  13. package/app/components/layout/header/TopBar.vue +3 -2
  14. package/app/components/product/detail/ProductDetailImageGallery.vue +50 -5
  15. package/app/composables/useOffers.ts +117 -0
  16. package/app/composables/useProduct.ts +15 -3
  17. package/app/composables/useProductCardActions.ts +11 -11
  18. package/app/composables/useProductListing.ts +10 -0
  19. package/app/composables/useProductUrl.ts +5 -5
  20. package/app/composables/useProducts.ts +22 -4
  21. package/app/plugins/model-viewer.client.ts +7 -0
  22. package/nuxt.config.ts +8 -0
  23. package/package.json +3 -2
  24. package/server/api/offers.post.ts +34 -0
  25. package/server/api/product/[id].get.ts +3 -2
  26. package/server/api/products/[id].get.ts +3 -3
  27. package/server/api/products/index.get.ts +3 -2
  28. package/server/api/typesense/search.post.ts +9 -15
  29. package/server/api/typesense/seed.get.ts +3 -4
  30. package/server/interfaces/offer.ts +36 -0
  31. package/server/services/LocalFileProductService.ts +10 -5
  32. package/server/services/MockOfferService.ts +89 -0
  33. package/server/utils/liveCatalog.ts +3 -4
  34. package/server/utils/liveInventories.ts +25 -33
  35. package/server/utils/livePrices.ts +21 -32
  36. package/server/utils/offerService.ts +57 -0
  37. package/server/utils/productsSchema.ts +2 -2
  38. package/server/utils/liveEnrichment.ts +0 -51
@@ -0,0 +1,3 @@
1
+ export const offersApi = {
2
+ resolve: () => "/api/offers",
3
+ };
@@ -39,13 +39,17 @@ const { data: products } = useFetch<Product[]>(productsApi.list(), {
39
39
  default: () => [],
40
40
  });
41
41
 
42
+ // Offer (price + availability) is its own axis — merge it onto the catalog
43
+ // so direct-order rows resolve an orderable product with a price.
44
+ const offeredProducts = useOffers().withOffers(() => products.value ?? []);
45
+
42
46
  function findProduct(sku: string): Product | undefined {
43
47
  const needle = sku.trim().toLowerCase();
44
48
  if (!needle) {
45
49
  return undefined;
46
50
  }
47
- return (products.value ?? []).find(p => p.sku.toLowerCase() === needle)
48
- ?? (products.value ?? []).find(p => p.sku.toLowerCase().includes(needle));
51
+ return offeredProducts.value.find(p => p.sku.toLowerCase() === needle)
52
+ ?? offeredProducts.value.find(p => p.sku.toLowerCase().includes(needle));
49
53
  }
50
54
 
51
55
  /* ---- tab 1: quick row entry ----------------------------------------- */
@@ -198,8 +202,8 @@ function addProductToCart(product: Product, quantity: number, customSku?: string
198
202
  categorySlug: product.categorySlug,
199
203
  subcategorySlug: product.subcategorySlug,
200
204
  ...(customSku?.trim() ? { customSku: customSku.trim() } : {}),
201
- ...(typeof product.maxOrderQuantity === "number"
202
- ? { maxOrderQuantity: product.maxOrderQuantity }
205
+ ...(typeof product.stocks?.[0]?.maxOrderQuantity === "number"
206
+ ? { maxOrderQuantity: product.stocks[0].maxOrderQuantity }
203
207
  : {}),
204
208
  });
205
209
  if (ok && quantity > 1) {
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { productApi } from "../../../api/product";
3
- import { getPriceWithOptionalTax, slugify } from "../../../composables/useProducts";
3
+ import { categoryProductPath, getPriceWithOptionalTax } from "../../../composables/useProducts";
4
4
  import type { CartItem } from "../../../interfaces/cart-item";
5
5
  import type { ProductDetail } from "../../../interfaces/product-detail";
6
6
 
@@ -72,11 +72,13 @@ async function loadFallbackSlugs() {
72
72
  const detailUrl = computed(() => {
73
73
  const categorySlug = props.item.categorySlug ?? fallbackCategorySlug.value;
74
74
  const subcategorySlug = props.item.subcategorySlug ?? fallbackSubcategorySlug.value;
75
- if (!categorySlug || !subcategorySlug) {
75
+ // Link as long as we have at least a category; the subcategory is optional
76
+ // (the detail route tolerates any category depth).
77
+ if (!categorySlug) {
76
78
  return null;
77
79
  }
78
80
 
79
- return localePath(`/category/${categorySlug}/${subcategorySlug}/product/${slugify(props.item)}`);
81
+ return localePath(categoryProductPath([categorySlug, subcategorySlug], props.item));
80
82
  });
81
83
  const inputValue = ref(String(props.item.quantity));
82
84
  const confirmOpen = ref(false);
@@ -4,7 +4,7 @@ const featureOrderLists = computed(() =>
4
4
  ((useAppConfig().features ?? {}) as Record<string, boolean>).orderLists !== false,
5
5
  );
6
6
 
7
- import { slugify } from "../../../composables/useProducts";
7
+ import { categoryProductPath } from "../../../composables/useProducts";
8
8
  import type { CalculatedCartLine } from "../../../interfaces/cart-calculation";
9
9
  import type { CartItem } from "../../../interfaces/cart-item";
10
10
  import { CART_MAX_QUANTITY } from "../../../interfaces/cart-item";
@@ -35,11 +35,13 @@ const { formatCurrency } = useCartSummaryFormatting();
35
35
  const lineKey = computed(() => cart.keyOf(props.item));
36
36
 
37
37
  const detailUrl = computed(() => {
38
- if (!props.item.categorySlug || !props.item.subcategorySlug) {
38
+ // Link as long as we have at least a category; the subcategory is optional
39
+ // (the detail route tolerates any category depth).
40
+ if (!props.item.categorySlug) {
39
41
  return null;
40
42
  }
41
43
  return localePath(
42
- `/category/${props.item.categorySlug}/${props.item.subcategorySlug}/product/${slugify(props.item)}`,
44
+ categoryProductPath([props.item.categorySlug, props.item.subcategorySlug], props.item),
43
45
  );
44
46
  });
45
47
 
@@ -25,7 +25,7 @@ const { data: products } = useFetch<Product[]>(productsApi.list(), {
25
25
  default: () => [],
26
26
  });
27
27
 
28
- const matches = computed(() => {
28
+ const rawMatches = computed(() => {
29
29
  const q = sku.value.trim().toLowerCase();
30
30
  if (q.length < 2) {
31
31
  return [];
@@ -35,6 +35,9 @@ const matches = computed(() => {
35
35
  .slice(0, 5);
36
36
  });
37
37
 
38
+ // Offers (price + availability) hydrate only for the few shown matches.
39
+ const matches = useOffers().withOffers(() => rawMatches.value);
40
+
38
41
  function buildTiers(prices: { [key: string]: number }[]) {
39
42
  return getPriceTiers(prices).map(tier => ({
40
43
  minQuantity: tier.quantity,
@@ -59,8 +62,8 @@ function addProduct(product: Product): void {
59
62
  priceTiers: buildTiers(product.prices),
60
63
  categorySlug: product.categorySlug,
61
64
  subcategorySlug: product.subcategorySlug,
62
- ...(typeof product.maxOrderQuantity === "number"
63
- ? { maxOrderQuantity: product.maxOrderQuantity }
65
+ ...(typeof product.stocks?.[0]?.maxOrderQuantity === "number"
66
+ ? { maxOrderQuantity: product.stocks[0].maxOrderQuantity }
64
67
  : {}),
65
68
  }, { chooseTarget: true });
66
69
  if (added && qty > 1) {
@@ -38,12 +38,15 @@ const { data } = useFetch<{ products: ProductList[] }>(searchApi.search(), {
38
38
  default: () => ({ products: [] }),
39
39
  });
40
40
 
41
- const suggestions = computed(() => {
41
+ // Offers (price + availability) hydrate for the cross-sell candidates; the
42
+ // out-of-stock filter applies once they resolve.
43
+ const candidates = useOffers().withOffers(() => {
42
44
  const inCart = new Set(cart.items.map(item => item.id));
43
- return (data.value.products ?? [])
44
- .filter(product => !inCart.has(product.id) && !product.isOutOfStock)
45
- .slice(0, 8);
45
+ return (data.value.products ?? []).filter(product => !inCart.has(product.id));
46
46
  });
47
+ const suggestions = computed(() =>
48
+ candidates.value.filter(product => !product.isOutOfStock).slice(0, 8),
49
+ );
47
50
 
48
51
  function add(product: ProductList): void {
49
52
  const price = getBaseUnitPrice(product.prices);
@@ -14,10 +14,14 @@ const props = defineProps<{
14
14
  product: ProductList;
15
15
  }>();
16
16
 
17
- const tiers = computed(() => getPriceTiers(props.product.prices ?? []));
17
+ // Price is the Offer domain — resolved separately, hydrates after first paint.
18
+ const { offer, pending } = useOffers().useOffer(() => props.product.id);
19
+ const offerPrices = computed(() => offer.value?.prices ?? []);
20
+
21
+ const tiers = computed(() => getPriceTiers(offerPrices.value));
18
22
  const hasTieredPricing = computed(() => tiers.value.length > 1);
19
23
  const displayPrice = computed<number | null>(() => {
20
- const basePrice = getDisplayUnitPrice(props.product.prices ?? []);
24
+ const basePrice = getDisplayUnitPrice(offerPrices.value);
21
25
  if (basePrice === null) {
22
26
  return null;
23
27
  }
@@ -28,7 +32,12 @@ const displayPrice = computed<number | null>(() => {
28
32
 
29
33
  <template>
30
34
  <div>
31
- <template v-if="displayPrice !== null">
35
+ <!-- Offer still loading — show a placeholder, never a flash of €0. -->
36
+ <USkeleton
37
+ v-if="pending"
38
+ class="h-6 w-24"
39
+ />
40
+ <template v-else-if="displayPrice !== null">
32
41
  <div v-if="hasTieredPricing">
33
42
  <span class="text-sm text-muted mt-0.5">{{ t('product.price.from') }}</span>
34
43
  {{ formatPrice(displayPrice) }}
@@ -5,15 +5,25 @@ const { icon } = useIcons();
5
5
 
6
6
  const { t } = useI18n();
7
7
 
8
- defineProps<{
8
+ const props = defineProps<{
9
9
  product: ProductList;
10
- isOutOfStock: boolean;
11
10
  }>();
11
+
12
+ // Availability is the Offer domain — resolved separately, hydrates after paint.
13
+ const { offer, pending } = useOffers().useOffer(() => props.product.id);
14
+ const isOutOfStock = computed(() => offer.value?.isOutOfStock ?? false);
12
15
  </script>
13
16
 
14
17
  <template>
15
18
  <div>
16
- <span class="flex items-center gap-1 text-sm font-medium">
19
+ <USkeleton
20
+ v-if="pending"
21
+ class="h-5 w-28"
22
+ />
23
+ <span
24
+ v-else
25
+ class="flex items-center gap-1 text-sm font-medium"
26
+ >
17
27
  {{ !isOutOfStock ? t('product.stock.available') : t('product.stock.unavailable') }}
18
28
  <UIcon
19
29
  :name="!isOutOfStock ? icon('check') : icon('close')"
@@ -42,10 +42,7 @@ const { isOutOfStock, hasPrice, addToCart } = useProductCardActions(() => props.
42
42
  {{ product.name }}
43
43
  </NuxtLink>
44
44
  <CategoryInfoCategorySku :product="product" />
45
- <CategoryInfoCategoryStock
46
- :product="product"
47
- :is-out-of-stock="isOutOfStock"
48
- />
45
+ <CategoryInfoCategoryStock :product="product" />
49
46
  <CategoryInfoCategoryPrice :product="product" />
50
47
  </div>
51
48
  <template #footer>
@@ -41,10 +41,7 @@ const { isOutOfStock, hasPrice, addToCart } = useProductCardActions(() => props.
41
41
  {{ product.name }}
42
42
  </NuxtLink>
43
43
  <CategoryInfoCategorySku :product="product" />
44
- <CategoryInfoCategoryStock
45
- :product="product"
46
- :is-out-of-stock="isOutOfStock"
47
- />
44
+ <CategoryInfoCategoryStock :product="product" />
48
45
  </div>
49
46
  <div class="shrink-0 flex flex-col items-end gap-2">
50
47
  <CategoryInfoCategoryPrice :product="product" />
@@ -1,12 +1,14 @@
1
1
  <script setup lang="ts">
2
2
  import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact } from "../../../config/navigation";
3
3
 
4
- // Consumers can replace the footer link columns / legal links via
5
- // app.config (`footerLinks`, `legalLinks`) — a lean storefront points
6
- // them at pages it actually ships instead of the demo's full sitemap.
4
+ // Consumers replace the footer columns / legal links, in priority order:
5
+ // per-request live menus (useState, e.g. the Blokkli theme from the pages app)
6
+ // → app.config override → the layer defaults (demo's full sitemap).
7
7
  const appConfig = useAppConfig();
8
- const footerLinks = computed(() => (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks);
9
- const legalLinks = computed(() => (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
8
+ const liveFooterLinks = useState<{ heading: string; links: { label: string; to: string }[] }[] | null>("cover:nav:footerLinks", () => null);
9
+ const liveLegalLinks = useState<{ label: string; to: string }[] | null>("cover:nav:legalLinks", () => null);
10
+ const footerLinks = computed(() => liveFooterLinks.value ?? (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks);
11
+ const legalLinks = computed(() => liveLegalLinks.value ?? (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
10
12
 
11
13
  const { icon } = useIcons();
12
14
  const localePath = useLocalePath();
@@ -1,10 +1,17 @@
1
1
  <script setup lang="ts">
2
2
  import { mainNavigation as defaultMainNav, mainNavigationSecondary as defaultSecondaryNav } from "../../../config/navigation";
3
3
 
4
- // app.config override: lean storefronts link only to pages they ship.
4
+ // Navigation source, in priority order:
5
+ // 1. per-request useState — a theme that publishes LIVE menus (e.g. the Blokkli
6
+ // theme reading the pages app; request-scoped, so multi-tenant safe)
7
+ // 2. app.config override — a theme's shipped/baked defaults
8
+ // 3. the layer's built-in defaults
9
+ // A theme that sets none of these (custom-theme, demo-shop) keeps the defaults.
5
10
  const appConfig = useAppConfig();
6
- const mainNavigation = computed(() => (appConfig.mainNavigation as typeof defaultMainNav | undefined) ?? defaultMainNav);
7
- const mainNavigationSecondary = computed(() => (appConfig.mainNavigationSecondary as typeof defaultSecondaryNav | undefined) ?? defaultSecondaryNav);
11
+ const liveMain = useState<typeof defaultMainNav | null>("cover:nav:mainNavigation", () => null);
12
+ const liveSecondary = useState<typeof defaultSecondaryNav | null>("cover:nav:mainNavigationSecondary", () => null);
13
+ const mainNavigation = computed(() => liveMain.value ?? (appConfig.mainNavigation as typeof defaultMainNav | undefined) ?? defaultMainNav);
14
+ const mainNavigationSecondary = computed(() => liveSecondary.value ?? (appConfig.mainNavigationSecondary as typeof defaultSecondaryNav | undefined) ?? defaultSecondaryNav);
8
15
 
9
16
  const { t } = useI18n();
10
17
  const localePath = useLocalePath();
@@ -1,9 +1,10 @@
1
1
  <script setup lang="ts">
2
2
  import { topbarQuickLinks as defaultQuickLinks, topbarUsps } from "../../../config/navigation";
3
3
 
4
- // app.config override: lean storefronts link only to pages they ship.
4
+ // Source priority: per-request live menus (useState) → app.config → defaults.
5
5
  const appConfig = useAppConfig();
6
- const topbarQuickLinks = computed(() => (appConfig.topbarQuickLinks as typeof defaultQuickLinks | undefined) ?? defaultQuickLinks);
6
+ const liveQuickLinks = useState<typeof defaultQuickLinks | null>("cover:nav:topbarQuickLinks", () => null);
7
+ const topbarQuickLinks = computed(() => liveQuickLinks.value ?? (appConfig.topbarQuickLinks as typeof defaultQuickLinks | undefined) ?? defaultQuickLinks);
7
8
 
8
9
  const { icon } = useIcons();
9
10
  const { t } = useI18n();
@@ -4,13 +4,27 @@ import type { ProductDetailImage } from "../../../interfaces/product-detail";
4
4
  const props = defineProps<{
5
5
  images: ProductDetailImage[];
6
6
  getImageUrl: (filename: string) => string;
7
+ /** Optional interactive 3D model (the asset's model_url, a .glb). */
8
+ modelUrl?: string | null;
9
+ /** Optional preview image shown before the 3D model loads (preview_url). */
10
+ modelPoster?: string | null;
7
11
  }>();
8
12
 
13
+ const has3d = computed(() => !!props.modelUrl);
14
+
15
+ // 'image' shows the selected still; 'model' shows the interactive 3D viewer.
16
+ const mode = ref<"image" | "model">("image");
9
17
  const selectedIndex = ref(0);
10
18
  const selectedImage = computed(() => props.images[selectedIndex.value]);
11
19
 
20
+ function showImage(index: number): void {
21
+ selectedIndex.value = index;
22
+ mode.value = "image";
23
+ }
24
+
12
25
  watch(() => props.images, () => {
13
26
  selectedIndex.value = 0;
27
+ mode.value = "image";
14
28
  });
15
29
  </script>
16
30
 
@@ -20,8 +34,17 @@ watch(() => props.images, () => {
20
34
  class="w-full aspect-square rounded-2xl overflow-hidden bg-elevated/60
21
35
  ring-1 ring-(--ui-border) flex items-center justify-center p-8"
22
36
  >
37
+ <!-- Interactive 3D (sovereign three.js engine; no AR). The square box
38
+ gives model-viewer a definite height so its canvas doesn't collapse. -->
39
+ <rx-model-viewer
40
+ v-if="mode === 'model' && modelUrl"
41
+ :src="modelUrl"
42
+ :poster="modelPoster || undefined"
43
+ auto-rotate
44
+ class="w-full h-full"
45
+ />
23
46
  <img
24
- v-if="selectedImage"
47
+ v-else-if="selectedImage"
25
48
  :src="getImageUrl(selectedImage.url)"
26
49
  :alt="`Product image ${selectedIndex + 1}`"
27
50
  class="max-w-full max-h-full object-contain"
@@ -29,7 +52,7 @@ watch(() => props.images, () => {
29
52
  </div>
30
53
 
31
54
  <div
32
- v-if="images.length > 1"
55
+ v-if="images.length > 1 || has3d"
33
56
  class="grid grid-cols-5 sm:grid-cols-6 gap-2"
34
57
  >
35
58
  <button
@@ -40,12 +63,12 @@ watch(() => props.images, () => {
40
63
  class="aspect-square rounded-lg overflow-hidden bg-elevated/60 p-1.5
41
64
  ring-1 transition-all cursor-pointer
42
65
  focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
43
- :class="index === selectedIndex
66
+ :class="mode === 'image' && index === selectedIndex
44
67
  ? 'ring-2 ring-(--ui-primary)'
45
68
  : 'ring-(--ui-border) hover:ring-(--ui-primary)/50'"
46
69
  :aria-label="`Thumbnail ${index + 1}`"
47
- :aria-pressed="index === selectedIndex"
48
- @click="selectedIndex = index"
70
+ :aria-pressed="mode === 'image' && index === selectedIndex"
71
+ @click="showImage(index)"
49
72
  >
50
73
  <img
51
74
  :src="getImageUrl(image.url)"
@@ -53,6 +76,28 @@ watch(() => props.images, () => {
53
76
  class="w-full h-full object-contain"
54
77
  >
55
78
  </button>
79
+
80
+ <!-- 3D entry -->
81
+ <button
82
+ v-if="has3d"
83
+ type="button"
84
+ tabindex="0"
85
+ class="aspect-square rounded-lg overflow-hidden bg-elevated/60
86
+ ring-1 transition-all cursor-pointer flex flex-col items-center justify-center gap-0.5
87
+ focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
88
+ :class="mode === 'model'
89
+ ? 'ring-2 ring-(--ui-primary)'
90
+ : 'ring-(--ui-border) hover:ring-(--ui-primary)/50'"
91
+ aria-label="3D view"
92
+ :aria-pressed="mode === 'model'"
93
+ @click="mode = 'model'"
94
+ >
95
+ <UIcon
96
+ name="i-lucide-rotate-3d"
97
+ class="size-5 text-muted"
98
+ />
99
+ <span class="text-[10px] font-semibold uppercase tracking-wide text-muted">3D</span>
100
+ </button>
56
101
  </div>
57
102
  </div>
58
103
  </template>
@@ -0,0 +1,117 @@
1
+ import { offersApi } from "../api/offers";
2
+ import type { ProductList } from "../interfaces/product-list";
3
+
4
+ /**
5
+ * Client-side Offer layer — the buyer-facing PRICE + AVAILABILITY, fetched on
6
+ * its own axis, decoupled from catalog and search.
7
+ *
8
+ * Catalog/search render the shell during SSR; `loadOffers()` is a no-op on the
9
+ * server, so the first byte never waits on the (heavyweight, ERP-grade) offer
10
+ * call. After hydration the page batches the visible products into ONE
11
+ * POST /api/offers, fills a shared cache, and the price/stock widgets fade in.
12
+ *
13
+ * Failure is soft: an unresolved offer reads as "price on request", never €0.
14
+ */
15
+
16
+ export interface OfferStock {
17
+ quantity: number;
18
+ maxOrderQuantity: number;
19
+ }
20
+
21
+ export interface Offer {
22
+ id: string;
23
+ prices: { [key: string]: number }[];
24
+ stocks: OfferStock[];
25
+ isOutOfStock: boolean;
26
+ }
27
+
28
+ type OfferRef = Pick<ProductList, "id" | "sku">;
29
+
30
+ export function useOffers() {
31
+ const cache = useState<Record<string, Offer>>("offers:cache", () => ({}));
32
+ const inflight = useState<Record<string, boolean>>("offers:pending", () => ({}));
33
+ // Ids whose offer fetch has finished (resolved or soft-failed). Until then a
34
+ // product reads as "pending" so SSR and the client both render a skeleton —
35
+ // no flash of "price on request", no hydration mismatch.
36
+ const attempted = useState<Record<string, boolean>>("offers:attempted", () => ({}));
37
+
38
+ /**
39
+ * Batch-resolve offers for the given products. Deduped against cache and
40
+ * in-flight requests. Client-only — deferred so SSR is never blocked.
41
+ */
42
+ async function loadOffers(items: OfferRef[]): Promise<void> {
43
+ if (import.meta.server) {
44
+ return;
45
+ }
46
+ const want = items.filter(
47
+ item => item?.id && !(item.id in cache.value) && !inflight.value[item.id],
48
+ );
49
+ if (want.length === 0) {
50
+ return;
51
+ }
52
+
53
+ inflight.value = {
54
+ ...inflight.value,
55
+ ...Object.fromEntries(want.map(item => [item.id, true])),
56
+ };
57
+
58
+ try {
59
+ const { offers } = await $fetch<{ offers: Record<string, Offer> }>(offersApi.resolve(), {
60
+ method: "POST",
61
+ body: { items: want.map(item => ({ id: item.id, sku: item.sku })) },
62
+ });
63
+ cache.value = { ...cache.value, ...offers };
64
+ }
65
+ catch {
66
+ // Soft failure — leave uncached; widgets render "price on request".
67
+ }
68
+ finally {
69
+ const next = { ...inflight.value };
70
+ for (const item of want) {
71
+ delete next[item.id];
72
+ }
73
+ inflight.value = next;
74
+ attempted.value = {
75
+ ...attempted.value,
76
+ ...Object.fromEntries(want.map(item => [item.id, true])),
77
+ };
78
+ }
79
+ }
80
+
81
+ /** Reactive accessor for a single product's offer + its loading state. */
82
+ function useOffer(getId: MaybeRefOrGetter<string>) {
83
+ const id = computed(() => toValue(getId));
84
+ const offer = computed<Offer | undefined>(() => cache.value[id.value]);
85
+ // Skeleton until the offer is resolved OR the attempt has finished
86
+ // (soft-failed → render "on request"). Default-pending so SSR and the
87
+ // first client render agree.
88
+ const pending = computed(() => !offer.value && !attempted.value[id.value]);
89
+ return { offer, pending };
90
+ }
91
+
92
+ /**
93
+ * Reactive list of products with their offer (price + availability) merged
94
+ * in, auto-loading offers as the list changes. For surfaces that fetch a
95
+ * catalog list and need orderable cards (quick-add, cross-sell, direct
96
+ * order). Products without a resolved offer read as "price on request".
97
+ */
98
+ function withOffers<T extends ProductList>(getItems: MaybeRefOrGetter<T[]>) {
99
+ const items = computed(() => toValue(getItems) ?? []);
100
+ watch(items, (list) => {
101
+ if (list.length) {
102
+ void loadOffers(list);
103
+ }
104
+ }, { immediate: true });
105
+ return computed<T[]>(() => items.value.map((product) => {
106
+ const found = cache.value[product.id];
107
+ return {
108
+ ...product,
109
+ prices: found?.prices ?? [],
110
+ stocks: found?.stocks ?? [],
111
+ isOutOfStock: found?.isOutOfStock ?? false,
112
+ };
113
+ }));
114
+ }
115
+
116
+ return { loadOffers, useOffer, withOffers };
117
+ }
@@ -21,6 +21,17 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
21
21
  },
22
22
  );
23
23
 
24
+ // Price + availability are the Offer domain — fetched on their own axis
25
+ // (heavyweight ERP call in production), never blocking the detail render.
26
+ const { loadOffers, useOffer } = useOffers();
27
+ const { offer, pending: offerPending } = useOffer(() => toValue(id));
28
+ watch(detail, (loaded) => {
29
+ const product = loaded?.product?.[0];
30
+ if (product) {
31
+ void loadOffers([{ id: toValue(id), sku: product.sku }]);
32
+ }
33
+ }, { immediate: true });
34
+
24
35
  const productInfo = computed<ProductDetailProduct | undefined>(
25
36
  () => detail.value?.product?.[0],
26
37
  );
@@ -35,8 +46,9 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
35
46
  () => detail.value?.descriptions?.find(d => d.type === "long")?.content,
36
47
  );
37
48
 
49
+ // From the offer, not the catalog detail payload.
38
50
  const stocks = computed<ProductDetailStock[]>(
39
- () => detail.value?.stocks ?? [],
51
+ () => offer.value?.stocks ?? [],
40
52
  );
41
53
 
42
54
  const attributes = computed<ProductDetailAttribute[]>(
@@ -44,7 +56,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
44
56
  );
45
57
 
46
58
  const prices = computed<{ [key: string]: number }[]>(
47
- () => detail.value?.prices ?? [],
59
+ () => offer.value?.prices ?? [],
48
60
  );
49
61
 
50
62
  const taxRate = computed<number>(() => detail.value?.tax?.rate ?? 0);
@@ -83,7 +95,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
83
95
  return {
84
96
  detail, status, error, refresh,
85
97
  productInfo, mainImages, longDescription,
86
- stocks, attributes, prices, taxRate,
98
+ stocks, attributes, prices, taxRate, offerPending,
87
99
  productCategories, categorySlug, subcategorySlug,
88
100
  formatPrice, getDetailImageUrl,
89
101
  };
@@ -8,16 +8,16 @@ export function useProductCardActions(getProduct: () => ProductList) {
8
8
  const { icon } = useIcons();
9
9
  const { t } = useI18n();
10
10
 
11
- const isOutOfStock = computed(() => {
12
- const product = getProduct();
13
- if (typeof product.isOutOfStock === "boolean") {
14
- return product.isOutOfStock;
15
- }
16
- return (product.stocks?.[0]?.quantity ?? 0) <= 0;
17
- });
11
+ // Price + availability are the Offer domain — resolved separately and
12
+ // hydrated after first paint. Until the offer arrives the card is
13
+ // optimistically in-stock but NOT orderable (no price yet).
14
+ const { offer } = useOffers().useOffer(() => getProduct().id);
15
+ const offerPrices = computed(() => offer.value?.prices ?? []);
16
+
17
+ const isOutOfStock = computed(() => offer.value?.isOutOfStock ?? false);
18
18
 
19
19
  /** Price on request (no price for this buyer context) — not orderable online. */
20
- const hasPrice = computed(() => getBaseUnitPrice(getProduct().prices ?? []) !== null);
20
+ const hasPrice = computed(() => getBaseUnitPrice(offerPrices.value) !== null);
21
21
 
22
22
  function buildPriceTiers(prices: { [key: string]: number }[]): CartItemPriceTier[] {
23
23
  if (!prices.length) {
@@ -48,7 +48,7 @@ export function useProductCardActions(getProduct: () => ProductList) {
48
48
  }
49
49
 
50
50
  const quantity = 1;
51
- const maxQuantity = product.maxOrderQuantity;
51
+ const maxQuantity = offer.value?.stocks?.[0]?.maxOrderQuantity;
52
52
  const currentCartQuantity
53
53
  = cart.items.find((item: CartItem) => item.id === product.id)?.quantity ?? 0;
54
54
 
@@ -63,7 +63,7 @@ export function useProductCardActions(getProduct: () => ProductList) {
63
63
  return;
64
64
  }
65
65
 
66
- const baseUnitPrice = getBaseUnitPrice(product.prices);
66
+ const baseUnitPrice = getBaseUnitPrice(offerPrices.value);
67
67
  if (baseUnitPrice === null) {
68
68
  return;
69
69
  }
@@ -75,7 +75,7 @@ export function useProductCardActions(getProduct: () => ProductList) {
75
75
  sku: product.sku,
76
76
  price: baseUnitPrice,
77
77
  taxRate: product.tax.rate,
78
- priceTiers: buildPriceTiers(product.prices),
78
+ priceTiers: buildPriceTiers(offerPrices.value),
79
79
  categorySlug: product.categorySlug,
80
80
  subcategorySlug: product.subcategorySlug,
81
81
  ...(typeof maxQuantity === "number" ? { maxOrderQuantity: maxQuantity } : {}),
@@ -147,6 +147,16 @@ export function useProductListing(options: ProductListingOptions) {
147
147
 
148
148
  /* ---- derived view state -------------------------------------------- */
149
149
  const products = computed<ProductList[]>(() => data.value?.products ?? []);
150
+
151
+ // Offer (price + availability) is its own axis — batch-hydrate the visible
152
+ // hits AFTER they arrive, never blocking the catalog/search render.
153
+ const { loadOffers } = useOffers();
154
+ watch(products, (list) => {
155
+ if (list.length) {
156
+ void loadOffers(list);
157
+ }
158
+ }, { immediate: true });
159
+
150
160
  const found = computed(() => data.value?.found ?? 0);
151
161
  const totalPages = computed(() => Math.ceil(found.value / (productsPerPage as number)));
152
162
  const isEmpty = computed(() => data.value !== null && data.value !== undefined && products.value.length === 0);
@@ -1,17 +1,17 @@
1
1
  import type { Product } from "../composables/useProducts";
2
- import { slugify } from "../composables/useProducts";
2
+ import { categoryProductPath } from "../composables/useProducts";
3
3
 
4
4
  /**
5
5
  * Generate a localized product URL with the current locale prefix.
6
6
  * Replaces the plain `productUrl()` function to support i18n routing.
7
+ * Tolerates any category depth and never emits a literal "undefined" segment.
7
8
  */
8
9
  export function useProductUrl(product: Product) {
9
10
  const localePath = useLocalePath();
10
11
 
11
- const url = computed(() => {
12
- const path = `/category/${product.categorySlug}/${product.subcategorySlug}/product/${slugify(product)}`;
13
- return localePath(path);
14
- });
12
+ const url = computed(() =>
13
+ localePath(categoryProductPath([product.categorySlug, product.subcategorySlug], product)),
14
+ );
15
15
 
16
16
  return url;
17
17
  }