Skip to content

Commit

Permalink
feat: 完善跟卖产品生成及示例
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjue666 committed Dec 3, 2024
1 parent 18c1094 commit 09ef983
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 46 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ schemaCheck.convertRequiredSchema2FormItems()
## Listing usage

- [ListingProduct](#ListingProduct)
- upload follow asin product [ListingProduct](#upload-follow-asin-product)
- [ListingQuantity](#ListingQuantity)
- [ListingPrice](#ListingPrice)
- [ListingImg](#ListingImg)
Expand Down Expand Up @@ -421,6 +422,59 @@ new ListingProduct({

</details>

### upload follow asin product

<details><summary>Example</summary>

```
const follow_goods = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: {
asin: 'B07Z8Z1VCC',
condition: 'New',
quantity: 100,
deal_time: 3,
sell_price: 88.88,
}, type: 'FOLLOW_ASIN' }).main()
// Result
{
"requirements": "LISTING_OFFER_ONLY",
"attributes": {
"condition_type": [
{
"value": "New"
}
],
"merchant_suggested_asin": [
{
"value": "B07Z8Z1VCC"
}
],
"fulfillment_availability": [
{
"fulfillment_channel_code": "DEFAULT",
"quantity": 100,
"lead_time_to_ship_max_days": 3
}
],
"purchasable_offer": [
{
"our_price": [
{
"schedule": [
{
"value_with_tax": 88.88
}
]
}
]
}
]
}
}
```

</details>

### ListingQuantity

<details><summary>Example</summary>
Expand Down
54 changes: 54 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ schemaCheck.convertRequiredSchema2FormItems()
## Listing接口相关用法

- 上传产品 [ListingProduct](#上传产品)
- 上传跟卖产品 [ListingProduct](#上传跟卖产品)
- 设置产品库存 [ListingQuantity](#设置产品库存)
- 设置产品价格 [ListingPrice](#设置产品价格)
- 设置产品图片 [ListingImg](#设置产品图片)
Expand Down Expand Up @@ -421,6 +422,59 @@ new ListingProduct({

</details>

### 上传跟卖产品

<details><summary>Example</summary>

```
const follow_goods = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: {
asin: 'B07Z8Z1VCC',
condition: 'New',
quantity: 100,
deal_time: 3,
sell_price: 88.88,
}, type: 'FOLLOW_ASIN' }).main()
// 返回结果
{
"requirements": "LISTING_OFFER_ONLY",
"attributes": {
"condition_type": [
{
"value": "New"
}
],
"merchant_suggested_asin": [
{
"value": "B07Z8Z1VCC"
}
],
"fulfillment_availability": [
{
"fulfillment_channel_code": "DEFAULT",
"quantity": 100,
"lead_time_to_ship_max_days": 3
}
],
"purchasable_offer": [
{
"our_price": [
{
"schedule": [
{
"value_with_tax": 88.88
}
]
}
]
}
]
}
}
```

</details>

### 设置产品库存

<details><summary>Example</summary>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spapi-listing-builder",
"type": "module",
"version": "0.1.9",
"version": "0.2.1",
"packageManager": "[email protected]",
"description": "_description_",
"author": "wangjue666 <[email protected]>",
Expand Down
7 changes: 5 additions & 2 deletions src/listing/product/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { renderListingArrValue as renderListingArrValueHelp } from '@/help'
import type { ListingType, ProductData, Recordable, RenderOtherAttributesFn } from '@/help/state'
import { ListingPrice } from '../price'
import { ListingQuantity } from '../quantity'
import { Condition, ProductBaseInfo } from './BaseInfo'
import { ProductParentage } from './Parentage'

Expand Down Expand Up @@ -47,11 +49,13 @@ export class ListingProduct {
value: data.asin,
},
],
fulfillment_availability: data.quantity && new ListingQuantity({ quantity: data.quantity, deal_time: data.deal_time }).genValue(),
purchasable_offer: data.sell_price && new ListingPrice({ sell_price: data.sell_price }).genValue(),
}
Object.assign(attributes, this.callRenderOtherAttributesFn(attributes))
return {
productType: data.product_type,
requirements: 'LISTING',
requirements: 'LISTING_OFFER_ONLY',
attributes,
}
}
Expand All @@ -70,7 +74,6 @@ export class ListingProduct {
productType: data.product_type,
requirements: 'LISTING',
attributes,

}
}

Expand Down
101 changes: 58 additions & 43 deletions test/listing/product/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
import { describe, expect, it } from 'vitest'
import { ListingProduct } from '../../../src/index'

import { childListingData1, childListingData2, listingData, parentListingData } from './state'
import type { Recordable } from '../../../src/index'

describe('should', () => {
it('listing结构', () => {
const t1 = new ListingProduct({
marketplace_id: 'ATVPDKIKX0DER',
data: listingData,
renderOtherAttributesFn: ({ renderListingArrValue, data }) => {
return {
list_price: renderListingArrValue(data.sell_price),
}
},
})
const obj: Recordable = t1.main()
console.log(JSON.stringify(obj, null, 2))
expect(obj.attributes.item_name[0].value).toEqual(listingData.title)
expect(obj.attributes.list_price[0].value).toEqual(String(listingData.sell_price))
})

it('有变体的父产品', () => {
const t1 = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: parentListingData })
const obj: Recordable = t1.main()
console.log(JSON.stringify(obj, null, 2))
expect(obj.attributes.item_name[0].value).toEqual(parentListingData.title)
expect(obj.attributes.parentage_level[0].value).toEqual('parent')
expect(obj.attributes.variation_theme[0].value).toEqual('SIZE_NAME/COLOR_NAME')
})

it('变体产品', () => {
const t1 = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: childListingData1 })
const t2 = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: childListingData2 })
const obj1: Recordable = t1.main()
const obj2: Recordable = t2.main()
console.log(JSON.stringify(obj1, null, 2))
expect(obj1.attributes.parentage_level[0].value).toEqual('child')
expect(obj2.attributes.parentage_level[0].value).toEqual('child')
expect(obj1.attributes.variation_theme[0].value).toEqual('SIZE_NAME/COLOR_NAME')
})
})
import { describe, expect, it } from 'vitest'
import { ListingProduct } from '../../../src/index'

import { childListingData1, childListingData2, listingData, parentListingData } from './state'
import type { Recordable } from '../../../src/index'

describe('should', () => {
it('listing结构', () => {
const t1 = new ListingProduct({
marketplace_id: 'ATVPDKIKX0DER',
data: listingData,
renderOtherAttributesFn: ({ renderListingArrValue, data }) => {
return {
list_price: renderListingArrValue(data.sell_price),
}
},
})
const obj: Recordable = t1.main()
console.log(JSON.stringify(obj, null, 2))
expect(obj.attributes.item_name[0].value).toEqual(listingData.title)
expect(obj.attributes.list_price[0].value).toEqual(String(listingData.sell_price))
})

it('有变体的父产品', () => {
const t1 = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: parentListingData })
const obj: Recordable = t1.main()
console.log(JSON.stringify(obj, null, 2))
expect(obj.attributes.item_name[0].value).toEqual(parentListingData.title)
expect(obj.attributes.parentage_level[0].value).toEqual('parent')
expect(obj.attributes.variation_theme[0].value).toEqual('SIZE_NAME/COLOR_NAME')
})

it('变体产品', () => {
const t1 = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: childListingData1 })
const t2 = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: childListingData2 })
const obj1: Recordable = t1.main()
const obj2: Recordable = t2.main()
console.log(JSON.stringify(obj1, null, 2))
expect(obj1.attributes.parentage_level[0].value).toEqual('child')
expect(obj2.attributes.parentage_level[0].value).toEqual('child')
expect(obj1.attributes.variation_theme[0].value).toEqual('SIZE_NAME/COLOR_NAME')
})

it('跟卖产品', () => {
const follow_goods = new ListingProduct({ marketplace_id: 'ATVPDKIKX0DER', data: {
asin: 'B07Z8Z1VCC',
condition: 'New',
quantity: 100,
deal_time: 3,
sell_price: 88.88,
}, type: 'FOLLOW_ASIN' }).main()

console.log(JSON.stringify(follow_goods, null, 2))
expect(follow_goods.attributes.condition_type[0].value).toEqual('New')
expect(follow_goods.attributes.merchant_suggested_asin[0].value).toEqual('B07Z8Z1VCC')
expect(follow_goods.attributes.fulfillment_availability[0].quantity).toEqual(100)
})
})

0 comments on commit 09ef983

Please sign in to comment.