Skip to content

Commit

Permalink
feat: 增加产品库存结构模板的feed生成
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjue666 committed Nov 1, 2024
1 parent 5866109 commit 0c8779e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/feed/img/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class FeedImg {

}
47 changes: 47 additions & 0 deletions src/feed/quantity/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
/**
* @param {string} sku - SKU of the product
* @param {number} deal_time - 预处理时间 默认2天
* @param {number} quantity - 数量
*/
export interface FeedQuantityData { sku: string, quantity: number, deal_time: number }

export class FeedQuantity {
sellerId: string
list: FeedQuantityData[]
constructor(sellerId: string, list: FeedQuantityData[]) {
this.sellerId = sellerId
this.list = list
}

main() {
return {
header: {
sellerId: this.sellerId,
version: '2.0',
issueLocale: 'en_US',
},
messages: this.genMessage(),
}
}

genMessage() {
return this.list.map((item, idx) => {
return {
messageId: idx + 1,
sku: item.sku,
operationType: 'PATCH',
productType: 'PRODUCT',
patches: [
{
op: 'replace',
path: '/attributes/fulfillment_availability',
value: [
{
fulfillment_channel_code: 'DEFAULT',
quantity: item.quantity,
lead_time_to_ship_max_days: item.deal_time || 2,
},
],
},
],
}
})
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './feed/img'
export * from './feed/price'
export * from './feed/quantity'

Expand Down
1 change: 1 addition & 0 deletions src/listing/img/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class ListingImg {}
11 changes: 11 additions & 0 deletions test/feed/quantity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, it } from 'vitest'
import { FeedQuantity } from '../../src/index'

describe('should', () => {
const t1 = new FeedQuantity('sellerId', [{ sku: 'sku-1', quantity: 100, deal_time: 3 }])
it('t1 message', () => {
const obj = t1.main()
console.log(obj)
expect(obj.messages.length).toEqual(1)
})
})

0 comments on commit 0c8779e

Please sign in to comment.