← back to Flockedwallpaper
update-zawaya-images.js
47 lines
const fs = require('fs');
const products = JSON.parse(fs.readFileSync('flocked-products.json', 'utf8'));
// Map of SKU variants to their best quality image URLs from Shopify CDN
const imageMap = {
'w7851-01': 'https://cdn.shopify.com/s/files/1/0015/4117/7456/files/w7851-01_ny3ngrwnlau6idto.webp?v=1738617147',
'w7851-02': 'https://cdn.shopify.com/s/files/1/0015/4117/7456/files/w7851-02_pvayxmrp02vym6gk.webp?v=1738617151',
'w7851-03': 'https://cdn.shopify.com/s/files/1/0015/4117/7456/files/w7851-03_i7itxxcasldfo47y.webp?v=1738617156',
'w7851-04': 'https://cdn.shopify.com/s/files/1/0015/4117/7456/files/w7851-04_pgmu5htsqjcifxmp.webp?v=1738617161'
};
let updated = 0;
// Update Zawaya products with better images
const updatedProducts = products.map(p => {
if (p.tags && p.tags.includes('W7851') && p.tags.includes('Zawaya Tribal')) {
// Determine which variant this is based on color
let imageKey;
if (p.primaryColor === 'White' || p.title.includes('Cream')) {
imageKey = 'w7851-02';
} else if (p.primaryColor === 'Blue') {
imageKey = 'w7851-03';
} else if (p.primaryColor === 'Green') {
imageKey = 'w7851-04';
} else {
// Default variant (w7851-01)
imageKey = 'w7851-01';
}
const newImage = imageMap[imageKey];
if (p.image !== newImage) {
console.log(`Updating ${p.title}`);
console.log(` Old: ${p.image}`);
console.log(` New: ${newImage}`);
p.image = newImage;
updated++;
}
}
return p;
});
console.log(`\nUpdated ${updated} Zawaya products with better images`);
fs.writeFileSync('flocked-products.json', JSON.stringify(updatedProducts, null, 2));
console.log('✓ Products file updated');