Skip to content

Commit 40dd5b8

Browse files
authored
Update October 26, 2023 (#46)
1 parent e5f2007 commit 40dd5b8

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

ozon/common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,13 @@ const (
577577
ReportInfoSuccess ReportInfoStatus = "success"
578578
ReportInfoFailed ReportInfoStatus = "failed"
579579
)
580+
581+
type SKUAvailability string
582+
583+
const (
584+
SKUAvailabilityHidden = "HIDDEN"
585+
SKUAvailabilityAvailable = "AVAILABLE"
586+
587+
// SKU is deleted
588+
SKUAvailabilityUnavailable = "UNAVAILABLE"
589+
)

ozon/products.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,3 +2335,64 @@ func (c Products) UpdateCharacteristics(ctx context.Context, params *UpdateChara
23352335

23362336
return resp, nil
23372337
}
2338+
2339+
type GetRelatedSKUsParams struct {
2340+
// List of SKUs
2341+
SKUs []string `json:"sku"`
2342+
}
2343+
2344+
type GetRelatedSKUsResponse struct {
2345+
core.CommonResponse
2346+
2347+
// Related SKUs information
2348+
Items []GetRelatedSKUsItem `json:"items"`
2349+
2350+
// Errors
2351+
Errors []GetRelatedSKUsError `json:"errors"`
2352+
}
2353+
2354+
type GetRelatedSKUsItem struct {
2355+
// Product availability attribute by SKU
2356+
Availability SKUAvailability `json:"availability"`
2357+
2358+
// Date and time of deletion
2359+
DeletedAt time.Time `json:"deleted_at"`
2360+
2361+
// Delivery scheme
2362+
DeliverySchema string `json:"delivery_schema"`
2363+
2364+
// Product identifier
2365+
ProductId int64 `json:"product_id"`
2366+
2367+
// Product identifier in the Ozon system, SKU
2368+
SKU int64 `json:"sku"`
2369+
}
2370+
2371+
type GetRelatedSKUsError struct {
2372+
// Error code
2373+
Code string `json:"code"`
2374+
2375+
// SKU, in which the error occurred
2376+
SKU int `json:"sku"`
2377+
2378+
// Error text
2379+
Message string `json:"message"`
2380+
}
2381+
2382+
// You can pass any SKU in the request, even a deleted one.
2383+
// The response will contain all SKUs related to the passed ones.
2384+
//
2385+
// In one request, you can pass up to 200 SKUs.
2386+
func (c Products) GetRelatedSKUs(ctx context.Context, params *GetRelatedSKUsParams) (*GetRelatedSKUsResponse, error) {
2387+
url := "/v1/product/related-sku/get"
2388+
2389+
resp := &GetRelatedSKUsResponse{}
2390+
2391+
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
2392+
if err != nil {
2393+
return nil, err
2394+
}
2395+
response.CopyCommonResponse(&resp.CommonResponse)
2396+
2397+
return resp, nil
2398+
}

ozon/products_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,3 +2600,69 @@ func TestUpdateCharacteristics(t *testing.T) {
26002600
}
26012601
}
26022602
}
2603+
2604+
func TestGetRelatedSKUs(t *testing.T) {
2605+
t.Parallel()
2606+
2607+
tests := []struct {
2608+
statusCode int
2609+
headers map[string]string
2610+
params *GetRelatedSKUsParams
2611+
response string
2612+
}{
2613+
// Test Ok
2614+
{
2615+
http.StatusOK,
2616+
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
2617+
&GetRelatedSKUsParams{
2618+
SKUs: []string{"321", "322"},
2619+
},
2620+
`{
2621+
"items": [
2622+
{
2623+
"availability": "HIDDEN",
2624+
"deleted_at": "2019-08-24T14:15:22Z",
2625+
"delivery_schema": "fbs",
2626+
"product_id": 123,
2627+
"sku": 321
2628+
}
2629+
],
2630+
"errors": [
2631+
{
2632+
"code": "test_code",
2633+
"sku": 322,
2634+
"message": "test_message"
2635+
}
2636+
]
2637+
}`,
2638+
},
2639+
// Test No Client-Id or Api-Key
2640+
{
2641+
http.StatusUnauthorized,
2642+
map[string]string{},
2643+
&GetRelatedSKUsParams{},
2644+
`{
2645+
"code": 16,
2646+
"message": "Client-Id and Api-Key headers are required"
2647+
}`,
2648+
},
2649+
}
2650+
2651+
for _, test := range tests {
2652+
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
2653+
2654+
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
2655+
resp, err := c.Products().GetRelatedSKUs(ctx, test.params)
2656+
if err != nil {
2657+
t.Error(err)
2658+
}
2659+
2660+
if resp.StatusCode != test.statusCode {
2661+
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
2662+
}
2663+
2664+
if len(resp.Errors)+len(resp.Items) != len(test.params.SKUs) {
2665+
t.Errorf("expected equal length of skus in request and response")
2666+
}
2667+
}
2668+
}

0 commit comments

Comments
 (0)