Skip to content

Commit

Permalink
fix(task-gmc-to-ecom):fix sku,and do not add newImage null
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Sep 9, 2024
1 parent da47b40 commit 8ef016b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions functions/lib/gmc-to-ecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ const parseProduct = async (appSdk, appData, auth, storeId, feedProduct, product
const categories = await getCategory(appSdk, storeId, feedProduct)
const condition = getFeedValueByKey('condition', feedProduct)
const newProductData = {
sku: (getFeedValueByKey('sku', feedProduct) || getFeedValueByKey('id', feedProduct) || getFeedValueByKey('ID', feedProduct)).toString(),
sku: (getFeedValueByKey('sku', feedProduct) || getFeedValueByKey('id', feedProduct) || getFeedValueByKey('ID', feedProduct)).toString()
.replace(/\s+/g, '_'),
name: getFeedValueByKey('title', feedProduct),
subtitle: getFeedValueByKey('subtitle', feedProduct),
meta_title: getFeedValueByKey('title', feedProduct),
Expand Down Expand Up @@ -269,14 +270,14 @@ const parseProduct = async (appSdk, appData, auth, storeId, feedProduct, product
}
})

let quantity = 0
const quantity = 0 // todo: let ?
const availability = getFeedValueByKey('availability', feedProduct)
if (availability) {
if (availability.toLowerCase() === 'in stock') {
newProductData.quantity = appData.default_quantity || 9999
} else if (Number(availability) > 0) {
newProductData.quantity = Number(availability)
} else if (storeId == 51412 && (Number(availability) === 0 || Number(availability) < 0)) {
} else if (storeId === 51412 && (Number(availability) === 0 || Number(availability) < 0)) {
newProductData.quantity = 9999
newProductData.production_time = {
days: 10
Expand Down Expand Up @@ -332,6 +333,7 @@ const saveEcomProduct = async (appSdk, appData, storeId, feedProduct, variations
try {
const auth = await appSdk.getAuth(parseInt(storeId, 10))
const sku = (getFeedValueByKey('sku', feedProduct) || getFeedValueByKey('id', feedProduct)).toString()
.replace(/\s+/g, '_')
const { result } = await findEcomProductBySKU(appSdk, storeId, sku, meta)
const product = result.length > 0 ? result[0] : {}
const { _id } = product
Expand Down Expand Up @@ -366,6 +368,7 @@ const saveEcomVariations = async (appSdk, appData, storeId, variations, product)
const parsedVariations = []
for (const variation of variations) {
const sku = (getFeedValueByKey('sku', variations) || getFeedValueByKey('id', variations)).toString()
.replace(/\s+/g, '_')
const variationFound = (product && product.variations && product.variations
.find(x => (x.sku || '').toString() === sku.toString())) || {}
const parsedVariation = await parseVariations(appSdk, appData, auth, storeId, variation, variationFound)
Expand Down Expand Up @@ -394,7 +397,9 @@ const saveEcomImages = async (appSdk, storeId, productId, imageLinks) => {
for (const imageLink of imageLinks) {
try {
const newPicture = await tryImageUpload(storeId, auth, imageLink, product)
pictures.push(newPicture)
if (newPicture) {
pictures.push(newPicture)
}
} catch (error) {
if (error && error.response) {
logger.error('saveEcomImages: error to save image ', { data: error.response.data })
Expand Down
3 changes: 2 additions & 1 deletion functions/lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ const handleFeedTableQueue = async (notification) => {
const products = await tableToEcom.parseProduct(data, body.contentType)
await handleFeedQueue(storeId, products)
} catch (error) {
logger.error('[tableToEcom.parseProduct:error]', { error })
logger.warn('[tableToEcom.parseProduct:error]')
logger.error(error)
throw error
}
}
Expand Down

0 comments on commit 8ef016b

Please sign in to comment.