feat: implement product detail page and define catalog interfaces
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
export interface Product {
|
export interface Product {
|
||||||
id: number;
|
id: number;
|
||||||
tenant_codigo: string;
|
|
||||||
category_id: number;
|
category_id: number;
|
||||||
brand_id: number | null;
|
brand_id: number | null;
|
||||||
slug: string;
|
slug: string;
|
||||||
@@ -17,7 +16,7 @@ export interface ProductAttributeOption {
|
|||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
sort_order: number;
|
sort_order: number;
|
||||||
metadata: Record<string, any> | null;
|
metadata: Record<string, unknown> | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProductAttribute {
|
export interface ProductAttribute {
|
||||||
@@ -25,19 +24,27 @@ export interface ProductAttribute {
|
|||||||
codigo: string;
|
codigo: string;
|
||||||
nombre: string;
|
nombre: string;
|
||||||
is_required: boolean;
|
is_required: boolean;
|
||||||
metadata_schema: Record<string, any> | null;
|
metadata_schema: Record<string, unknown> | null;
|
||||||
type: string;
|
type: string;
|
||||||
options: ProductAttributeOption[];
|
options: ProductAttributeOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProductVariant {
|
export interface ProductVariant {
|
||||||
variant_id: number;
|
id: number;
|
||||||
|
stock: number;
|
||||||
|
definitions: Record<string, string>;
|
||||||
images: string[];
|
images: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductVariantMap {
|
||||||
|
variant_id: number;
|
||||||
|
stock: number;
|
||||||
attributes: Record<string, string>;
|
attributes: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProductDetail extends Product {
|
export interface ProductDetail extends Product {
|
||||||
attributes: ProductAttribute[];
|
attributes: ProductAttribute[];
|
||||||
default_variant: ProductVariant | null;
|
variants_map: ProductVariantMap[];
|
||||||
|
variant: ProductVariant | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
|||||||
protected readonly carouselImages = computed(() => {
|
protected readonly carouselImages = computed(() => {
|
||||||
const prod = this.product();
|
const prod = this.product();
|
||||||
if (!prod) return [];
|
if (!prod) return [];
|
||||||
if (prod.default_variant?.images && prod.default_variant.images.length > 0) {
|
if (prod.variant?.images && prod.variant.images.length > 0) {
|
||||||
return prod.default_variant.images;
|
return prod.variant.images;
|
||||||
}
|
}
|
||||||
if (prod.images && prod.images.length > 0) {
|
if (prod.images && prod.images.length > 0) {
|
||||||
return prod.images;
|
return prod.images;
|
||||||
@@ -181,7 +181,7 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initializeSelections(product: ProductDetail): void {
|
private initializeSelections(product: ProductDetail): void {
|
||||||
const defaultVariant = product.default_variant;
|
const defaultVariant = product.variant;
|
||||||
const selections: Record<number, number> = {};
|
const selections: Record<number, number> = {};
|
||||||
|
|
||||||
for (const attribute of product.attributes) {
|
for (const attribute of product.attributes) {
|
||||||
@@ -202,7 +202,7 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultValue = this.getDefaultVariantAttributeValue(attribute, variant.attributes);
|
const defaultValue = this.getDefaultVariantAttributeValue(attribute, variant.definitions);
|
||||||
if (!defaultValue) {
|
if (!defaultValue) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user