fix case when variant has no metadata and no package elements are displayed
This commit is contained in:
@@ -20,12 +20,24 @@ export const getAnalysisElementMedusaProductIds = (products: Pick<StoreProduct,
|
|||||||
.flatMap((product) => {
|
.flatMap((product) => {
|
||||||
const value = (product as Product)?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
const value = (product as Product)?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||||
const value_variant = (product as Product)?.variant?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
const value_variant = (product as Product)?.variant?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||||
|
|
||||||
|
const result: string[] = [];
|
||||||
try {
|
try {
|
||||||
return [...JSON.parse(value as string), ...JSON.parse(value_variant as string)];
|
if (value) {
|
||||||
|
result.push(...JSON.parse(value as string));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse analysisElementMedusaProductIds from analysis package variant, possibly invalid format", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (value_variant) {
|
||||||
|
result.push(...JSON.parse(value_variant as string));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to parse analysisElementMedusaProductIds from analysis package, possibly invalid format", e);
|
console.error("Failed to parse analysisElementMedusaProductIds from analysis package, possibly invalid format", e);
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
})
|
})
|
||||||
.filter(Boolean) as string[];
|
.filter(Boolean) as string[];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user