fix: align jst sku sync with stock spus
This commit is contained in:
parent
273097f8b5
commit
e9a6deb3a1
@ -112,6 +112,10 @@ function buildStableId(prefix: string, value: string) {
|
||||
return `${prefix}-${createHash('sha1').update(value).digest('hex').slice(0, 20)}`
|
||||
}
|
||||
|
||||
function buildStockProductId(sourceSpu: string) {
|
||||
return `jst-stock-${createHash('sha1').update(sourceSpu).digest('hex').slice(0, 16)}`
|
||||
}
|
||||
|
||||
function pickSourceImage(row: JstSkuSourceRow) {
|
||||
return normalizeSourceString(row.pic_big) || normalizeSourceString(row.pic)
|
||||
}
|
||||
@ -179,15 +183,21 @@ function isJstSkuPayload(payload: unknown) {
|
||||
return [
|
||||
readPayloadString(payload, 'source'),
|
||||
readPayloadString(payload, 'sourceTable'),
|
||||
readPayloadString(payload, 'sourceType'),
|
||||
readPayloadString(payload, 'importSource'),
|
||||
readPayloadString(payload, 'externalSource'),
|
||||
readNestedPayloadString(payload, 'source'),
|
||||
readNestedPayloadString(payload, 'sourceTable'),
|
||||
readNestedPayloadString(payload, 'sourceType'),
|
||||
readNestedPayloadString(payload, 'importSource'),
|
||||
readNestedPayloadString(payload, 'externalSource'),
|
||||
].some((value) => {
|
||||
const normalizedValue = value.toLowerCase().replace(/-/g, '_')
|
||||
return normalizedValue === 'jst_sku' || normalizedValue === 'jstsku'
|
||||
return (
|
||||
normalizedValue === 'jst_sku' ||
|
||||
normalizedValue === 'jstsku' ||
|
||||
normalizedValue === 'jst_sku_stock_source'
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -332,7 +342,7 @@ function buildSourceProductPayload(
|
||||
const firstSourceRow = group.rows[0] ?? {}
|
||||
|
||||
const rawPayload = {
|
||||
id: buildStableId('jst-stock', sourceSpu),
|
||||
id: buildStockProductId(sourceSpu),
|
||||
productDevelopmentKind: 'product',
|
||||
spu: sourceSpu.toUpperCase(),
|
||||
projectStatus: 'approved',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user