From 6eac0b92edecc5067d4da30a90d3bd8f5587cb59 Mon Sep 17 00:00:00 2001 From: MOHAN Date: Thu, 4 Jun 2026 16:39:54 +0530 Subject: [PATCH] Fix converter reading nested scraped data and brand priority Both motousher and dirtstreet converters were reading product fields (title, sku, price, images) directly from the aggregated record, but those fields live inside record.scraped after fetchWebsiteData wraps them. Results were: Untitled Product, missing images, SKU=variant-1. Also fixed brand priority: per-product brand (e.g. Evans Coolant, SC Project) now takes precedence over the global SHOPIFY_BRAND env var (KYT), which was incorrectly overriding all products from the new sources. Co-Authored-By: Claude Sonnet 4.6 --- .../import-pipeline/sources/dirtstreet/converter.js | 5 +++-- .../import-pipeline/sources/motousher/converter.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) 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 };