feat: rename stock to cantidad_maxima in product variant interfaces and update related components for consistency

This commit is contained in:
2026-07-02 09:39:06 -03:00
parent 16eea32ce7
commit 4817dd1f76
5 changed files with 14 additions and 14 deletions

View File

@@ -31,14 +31,14 @@ export interface ProductAttribute {
export interface ProductVariant { export interface ProductVariant {
id: number; id: number;
stock: number; cantidad_maxima: number;
definitions: Record<string, string>; definitions: Record<string, string>;
images: string[]; images: string[];
} }
export interface ProductVariantMap { export interface ProductVariantMap {
variant_id: number; variant_id: number;
stock: number; cantidad_maxima: number;
attributes: Record<string, string>; attributes: Record<string, string>;
} }

View File

@@ -46,7 +46,7 @@ export class ProductAttributeSelectorComponent {
const optionNormalized = this.normalizeText(option.value || option.label); const optionNormalized = this.normalizeText(option.value || option.label);
const isAvailable = variants.some(variant => { const isAvailable = variants.some(variant => {
if (variant.stock <= 0) return false; if (variant.cantidad_maxima <= 0) return false;
const variantAttrValue = this.getDefaultVariantAttributeValue(attribute, variant.attributes); const variantAttrValue = this.getDefaultVariantAttributeValue(attribute, variant.attributes);
if (!variantAttrValue || this.normalizeText(variantAttrValue) !== optionNormalized) { if (!variantAttrValue || this.normalizeText(variantAttrValue) !== optionNormalized) {

View File

@@ -55,7 +55,7 @@
<div class="product-detail__purchase"> <div class="product-detail__purchase">
<app-quantity-selector <app-quantity-selector
[(quantity)]="quantity" [(quantity)]="quantity"
[max]="selectedVariant()?.stock ?? 1" [max]="selectedVariant()?.cantidad_maxima ?? 1"
/> />
<div class="product-detail__actions"> <div class="product-detail__actions">

View File

@@ -132,7 +132,7 @@ describe('ProductDetailPageComponent', () => {
images: ['https://example.com/product.png'], images: ['https://example.com/product.png'],
variant: { variant: {
id: 123, id: 123,
stock: 10, cantidad_maxima: 10,
images: ['https://example.com/variant1.png', 'https://example.com/variant2.png'], images: ['https://example.com/variant1.png', 'https://example.com/variant2.png'],
definitions: {} definitions: {}
} }
@@ -234,7 +234,7 @@ describe('ProductDetailPageComponent', () => {
], ],
variant: { variant: {
id: 123, id: 123,
stock: 10, cantidad_maxima: 10,
images: ['https://example.com/variant1.png'], images: ['https://example.com/variant1.png'],
definitions: { definitions: {
color: 'beige', color: 'beige',
@@ -279,7 +279,7 @@ describe('ProductDetailPageComponent', () => {
const fixture = TestBed.createComponent(ProductDetailPageComponent); const fixture = TestBed.createComponent(ProductDetailPageComponent);
fixture.componentInstance['selectedVariant'].set({ fixture.componentInstance['selectedVariant'].set({
variant_id: 1, variant_id: 1,
stock: 10, cantidad_maxima: 10,
attributes: {} attributes: {}
}); });
fixture.detectChanges(); fixture.detectChanges();
@@ -355,14 +355,14 @@ describe('ProductDetailPageComponent', () => {
...mockProduct, ...mockProduct,
variant: { variant: {
id: 123, id: 123,
stock: 5, cantidad_maxima: 5,
images: [], images: [],
definitions: {} definitions: {}
}, },
variants_map: [ variants_map: [
{ {
variant_id: 123, variant_id: 123,
stock: 5, cantidad_maxima: 5,
attributes: {} attributes: {}
} }
] ]
@@ -396,14 +396,14 @@ describe('ProductDetailPageComponent', () => {
...mockProduct, ...mockProduct,
variant: { variant: {
id: 123, id: 123,
stock: 5, cantidad_maxima: 5,
images: [], images: [],
definitions: {} definitions: {}
}, },
variants_map: [ variants_map: [
{ {
variant_id: 123, variant_id: 123,
stock: 5, cantidad_maxima: 5,
attributes: {} attributes: {}
} }
] ]

View File

@@ -170,7 +170,7 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
if (!currentProduct) return null; if (!currentProduct) return null;
const updatedVariantsMap = currentProduct.variants_map.map((v) => { const updatedVariantsMap = currentProduct.variants_map.map((v) => {
if (v.variant_id === variantId) { if (v.variant_id === variantId) {
return { ...v, stock: 0 }; return { ...v, cantidad_maxima: 0 };
} }
return v; return v;
}); });
@@ -205,8 +205,8 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
} }
this.selectedVariant.set(variant); this.selectedVariant.set(variant);
if (variant && this.quantity() > variant.stock) { if (variant && this.quantity() > variant.cantidad_maxima) {
this.quantity.set(Math.max(1, variant.stock)); this.quantity.set(Math.max(1, variant.cantidad_maxima));
} }
const currentProduct = this.product(); const currentProduct = this.product();