This commit is contained in:
Your Name committed 2026-10-02 09:27:12 +07:00
1 parent 3631f59bba
commit c3c2d97cc1
2 files changed
+94 -3

No files matched your search

@@ -250,6 +250,19 @@ export default function AddToCartSection({ product, showBrandMeta = true, showMo
const description = resolveLocalized(product.description, lang)
const getOptionImage = (optIndex: number, val: string) => {
// 1. Check if option itself has an imageUrl on value
const option = product.options?.[optIndex];
if (option && Array.isArray(option.values)) {
const matchVal = option.values.find((v: any) => {
const base = typeof v === 'string' ? v : (v?.th || v?.en || Object.values(v)[0]);
return base === val;
});
if (matchVal && typeof matchVal === 'object' && (matchVal as any).imageUrl) {
return (matchVal as any).imageUrl as string;
}
}
// 2. Fallback to matching variant imageUrl
if (!product.variants) return null;
const match = product.variants.find(v => {
const vVal = optIndex === 0 ? v.option1 : optIndex === 1 ? v.option2 : v.option3;