changes
This commit is contained in:
@@ -24,12 +24,13 @@ export class ApiService {
|
||||
return map[apiLang] || apiLang.toLowerCase();
|
||||
}
|
||||
|
||||
/** Resolve relative image URLs (e.g. ./images/x.webp) against API base */
|
||||
/** Resolve relative image URLs (e.g. ./images/x.webp) against site origin */
|
||||
private resolveImageUrl(url: string): string {
|
||||
if (!url) return '';
|
||||
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('/')) return url;
|
||||
if (url.startsWith('./')) return `${this.baseUrl}/${url.slice(2)}`;
|
||||
return `${this.baseUrl}/${url}`;
|
||||
const origin = `https://${environment.domain}`;
|
||||
if (url.startsWith('./')) return `${origin}/${url.slice(2)}`;
|
||||
return `${origin}/${url}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,17 +107,6 @@ export class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
// Map backend descriptions[] → translations (multi-lang descriptions)
|
||||
if (raw.descriptions && Array.isArray(raw.descriptions)) {
|
||||
item.descriptions = raw.descriptions;
|
||||
if (!item.translations) item.translations = {};
|
||||
for (const entry of raw.descriptions) {
|
||||
const lang = this.normalizeLang(entry.language);
|
||||
if (!item.translations[lang]) item.translations[lang] = {};
|
||||
item.translations[lang].simpleDescription = entry.value;
|
||||
}
|
||||
}
|
||||
|
||||
// Preserve attributes from backend
|
||||
item.attributes = raw.attributes || [];
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ export class CartService {
|
||||
return false;
|
||||
}
|
||||
|
||||
addItem(itemID: number, quantity: number = 1): void {
|
||||
addItem(itemID: number, quantity: number = 1, variant?: { colour?: string; size?: string; price?: number; currency?: string }): void {
|
||||
// Prevent duplicate API calls for same item
|
||||
if (this.addingItems.has(itemID)) return;
|
||||
|
||||
@@ -118,7 +118,14 @@ export class CartService {
|
||||
this.addingItems.add(itemID);
|
||||
this.apiService.getItem(itemID).subscribe({
|
||||
next: (item) => {
|
||||
const cartItem: CartItem = { ...item, quantity };
|
||||
const cartItem: CartItem = {
|
||||
...item,
|
||||
quantity,
|
||||
...(variant?.colour != null && { colour: variant.colour }),
|
||||
...(variant?.size != null && { size: variant.size }),
|
||||
...(variant?.price != null && { price: variant.price }),
|
||||
...(variant?.currency != null && { currency: variant.currency }),
|
||||
};
|
||||
this.cartItems.set([...this.cartItems(), cartItem]);
|
||||
this.addingItems.delete(itemID);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user