|
@@ -559,24 +559,27 @@ async function syncProducts(
|
|
|
const productsToCache = products.map((product: ShopifyProduct) => {
|
|
const productsToCache = products.map((product: ShopifyProduct) => {
|
|
|
const primaryVariant = product.variants?.[0]
|
|
const primaryVariant = product.variants?.[0]
|
|
|
|
|
|
|
|
|
|
+ // Build categories array from product_type and vendor
|
|
|
|
|
+ const categories: any[] = []
|
|
|
|
|
+ if (product.product_type) {
|
|
|
|
|
+ categories.push({
|
|
|
|
|
+ id: product.product_type.toLowerCase().replace(/\s+/g, '-'),
|
|
|
|
|
+ name: product.product_type
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
store_id: storeId,
|
|
store_id: storeId,
|
|
|
shopify_product_id: product.id.toString(),
|
|
shopify_product_id: product.id.toString(),
|
|
|
- title: product.title,
|
|
|
|
|
- handle: product.handle,
|
|
|
|
|
- vendor: product.vendor || null,
|
|
|
|
|
- product_type: product.product_type || null,
|
|
|
|
|
- status: product.status,
|
|
|
|
|
|
|
+ name: product.title, // Map title to name for consistency
|
|
|
|
|
+ sku: primaryVariant?.sku || null,
|
|
|
price: primaryVariant ? parseFloat(primaryVariant.price) : 0,
|
|
price: primaryVariant ? parseFloat(primaryVariant.price) : 0,
|
|
|
- compare_at_price: primaryVariant?.compare_at_price ? parseFloat(primaryVariant.compare_at_price) : null,
|
|
|
|
|
currency: currency,
|
|
currency: currency,
|
|
|
- sku: primaryVariant?.sku || null,
|
|
|
|
|
- inventory_quantity: primaryVariant?.inventory_quantity || 0,
|
|
|
|
|
- description: product.body_html || null,
|
|
|
|
|
- images: product.images || [],
|
|
|
|
|
- variants: product.variants || [],
|
|
|
|
|
- options: product.options || [],
|
|
|
|
|
|
|
+ categories: categories,
|
|
|
|
|
+ product_type: product.product_type || null,
|
|
|
|
|
+ vendor: product.vendor || null,
|
|
|
tags: product.tags ? product.tags.split(',').map(t => t.trim()) : [],
|
|
tags: product.tags ? product.tags.split(',').map(t => t.trim()) : [],
|
|
|
|
|
+ description: product.body_html || null,
|
|
|
raw_data: product,
|
|
raw_data: product,
|
|
|
last_synced_at: new Date().toISOString()
|
|
last_synced_at: new Date().toISOString()
|
|
|
}
|
|
}
|