Skip to content

Commit 2f1dbd5

Browse files
committed
add method for updating product characteristics
1 parent 387af0e commit 2f1dbd5

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

ozon/products.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,3 +2126,59 @@ func (c Products) NumberOfSubsToProductAvailability(params *NumberOfSubsToProduc
21262126

21272127
return resp, nil
21282128
}
2129+
2130+
type UpdateCharacteristicsParams struct {
2131+
// Products and characteristics to be updated
2132+
Items []UpdateCharacteristicsItem `json:"items"`
2133+
}
2134+
2135+
type UpdateCharacteristicsItem struct {
2136+
// Product characteristics
2137+
Attributes []UpdateCharacteristicsItemAttribute `json:"attributes"`
2138+
2139+
// Product ID
2140+
OfferId string `json:"offer_id"`
2141+
}
2142+
2143+
type UpdateCharacteristicsItemAttribute struct {
2144+
// Identifier of the characteristic that supports nested properties.
2145+
// Each of the nested characteristics can have multiple value variants
2146+
ComplexId int64 `json:"complex_id"`
2147+
2148+
// Characteristic identifier
2149+
Id int64 `json:"id"`
2150+
2151+
// Array of nested characteristic values
2152+
Values []UpdateCharacteristicsItemValue `json:"values"`
2153+
}
2154+
2155+
type UpdateCharacteristicsItemValue struct {
2156+
// Characteristic identifier in the dictionary
2157+
DictionaryValueId int64 `json:"dictionary_value_id"`
2158+
2159+
// Product characteristic value
2160+
Value string `json:"value"`
2161+
}
2162+
2163+
type UpdateCharacteristicsResponse struct {
2164+
core.CommonResponse
2165+
2166+
// Products update task code.
2167+
//
2168+
// To check the update status, pass the received value to the `/v1/product/import/info` method
2169+
TaskId int64 `json:"task_id"`
2170+
}
2171+
2172+
func (c Products) UpdateCharacteristics(params *UpdateCharacteristicsParams) (*UpdateCharacteristicsResponse, error) {
2173+
url := "/v1/product/attributes/update"
2174+
2175+
resp := &UpdateCharacteristicsResponse{}
2176+
2177+
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
2178+
if err != nil {
2179+
return nil, err
2180+
}
2181+
response.CopyCommonResponse(&resp.CommonResponse)
2182+
2183+
return resp, nil
2184+
}

ozon/products_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,3 +2487,65 @@ func TestNumberOfSubsToProductAvailability(t *testing.T) {
24872487
}
24882488
}
24892489
}
2490+
2491+
func TestUpdateCharacteristics(t *testing.T) {
2492+
t.Parallel()
2493+
2494+
tests := []struct {
2495+
statusCode int
2496+
headers map[string]string
2497+
params *UpdateCharacteristicsParams
2498+
response string
2499+
}{
2500+
// Test Ok
2501+
{
2502+
http.StatusOK,
2503+
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
2504+
&UpdateCharacteristicsParams{
2505+
Items: []UpdateCharacteristicsItem{
2506+
{
2507+
Attributes: []UpdateCharacteristicsItemAttribute{
2508+
{
2509+
ComplexId: 0,
2510+
Id: 0,
2511+
Values: []UpdateCharacteristicsItemValue{
2512+
{
2513+
DictionaryValueId: 0,
2514+
Value: "string",
2515+
},
2516+
},
2517+
},
2518+
},
2519+
OfferId: "string",
2520+
},
2521+
},
2522+
},
2523+
`{
2524+
"task_id": 0
2525+
}`,
2526+
},
2527+
// Test No Client-Id or Api-Key
2528+
{
2529+
http.StatusUnauthorized,
2530+
map[string]string{},
2531+
&UpdateCharacteristicsParams{},
2532+
`{
2533+
"code": 16,
2534+
"message": "Client-Id and Api-Key headers are required"
2535+
}`,
2536+
},
2537+
}
2538+
2539+
for _, test := range tests {
2540+
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
2541+
2542+
resp, err := c.Products().UpdateCharacteristics(test.params)
2543+
if err != nil {
2544+
t.Error(err)
2545+
}
2546+
2547+
if resp.StatusCode != test.statusCode {
2548+
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
2549+
}
2550+
}
2551+
}

0 commit comments

Comments
 (0)