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 <noreply@anthropic.com>
This commit is contained in:
MOHAN 2026-06-04 16:39:54 +05:30
parent c0132ab0aa
commit 6eac0b92ed
2 changed files with 14 additions and 4 deletions

View File

@ -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,
});
});

View File

@ -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 };