feat: rename stock to cantidad_maxima in product variant interfaces and update related components for consistency
This commit is contained in:
@@ -31,14 +31,14 @@ export interface ProductAttribute {
|
||||
|
||||
export interface ProductVariant {
|
||||
id: number;
|
||||
stock: number;
|
||||
cantidad_maxima: number;
|
||||
definitions: Record<string, string>;
|
||||
images: string[];
|
||||
}
|
||||
|
||||
export interface ProductVariantMap {
|
||||
variant_id: number;
|
||||
stock: number;
|
||||
cantidad_maxima: number;
|
||||
attributes: Record<string, string>;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ export class ProductAttributeSelectorComponent {
|
||||
const optionNormalized = this.normalizeText(option.value || option.label);
|
||||
|
||||
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);
|
||||
if (!variantAttrValue || this.normalizeText(variantAttrValue) !== optionNormalized) {
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
<div class="product-detail__purchase">
|
||||
<app-quantity-selector
|
||||
[(quantity)]="quantity"
|
||||
[max]="selectedVariant()?.stock ?? 1"
|
||||
[max]="selectedVariant()?.cantidad_maxima ?? 1"
|
||||
/>
|
||||
|
||||
<div class="product-detail__actions">
|
||||
|
||||
@@ -132,7 +132,7 @@ describe('ProductDetailPageComponent', () => {
|
||||
images: ['https://example.com/product.png'],
|
||||
variant: {
|
||||
id: 123,
|
||||
stock: 10,
|
||||
cantidad_maxima: 10,
|
||||
images: ['https://example.com/variant1.png', 'https://example.com/variant2.png'],
|
||||
definitions: {}
|
||||
}
|
||||
@@ -234,7 +234,7 @@ describe('ProductDetailPageComponent', () => {
|
||||
],
|
||||
variant: {
|
||||
id: 123,
|
||||
stock: 10,
|
||||
cantidad_maxima: 10,
|
||||
images: ['https://example.com/variant1.png'],
|
||||
definitions: {
|
||||
color: 'beige',
|
||||
@@ -279,7 +279,7 @@ describe('ProductDetailPageComponent', () => {
|
||||
const fixture = TestBed.createComponent(ProductDetailPageComponent);
|
||||
fixture.componentInstance['selectedVariant'].set({
|
||||
variant_id: 1,
|
||||
stock: 10,
|
||||
cantidad_maxima: 10,
|
||||
attributes: {}
|
||||
});
|
||||
fixture.detectChanges();
|
||||
@@ -355,14 +355,14 @@ describe('ProductDetailPageComponent', () => {
|
||||
...mockProduct,
|
||||
variant: {
|
||||
id: 123,
|
||||
stock: 5,
|
||||
cantidad_maxima: 5,
|
||||
images: [],
|
||||
definitions: {}
|
||||
},
|
||||
variants_map: [
|
||||
{
|
||||
variant_id: 123,
|
||||
stock: 5,
|
||||
cantidad_maxima: 5,
|
||||
attributes: {}
|
||||
}
|
||||
]
|
||||
@@ -396,14 +396,14 @@ describe('ProductDetailPageComponent', () => {
|
||||
...mockProduct,
|
||||
variant: {
|
||||
id: 123,
|
||||
stock: 5,
|
||||
cantidad_maxima: 5,
|
||||
images: [],
|
||||
definitions: {}
|
||||
},
|
||||
variants_map: [
|
||||
{
|
||||
variant_id: 123,
|
||||
stock: 5,
|
||||
cantidad_maxima: 5,
|
||||
attributes: {}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -170,7 +170,7 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
||||
if (!currentProduct) return null;
|
||||
const updatedVariantsMap = currentProduct.variants_map.map((v) => {
|
||||
if (v.variant_id === variantId) {
|
||||
return { ...v, stock: 0 };
|
||||
return { ...v, cantidad_maxima: 0 };
|
||||
}
|
||||
return v;
|
||||
});
|
||||
@@ -205,8 +205,8 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
this.selectedVariant.set(variant);
|
||||
if (variant && this.quantity() > variant.stock) {
|
||||
this.quantity.set(Math.max(1, variant.stock));
|
||||
if (variant && this.quantity() > variant.cantidad_maxima) {
|
||||
this.quantity.set(Math.max(1, variant.cantidad_maxima));
|
||||
}
|
||||
|
||||
const currentProduct = this.product();
|
||||
|
||||
Reference in New Issue
Block a user