Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4afc63bdc6 | ||
|
|
41c7ad25e7 | ||
|
|
2056e6c766 | ||
|
|
f2377be69c | ||
|
|
d6b84e4480 | ||
|
|
f8f540af6a | ||
|
|
51eadd98dc | ||
|
|
fbf0aec892 | ||
|
|
e3eca46e0e | ||
|
|
586313d6d7 | ||
|
|
77a15c26b1 | ||
|
|
8cd43a2584 |
No files matched your search
@@ -47,7 +47,10 @@ async function meilisearchProductTransformer(
|
||||
inventory_quantity?: number | null
|
||||
manage_inventory?: boolean | null
|
||||
allow_backorder?: boolean | null
|
||||
calculated_price?: { calculated_amount?: number | null } | null
|
||||
prices?: Array<{
|
||||
amount?: number | null
|
||||
currency_code?: string | null
|
||||
}> | null
|
||||
}>
|
||||
| null
|
||||
| undefined
|
||||
@@ -63,6 +66,18 @@ async function meilisearchProductTransformer(
|
||||
variant.manage_inventory === false ||
|
||||
(variant.inventory_quantity ?? 0) > 0
|
||||
|
||||
// variants.calculated_price requiere currency_code/region_id en el
|
||||
// contexto de pricing, que el workflow de sync interno del plugin no
|
||||
// provee -- hace fallar TODO el job de indexado (confirmado en vivo:
|
||||
// "Method calculatePrices requires currency_code in the pricing
|
||||
// context"). variants.prices es la lista cruda de precios (sin
|
||||
// resolver promociones/reglas), no necesita contexto -- alcanza para
|
||||
// el filtro/orden por precio en la busqueda, que no necesita el
|
||||
// precio final promocional.
|
||||
const copPrice = variant?.prices?.find(
|
||||
(price) => price.currency_code?.toLowerCase() === "cop",
|
||||
)
|
||||
|
||||
return {
|
||||
id: document.id,
|
||||
name: document.title || "Producto ARI Shopping",
|
||||
@@ -73,10 +88,7 @@ async function meilisearchProductTransformer(
|
||||
brand: stringMetadata(metadata, "brand") || "ARI Shopping",
|
||||
ageRange: stringMetadata(metadata, "ageRange") || "Todas",
|
||||
tags: (tags || []).map((tag) => tag.value).filter(Boolean),
|
||||
price:
|
||||
typeof variant?.calculated_price?.calculated_amount === "number"
|
||||
? variant.calculated_price.calculated_amount
|
||||
: null,
|
||||
price: typeof copPrice?.amount === "number" ? copPrice.amount : null,
|
||||
available,
|
||||
isNew: booleanMetadata(metadata, "isNew"),
|
||||
featured: booleanMetadata(metadata, "featured"),
|
||||
@@ -184,7 +196,8 @@ module.exports = defineConfig({
|
||||
"variants.inventory_quantity",
|
||||
"variants.manage_inventory",
|
||||
"variants.allow_backorder",
|
||||
"variants.calculated_price.calculated_amount",
|
||||
"variants.prices.amount",
|
||||
"variants.prices.currency_code",
|
||||
],
|
||||
indexSettings: {
|
||||
// Tabla de ADR 0006 §3: Buscable / Filtrable-faceta / Ordenable.
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework";
|
||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
QueryContext,
|
||||
} from "@medusajs/framework/utils";
|
||||
import {
|
||||
MEILISEARCH_MODULE,
|
||||
type MeiliSearchService,
|
||||
@@ -76,6 +79,13 @@ export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
||||
const q = stringParam(req.query, "q") ?? "";
|
||||
const limit = numberParam(req.query, "limit") ?? 24;
|
||||
const offset = numberParam(req.query, "offset") ?? 0;
|
||||
// calculated_price exige region_id/currency_code en el contexto de
|
||||
// pricing o query.graph tira "Method calculatePrices requires
|
||||
// currency_code in the pricing context" (mismo error que ya rompio el
|
||||
// job de sync -- ver medusa-config.ts). El storefront ya manda
|
||||
// region_id contra /store/products (medusa.ts, regionId()); esta ruta
|
||||
// espera el mismo query param.
|
||||
const regionId = stringParam(req.query, "region_id");
|
||||
|
||||
const filterParts: string[] = [];
|
||||
for (const facet of ["category", "collection", "brand", "ageRange"]) {
|
||||
@@ -139,10 +149,36 @@ export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
// calculatePrices exige currency_code en el contexto -- no alcanza con
|
||||
// region_id solo (a diferencia de /store/products nativo, que lo
|
||||
// resuelve el middleware setPricingContext; esta ruta no pasa por esa
|
||||
// cadena). Resolvemos la moneda real de la region en vez de asumir COP
|
||||
// fijo, por si el catalogo suma otra region/moneda mas adelante.
|
||||
let currencyCode: string | undefined;
|
||||
if (regionId) {
|
||||
const { data: regions = [] } = await query.graph({
|
||||
entity: "region",
|
||||
fields: ["id", "currency_code"],
|
||||
filters: { id: regionId },
|
||||
});
|
||||
currencyCode = regions[0]?.currency_code;
|
||||
}
|
||||
|
||||
const { data: products = [] } = await query.graph({
|
||||
entity: "product",
|
||||
fields: PRODUCT_FIELDS,
|
||||
filters: { id: productIds },
|
||||
context:
|
||||
regionId && currencyCode
|
||||
? {
|
||||
variants: {
|
||||
calculated_price: QueryContext({
|
||||
region_id: regionId,
|
||||
currency_code: currencyCode,
|
||||
}),
|
||||
},
|
||||
}
|
||||
: {},
|
||||
});
|
||||
|
||||
// Preserva el ranking de relevancia de Meilisearch -- query.graph no
|
||||
|
||||
@@ -295,3 +295,36 @@ desviaciones reales respecto al diseño de §4/§5 de este ADR:
|
||||
Ninguna de las tres cambia la decisión ni sus consecuencias — cambian
|
||||
el cómo, no el qué. Plan de implementación completo, fase por fase,
|
||||
en la sesión que aprobó esta Etapa 2 (2026-08-26).
|
||||
|
||||
## Nota de implementación 2 (2026-08-26, gate en vivo de Fase 2)
|
||||
|
||||
Dos bugs reales encontrados y corregidos durante el gate de
|
||||
verificación en vivo (crear/editar productos, categoría y colección
|
||||
reales y confirmar que llegan a Meilisearch), ambos con la misma causa
|
||||
raíz: `variants.calculated_price` de Medusa exige `region_id` **y**
|
||||
`currency_code` resueltos en el contexto de pricing de la consulta, y
|
||||
ninguno de los dos caminos nuevos de este ADR pasa por el middleware
|
||||
nativo (`setPricingContext`) que se lo da gratis a `/store/products`:
|
||||
|
||||
1. El job de sync inicial del plugin (`sync-products.js`, corre una
|
||||
vez al boot) hacía fallar el indexado de **todos** los productos
|
||||
con `Method calculatePrices requires currency_code in the pricing
|
||||
context` — las categorías sí indexaban bien (no llevan precio).
|
||||
Arreglado indexando el precio crudo (`variants.prices`, sin
|
||||
resolver promociones/reglas) en vez de `calculated_price` — alcanza
|
||||
para el filtro/orden por precio de la búsqueda.
|
||||
2. La ruta propia `/store/search` pegaba el mismo error al re-hidratar
|
||||
productos vía `query.graph`. Pasar `region_id` solo no alcanzó;
|
||||
hubo que resolver el `currency_code` real de la región con una
|
||||
consulta adicional antes de armar el `QueryContext`.
|
||||
|
||||
Confirmado en vivo, con el fix aplicado: búsqueda por texto, facetas
|
||||
sobre las 27 unidades del catálogo real, y precio calculado correcto
|
||||
(`calculated_amount`/`currency_code`) en la respuesta de
|
||||
`/store/search`. También confirmado en vivo que los tres eventos que
|
||||
el ADR original marcaba como "verificar, no asumir" — `product.*`,
|
||||
`product-category.*` y **`product-collection.updated`** (el que tenía
|
||||
un reporte público de no disparar siempre) — sí sincronizan de forma
|
||||
confiable en esta combinación exacta (Medusa 2.18.0 + plugin 1.4.1),
|
||||
propagando un rename de categoría/colección al documento indexado en
|
||||
menos de 10 segundos.
|
||||
@@ -25,7 +25,7 @@ spec:
|
||||
runAsNonRoot: false
|
||||
containers:
|
||||
- name: app
|
||||
image: gitea.cruzcloud.net/devops/docs-portal:v1.0.162
|
||||
image: gitea.cruzcloud.net/devops/docs-portal:v1.0.164
|
||||
# El base saca TODAS las capabilities. Probado en vivo y
|
||||
# revertido: con drop: ALL (aunque se agregue NET_BIND_SERVICE
|
||||
# de vuelta) el propio entrypoint de nginx:1.27-alpine falla al
|
||||
|
||||
@@ -65,7 +65,7 @@ spec:
|
||||
memory: 64Mi
|
||||
|
||||
- name: migrations
|
||||
image: gitea.cruzcloud.net/devops/ecommerce-medusa:v1.0.127
|
||||
image: gitea.cruzcloud.net/devops/ecommerce-medusa:v1.0.167
|
||||
imagePullPolicy: IfNotPresent
|
||||
command:
|
||||
- node
|
||||
@@ -86,7 +86,7 @@ spec:
|
||||
|
||||
containers:
|
||||
- name: app
|
||||
image: gitea.cruzcloud.net/devops/ecommerce-medusa:v1.0.127
|
||||
image: gitea.cruzcloud.net/devops/ecommerce-medusa:v1.0.167
|
||||
imagePullPolicy: IfNotPresent
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
|
||||
Reference in new issue
Block a user