diff --git a/src/app/core/layout/store-layout/store-layout.component.spec.ts b/src/app/core/layout/store-layout/store-layout.component.spec.ts index a4ecba1..33c28c9 100644 --- a/src/app/core/layout/store-layout/store-layout.component.spec.ts +++ b/src/app/core/layout/store-layout/store-layout.component.spec.ts @@ -574,6 +574,7 @@ describe('StoreLayoutComponent', () => { product: { nombre: 'Producto', imagen: null, + variant: null, }, }, ], @@ -627,6 +628,7 @@ describe('StoreLayoutComponent', () => { product: { nombre: 'Producto', imagen: null, + variant: null, }, }, ], diff --git a/src/app/core/layout/store-layout/store-layout.component.ts b/src/app/core/layout/store-layout/store-layout.component.ts index 0ab3b6c..66b73d4 100644 --- a/src/app/core/layout/store-layout/store-layout.component.ts +++ b/src/app/core/layout/store-layout/store-layout.component.ts @@ -70,10 +70,7 @@ export class StoreLayoutComponent implements OnInit { }); } - const variants = item.product?.variants ?? []; - const selectedVariant = item.product?.variants?.find( - (variant) => variant.id === item.variant_id, - ); + const selectedVariant = item.product?.variant ?? null; if (selectedVariant) { attributes = Object.entries(selectedVariant.values).map(([label, value]) => ({ @@ -92,7 +89,6 @@ export class StoreLayoutComponent implements OnInit { attributes, quantity: item.cantidad, variantId: item.variant_id, - variants, }; } diff --git a/src/app/core/services/cart/cart.interface.ts b/src/app/core/services/cart/cart.interface.ts index 6846737..511f056 100644 --- a/src/app/core/services/cart/cart.interface.ts +++ b/src/app/core/services/cart/cart.interface.ts @@ -1,7 +1,7 @@ export interface CartItemProduct { nombre: string; imagen: string | null; - variants?: CartItemVariant[]; + variant: CartItemVariant | null; } export interface CartItemVariantOption { diff --git a/src/app/core/services/cart/cart.service.spec.ts b/src/app/core/services/cart/cart.service.spec.ts index 08e66e8..bb5b77a 100644 --- a/src/app/core/services/cart/cart.service.spec.ts +++ b/src/app/core/services/cart/cart.service.spec.ts @@ -27,6 +27,12 @@ describe('CartService', () => { product: { nombre: 'Test Product (Size: M)', imagen: null, + variant: { + id: 10, + precio: '10.00', + stock_tecnico: 1, + values: { size: 'M' }, + }, }, }, ], diff --git a/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.spec.ts b/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.spec.ts index 64b24c5..d48c9f4 100644 --- a/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.spec.ts +++ b/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.spec.ts @@ -203,17 +203,15 @@ describe('ProductTicketSelectorComponent', () => { product: { nombre: 'Entrada', imagen: null, - variants: [ - { - id: 401, - precio: '10000.00', - stock_tecnico: 1, - values: { - sector: { value: 'a', label: 'Sector A' }, - seat: '1', - }, + variant: { + id: 401, + precio: '10000.00', + stock_tecnico: 1, + values: { + sector: { value: 'a', label: 'Sector A' }, + seat: '1', }, - ], + }, }, }, ], @@ -304,14 +302,12 @@ describe('ProductTicketSelectorComponent', () => { product: { nombre: 'Entrada', imagen: null, - variants: [ - { - id: 401, - precio: '10000.00', - stock_tecnico: 0, - values: { seat: '1' }, - }, - ], + variant: { + id: 401, + precio: '10000.00', + stock_tecnico: 0, + values: { seat: '1' }, + }, }, }, ], diff --git a/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.ts b/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.ts index 31058e8..0f94256 100644 --- a/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.ts +++ b/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.ts @@ -455,8 +455,8 @@ export class ProductTicketSelectorComponent { private createCartRow(item: CartItem, id = this.nextRowId++): TicketSelectionRow | null { if (item.variant_id === null) return null; - const variant = item.product?.variants?.find(({ id }) => id === item.variant_id); - if (!variant) return null; + const variant = item.product?.variant; + if (!variant || variant.id !== item.variant_id) return null; const selectedValues = this.normalizeCartValues(variant.values);