This commit is contained in:
sdarbinyan
2026-03-24 03:12:04 +04:00
parent 2a41062769
commit ee23fd2d3c
4 changed files with 43 additions and 13 deletions

View File

@@ -24,6 +24,12 @@ export class ApiService {
return map[apiLang] || apiLang.toLowerCase();
}
/** Convert Go-style hex colour (0xfffca0) → CSS hex (#fffca0) */
private normalizeColor(c: string): string {
if (!c) return '';
return c.startsWith('0x') ? '#' + c.slice(2) : c;
}
/** Resolve relative image URLs (e.g. ./images/x.webp) against site origin */
private resolveImageUrl(url: string): string {
if (!url) return '';
@@ -46,10 +52,14 @@ export class ApiService {
const details = raw.itemDetails || raw.itemdetails;
if (details && Array.isArray(details) && details.length > 0) {
const detail = details[0];
item.itemDetails = raw.itemDetails;
item.itemDetails = details.map((d: any) => ({
...d,
colour: this.normalizeColor(d.colour || d.color || ''),
color: undefined,
}));
if (item.price == null || item.price === 0) item.price = detail.price;
if (!item.currency) item.currency = detail.currency;
if (!item.colour) item.colour = detail.colour || detail.color || '';
if (!item.colour) item.colour = this.normalizeColor(detail.colour || detail.color || '');
if (!item.size) item.size = detail.size || '';
// Use remaining from detail for stock level
if (raw.remaining == null && detail.remaining != null) {
@@ -111,7 +121,7 @@ export class ApiService {
item.attributes = raw.attributes || [];
// Preserve colour & size (only if not already set from itemDetails)
if (!item.colour) item.colour = raw.colour || '';
if (!item.colour) item.colour = this.normalizeColor(raw.colour || '');
if (!item.size) item.size = raw.size || '';
// Map backOffice comments → legacy callbacks