Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
533a2439de |
@@ -32,9 +32,9 @@
|
||||
- [x] Information about product quantity
|
||||
- [x] Stocks in seller's warehouses (FBS и rFBS)
|
||||
- [x] Update prices
|
||||
- [ ] Get product price information
|
||||
- [ ] Get information about the markdown and the main product by the markdown product SKU
|
||||
- [ ] Set a discount on a markdown product
|
||||
- [x] Get product price information
|
||||
- [x] Get information about the markdown and the main product by the markdown product SKU
|
||||
- [x] Set a discount on a markdown product
|
||||
|
||||
## Promotions
|
||||
- [x] Available promotions
|
||||
|
||||
292
ozon/products.go
292
ozon/products.go
@@ -1283,7 +1283,7 @@ type GetDescriptionOfProductResponse struct {
|
||||
// Product characteristic value
|
||||
Value string `json:"value"`
|
||||
} `json:"values"`
|
||||
} `json:"attributes`
|
||||
} `json:"attributes"`
|
||||
} `json:"complex_attributes"`
|
||||
|
||||
// Depth
|
||||
@@ -1714,3 +1714,293 @@ func (c Products) StatusOfUploadingActivationCodes(params *StatusOfUploadingActi
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type GetProductPriceInfoParams struct {
|
||||
// Filter by product
|
||||
Filter GetProductPriceInfoFilter `json:"filter"`
|
||||
|
||||
// Identifier of the last value on page.
|
||||
//
|
||||
// To get the next values, specify the recieved value in the next request in the `last_id` parameter
|
||||
LastId string `json:"last_id"`
|
||||
|
||||
// Number of values per page. Minimum is 1, maximum is 1000
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
type GetProductPriceInfoFilter struct {
|
||||
// Filter by the `offer_id` parameter. It is possible to pass a list of values
|
||||
OfferId []string `json:"offer_id"`
|
||||
|
||||
// Filter by the `product_id` parameter. It is possible to pass a list of up to 1000 values
|
||||
ProductId []int64 `json:"product_id"`
|
||||
|
||||
// Filter by product visibility
|
||||
Visibility string `json:"visibility" default:"ALL"`
|
||||
}
|
||||
|
||||
type GetProductPriceInfoResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Result
|
||||
Result struct {
|
||||
// Products list
|
||||
Items []struct {
|
||||
// Commissions information
|
||||
Commissions struct {
|
||||
// Last mile (FBO)
|
||||
FBOLastMile float64 `json:"fbo_deliv_to_customer_amount"`
|
||||
|
||||
// Pipeline to (FBO)
|
||||
FBOPipelineTo float64 `json:"fbo_direct_flow_trans_max_amount"`
|
||||
|
||||
// Pipeline from (FBO)
|
||||
FBOPipelineFrom float64 `json:"fbo_direct_flow_trans_min_amount"`
|
||||
|
||||
// Order packaging fee (FBO)
|
||||
FBOOrderPackagingFee float64 `json:"fbo_fulfillment_amount"`
|
||||
|
||||
// Return and cancellation fees (FBO)
|
||||
FBOReturnCancellationFee float64 `json:"fbo_return_flow_amount"`
|
||||
|
||||
// Reverse logistics fee from (FBO)
|
||||
FBOReverseLogisticsFeeFrom float64 `json:"fbo_return_flow_trans_min_amount"`
|
||||
|
||||
// Reverse logistics fee to (FBO)
|
||||
FBOReverseLogisticsFeeTo float64 `json:"fbo_return_flow_trans_max_amount"`
|
||||
|
||||
// Last mile (FBS)
|
||||
FBSLastMile float64 `json:"fbs_deliv_to_customer_amount"`
|
||||
|
||||
// Pipeline to (FBS)
|
||||
FBSPipelineTo float64 `json:"fbs_direct_flow_trans_max_amount"`
|
||||
|
||||
// Pipeline from (FBS)
|
||||
FBSPipelineFrom float64 `json:"fbs_direct_flow_trans_min_amount"`
|
||||
|
||||
// Shipment processing fee to (FBS)
|
||||
FBSShipmentProcessingToFee float64 `json:"fbs_first_mile_min_amount"`
|
||||
|
||||
// Shipment processing fee from (FBS)
|
||||
FBSShipmentProcessingFromFee float64 `json:"Shipment processing fee from (FBS)"`
|
||||
|
||||
// Return and cancellation fees, shipment processing (FBS)
|
||||
FBSReturnCancellationProcessingFee float64 `json:"fbs_return_flow_amount"`
|
||||
|
||||
// Return and cancellation fees, pipeline to (FBS)
|
||||
FBSReturnCancellationToFees float64 `json:"fbs_return_flow_trans_max_amount"`
|
||||
|
||||
// Return and cancellation fees, pipeline from (FBS)
|
||||
FBSReturnCancellationFromFees float64 `json:"fbs_return_flow_trans_min_amount"`
|
||||
|
||||
// Sales commission percentage (FBO and FBS)
|
||||
SalesCommissionRate float64 `json:"sales_percent"`
|
||||
} `json:"commissions"`
|
||||
|
||||
// Promotions information
|
||||
MarketingActions []struct {
|
||||
// Seller's promotions. The parameters date_from, date_to, discount_value and title are specified for each seller's promotion
|
||||
Actions []struct {
|
||||
// Date and time when the seller's promotion starts
|
||||
DateFrom time.Time `json:"date_from"`
|
||||
|
||||
// Date and time when the seller's promotion ends
|
||||
DateTo time.Time `json:"date_to"`
|
||||
|
||||
// Discount on the seller's promotion
|
||||
DiscountValue string `json:"discount_value"`
|
||||
|
||||
// Promotion name
|
||||
Title string `json:"title"`
|
||||
} `json:"actions"`
|
||||
|
||||
// Current period start date and time for all current promotions
|
||||
CurrentPeriodFrom time.Time `json:"current_period_from"`
|
||||
|
||||
// Current period end date and time for all current promotions
|
||||
CurrentPeriodTo time.Time `json:"current_period_to"`
|
||||
|
||||
// If a promotion can be applied to the product at the expense of Ozon, this field is set to true
|
||||
OzonActionsExist bool `json:"ozon_actions_exist"`
|
||||
} `json:"marketing_actions"`
|
||||
|
||||
// Seller product identifier
|
||||
OfferId string `json:"offer_id"`
|
||||
|
||||
// Product price
|
||||
Price struct {
|
||||
// If promos auto-application is enabled, the value is true
|
||||
AutoActionEnabled bool `json:"auto_action_enabled"`
|
||||
|
||||
// Currency of your prices. It matches the currency set in the personal account settings
|
||||
CurrencyCode string `json:"currency_code"`
|
||||
|
||||
// Product price including all promotion discounts. This value will be indicated on the Ozon storefront
|
||||
MarketingPrice string `json:"marketing_price"`
|
||||
|
||||
// Product price with seller's promotions applied
|
||||
MarketingSellerPrice string `json:"marketing_seller_price"`
|
||||
|
||||
// Minimum price for similar products on Ozon
|
||||
MinOzonPrice string `json:"min_ozon_price"`
|
||||
|
||||
// Minimum product price with all promotions applied
|
||||
MinPrice string `json:"min_price"`
|
||||
|
||||
// Price before discounts. Displayed strikethrough on the product description page
|
||||
OldPrice string `json:"old_price"`
|
||||
|
||||
// Price for customers with an Ozon Premium subscription
|
||||
PremiumPrice string `json:"premium_price"`
|
||||
|
||||
// Product price including discounts. This value is shown on the product description page
|
||||
Price string `json:"price"`
|
||||
|
||||
// Product price suggested by the system based on similar offers
|
||||
RecommendedPrice string `json:"recommended_price"`
|
||||
|
||||
// Retailer price
|
||||
RetailPrice string `json:"retail_price"`
|
||||
|
||||
// Product VAT rate
|
||||
VAT string `json:"vat"`
|
||||
} `json:"price"`
|
||||
|
||||
// Price index
|
||||
PriceIndex string `json:"price_index"`
|
||||
|
||||
// Product identifier
|
||||
ProductId int64 `json:"product_id"`
|
||||
|
||||
// Product volume weight
|
||||
VolumeWeight float64 `json:"volume_weight"`
|
||||
} `json:"items"`
|
||||
|
||||
// Identifier of the last value on page. Leave this field blank in the first request.
|
||||
//
|
||||
// To get the next values, specify last_id from the response of the previous request
|
||||
LastId string `json:"last_id"`
|
||||
|
||||
// Products number in the list
|
||||
Total int32 `json:"total"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// You can specify up to 1000 products in the request
|
||||
func (c Products) GetProductPriceInfo(params *GetProductPriceInfoParams) (*GetProductPriceInfoResponse, error) {
|
||||
url := "/v4/product/info/prices"
|
||||
|
||||
resp := &GetProductPriceInfoResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type GetMarkdownInfoParams struct {
|
||||
// Markdown products SKUs list
|
||||
DiscountedSKUs []string `json:"discounted_skus"`
|
||||
}
|
||||
|
||||
type GetMarkdownInfoResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Information about the markdown and the main product
|
||||
Items []struct{
|
||||
// Comment on the damage reason
|
||||
CommentReasonDamaged string `json:"comment_reason_damaged"`
|
||||
|
||||
// Product condition: new or used
|
||||
Condition string `json:"condition"`
|
||||
|
||||
// Product condition on a 1 to 7 scale.
|
||||
// - 1 — satisfactory,
|
||||
// - 2 — good,
|
||||
// - 3 — very good,
|
||||
// - 4 — excellent,
|
||||
// - 5–7 — like new
|
||||
ConditionEstimate string `json:"condition_estimate"`
|
||||
|
||||
// Product defects
|
||||
Defects string `json:"defects"`
|
||||
|
||||
// Markdown product SKU
|
||||
DiscountedSKU int64 `json:"discounted_sku"`
|
||||
|
||||
// Mechanical damage description
|
||||
MechanicalDamage string `json:"mechanical_damage"`
|
||||
|
||||
// Packaging damage description
|
||||
PackageDamage string `json:"package_damage"`
|
||||
|
||||
// Indication of package integrity damage
|
||||
PackagingViolation string `json:"packaging_violation"`
|
||||
|
||||
// Damage reason
|
||||
ReasonDamaged string `json:"reason_damaged"`
|
||||
|
||||
// Indication of repaired product
|
||||
Repair string `json:"repair"`
|
||||
|
||||
// Indication that the product is incomplete
|
||||
Shortage string `json:"shortage"`
|
||||
|
||||
// Main products SKU
|
||||
SKU int64 `json:"sku"`
|
||||
|
||||
// Indication that the product has a valid warranty
|
||||
WarrantyType string `json:"warranty_type"`
|
||||
} `json:"items"`
|
||||
}
|
||||
|
||||
// Get information about the markdown and the main product by the markdown product SKU
|
||||
//
|
||||
// A method for getting information about the condition and defects of a markdown product by its SKU.
|
||||
// The method also returns the SKU of the main product
|
||||
func (c Products) GetMarkdownInfo(params *GetMarkdownInfoParams) (*GetMarkdownInfoResponse, error) {
|
||||
url := "/v1/product/info/discounted"
|
||||
|
||||
resp := &GetMarkdownInfoResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type SetDiscountOnMarkdownProductParams struct{
|
||||
// Discount amount: from 3 to 99 percents
|
||||
Discount int32 `json:"discount"`
|
||||
|
||||
// Product identifier
|
||||
ProductId int64 `json:"product_id"`
|
||||
}
|
||||
|
||||
type SetDiscountOnMarkdownProductResponse struct{
|
||||
core.CommonResponse
|
||||
|
||||
// Method result. true if the query was executed without errors
|
||||
Result bool `json:"result"`
|
||||
}
|
||||
|
||||
// A method for setting the discount percentage on markdown products sold under the FBS scheme
|
||||
func (c Products) SetDiscountOnMarkdownProduct(params *SetDiscountOnMarkdownProductParams) (*SetDiscountOnMarkdownProductResponse, error) {
|
||||
url := "/v1/product/update/discount"
|
||||
|
||||
resp := &SetDiscountOnMarkdownProductResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -2197,3 +2197,213 @@ func TestStatusOfUploadingActivationCodes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetProductPriceInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *GetProductPriceInfoParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&GetProductPriceInfoParams{
|
||||
Filter: GetProductPriceInfoFilter{
|
||||
OfferId: []string{"356792"},
|
||||
ProductId: []int64{243686911},
|
||||
Visibility: "ALL",
|
||||
},
|
||||
},
|
||||
`{
|
||||
"result": {
|
||||
"items": [
|
||||
{
|
||||
"product_id": 243686911,
|
||||
"offer_id": "356792",
|
||||
"price": {
|
||||
"currency_code": "RUB",
|
||||
"price": "499.0000",
|
||||
"old_price": "579.0000",
|
||||
"premium_price": "",
|
||||
"recommended_price": "",
|
||||
"retail_price": "",
|
||||
"vat": "0.200000",
|
||||
"min_ozon_price": "",
|
||||
"marketing_price": "",
|
||||
"marketing_seller_price": "",
|
||||
"auto_action_enabled": true
|
||||
},
|
||||
"price_index": "0.00",
|
||||
"commissions": {
|
||||
"sales_percent": 15,
|
||||
"fbo_fulfillment_amount": 0,
|
||||
"fbo_direct_flow_trans_min_amount": 31,
|
||||
"fbo_direct_flow_trans_max_amount": 46.5,
|
||||
"fbo_deliv_to_customer_amount": 14.75,
|
||||
"fbo_return_flow_amount": 50,
|
||||
"fbo_return_flow_trans_min_amount": 21.7,
|
||||
"fbo_return_flow_trans_max_amount": 21.7,
|
||||
"fbs_first_mile_min_amount": 0,
|
||||
"fbs_first_mile_max_amount": 0,
|
||||
"fbs_direct_flow_trans_min_amount": 41,
|
||||
"fbs_direct_flow_trans_max_amount": 61.5,
|
||||
"fbs_deliv_to_customer_amount": 60,
|
||||
"fbs_return_flow_amount": 40,
|
||||
"fbs_return_flow_trans_min_amount": 41,
|
||||
"fbs_return_flow_trans_max_amount": 61.5
|
||||
},
|
||||
"marketing_actions": null,
|
||||
"volume_weight": 0
|
||||
}
|
||||
],
|
||||
"total": 1,
|
||||
"last_id": "ceVуbA=="
|
||||
}
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&GetProductPriceInfoParams{},
|
||||
`{
|
||||
"code": 16,
|
||||
"message": "Client-Id and Api-Key headers are required"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||
|
||||
resp, err := c.Products().GetProductPriceInfo(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != test.statusCode {
|
||||
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMarkdownInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *GetMarkdownInfoParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&GetMarkdownInfoParams{
|
||||
DiscountedSKUs: []string{"635548518"},
|
||||
},
|
||||
`{
|
||||
"items": [
|
||||
{
|
||||
"discounted_sku": 635548518,
|
||||
"sku": 320067758,
|
||||
"condition_estimation": "4",
|
||||
"packaging_violation": "",
|
||||
"warranty_type": "",
|
||||
"reason_damaged": "Механическое повреждение",
|
||||
"comment_reason_damaged": "повреждена заводская упаковка",
|
||||
"defects": "",
|
||||
"mechanical_damage": "",
|
||||
"package_damage": "",
|
||||
"shortage": "",
|
||||
"repair": "",
|
||||
"condition": ""
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&GetMarkdownInfoParams{},
|
||||
`{
|
||||
"code": 16,
|
||||
"message": "Client-Id and Api-Key headers are required"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||
|
||||
resp, err := c.Products().GetMarkdownInfo(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != test.statusCode {
|
||||
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
if len(resp.Items) > 0 {
|
||||
if fmt.Sprint(resp.Items[0].DiscountedSKU) != test.params.DiscountedSKUs[0] {
|
||||
t.Errorf("SKUs in reqest and resonse are not equal")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDiscountOnMarkdownProductParams(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *SetDiscountOnMarkdownProductParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&SetDiscountOnMarkdownProductParams{
|
||||
Discount: 0,
|
||||
ProductId: 0,
|
||||
},
|
||||
`{
|
||||
"result": true
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&SetDiscountOnMarkdownProductParams{},
|
||||
`{
|
||||
"code": 16,
|
||||
"message": "Client-Id and Api-Key headers are required"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||
|
||||
resp, err := c.Products().SetDiscountOnMarkdownProduct(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != test.statusCode {
|
||||
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user