diff --git a/src/business-logic/import-pipeline/sources/dirtstreet/converter.js b/src/business-logic/import-pipeline/sources/dirtstreet/converter.js index e99de09..1ee84db 100644 --- a/src/business-logic/import-pipeline/sources/dirtstreet/converter.js +++ b/src/business-logic/import-pipeline/sources/dirtstreet/converter.js @@ -47,7 +47,7 @@ function buildDescriptionHtml(record) { } function convertDirtstreetRecordToShopifyReady(record, options = {}) { - const brand = options.brand || record.brand || "Dirtstreet"; + const brand = record.brand || options.brand || "Dirtstreet"; const uploadedImageMap = options.uploadedImageMap || null; const title = record.title || "Untitled Product"; @@ -134,7 +134,8 @@ function convertDirtstreetJsonToShopifyProducts(input, options = {}) { // Each record in aggregated JSON has raw scraped data in record.scraped const scraped = record.scraped || record; return convertDirtstreetRecordToShopifyReady(scraped, { - brand: options.brand || scraped.brand || record.brand, + // Per-product brand always wins over global SHOPIFY_BRAND env + brand: scraped.brand || record.brand || options.brand, uploadedImageMap: options.uploadedImageMap, }); }); diff --git a/src/business-logic/import-pipeline/sources/motousher/converter.js b/src/business-logic/import-pipeline/sources/motousher/converter.js index 6337892..4bb01a1 100644 --- a/src/business-logic/import-pipeline/sources/motousher/converter.js +++ b/src/business-logic/import-pipeline/sources/motousher/converter.js @@ -15,7 +15,8 @@ function getImageFileName(imagePath) { } function convertMotousherRecordToShopifyReady(record, options = {}) { - const brand = options.brand || record.brand || "Motousher"; + // Per-product brand always wins over global env override + const brand = record.brand || options.brand || "Motousher"; const uploadedImageMap = options.uploadedImageMap || null; const productId = record.handle || slugify(`${record.title || ""}-${record.sku || ""}`); @@ -107,7 +108,15 @@ function convertMotousherRecordToShopifyReady(record, options = {}) { function convertMotousherJsonToShopifyProducts(input, options = {}) { const records = Array.isArray(input?.products) ? input.products : []; - return records.map((record) => convertMotousherRecordToShopifyReady(record, options)); + return records.map((record) => { + // Aggregated JSON wraps scraped data inside record.scraped + const data = record.scraped || record; + return convertMotousherRecordToShopifyReady(data, { + ...options, + // Per-product brand takes priority over global SHOPIFY_BRAND env + brand: data.brand || record.brand || options.brand, + }); + }); } module.exports = { convertMotousherRecordToShopifyReady, convertMotousherJsonToShopifyProducts };