update/6-october-2023 - New Categories' methods version (#43)

This commit is contained in:
Kirill
2023-10-08 19:02:14 +03:00
committed by GitHub
parent 699d210296
commit b07968d280
4 changed files with 122 additions and 139 deletions

View File

@@ -12,17 +12,14 @@ type Categories struct {
}
type GetProductTreeParams struct {
// Category identifier
CategoryId int64 `json:"category_id"`
// Response language
Language Language `json:"language" default:"DEFAULT"`
Language Language `json:"language"`
}
type GetProductTreeResponse struct {
core.CommonResponse
// Category list
// Categories list
Result []GetProductTreeResult `json:"result"`
}
@@ -30,19 +27,29 @@ type GetProductTreeResult struct {
// Category identifier
CategoryId int64 `json:"category_id"`
// Subcategory tree
Children []GetProductTreeResponse `json:"children"`
// Category name
Title string `json:"title"`
CategoryName string `json:"category_name"`
// `true`, if you can't create products in the category. `false`, if you can
Disabled bool `json:"disabled"`
// Product type identifier
TypeId int64 `json:"type_id"`
// Product type name
TypeName string `json:"type_name"`
// Subcategory tree
Children []GetProductTreeResult `json:"children"`
}
// Returns product categories in the tree view.
//
// New products can be created in the last level categories only.
// This means that you need to match these particular categories with the categories of your site.
// It is not possible to create categories by user request
func (c Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*GetProductTreeResponse, error) {
url := "/v2/category/tree"
// We don't create new categories by user request.
func (c *Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*GetProductTreeResponse, error) {
url := "/v1/description-category/tree"
resp := &GetProductTreeResponse{}
@@ -56,14 +63,14 @@ func (c Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*Ge
}
type GetCategoryAttributesParams struct {
// Filter by characteristics
AttributeType AttributeType `json:"attribute_type" default:"ALL"`
// Category identifier
CategoryId []int64 `json:"category_id"`
CategoryId int64 `json:"category_id"`
// Response language
Language Language `json:"language" default:"DEFAULT"`
Language Language `json:"language"`
// Product type identifier
TypeId int64 `json:"type_id"`
}
type GetCategoryAttributesResponse struct {
@@ -74,19 +81,6 @@ type GetCategoryAttributesResponse struct {
}
type GetCategoryAttributesResult struct {
// Array of product characteristics
Attributes []GetCategoryAttributesResultAttribute `json:"attributes"`
// Category identifier
CategoryId int64 `json:"category_id"`
}
type GetCategoryAttributesResultAttribute struct {
// Indication that the dictionary attribute values depend on the category:
// - true — the attribute has its own set of values for each category.
// - false — the attribute has the same set of values for all categories
CategoryDependent bool `json:"category_dependent"`
// Characteristic description
Description string `json:"description"`
@@ -99,26 +93,29 @@ type GetCategoryAttributesResultAttribute struct {
// Characteristics group name
GroupName string `json:"group_name"`
// Document generation task number
// Number of document generation task
Id int64 `json:"id"`
// Indicates that the attribute is aspect. An aspect attribute is a characteristic that distinguishes products of the same model.
//
// For example, clothes and shoes of the same model may have different colors and sizes. That is, color and size are aspect attributes.
// For example, clothes or shoes of the same model may have different colors and sizes. That is, color and size are aspect attributes.
//
// Values description:
// - true — the attribute is aspect and cannot be changed after the products are delivered to the warehouse or sold from the seller's warehouse.
// - false — the attribute is not aspect and can be changed at any time
//
// - `true`—the attribute is aspect and can't be changed after the products are delivered to the warehouse or sold from the seller's warehouse.
// - `false`—the attribute is not aspect and can be changed at any time
IsAspect bool `json:"is_aspect"`
// Indicates that the characteristic is a set of values:
// - true — the characteristic is a set of values,
// - false — the characteristic consists of a single value
//
// - `true`—the characteristic is a set of values,
// - `false`—the characteristic consists of a single value
IsCollection bool `json:"is_collection"`
// Indicates that the characteristic is mandatory:
// - true — a mandatory characteristic,
// - false — you can leave the characteristic out
//
// - `true`—a mandatory characteristic,
// - `false`—an optional characteristic
IsRequired bool `json:"is_required"`
// Name
@@ -128,15 +125,13 @@ type GetCategoryAttributesResultAttribute struct {
Type string `json:"type"`
}
// Getting characteristics for specified product category.
// Getting characteristics for specified product category and type.
//
// Pass up to 20 category identifiers in the `category_id` list.
//
// You can check whether the attribute has a nested directory by the `dictionary_id` parameter.
// The 0 value means there is no directory. If the value is different, then there are directories.
// You can get them using the `/v2/category/attribute/values` method
func (c Categories) Attributes(ctx context.Context, params *GetCategoryAttributesParams) (*GetCategoryAttributesResponse, error) {
url := "/v3/category/attribute"
// If the dictionary_id value is 0, there is no directory.
// If the value is different, there are directories.
// Get them using the `/v1/description-category/attribute/values` method.
func (c *Categories) Attributes(ctx context.Context, params *GetCategoryAttributesParams) (*GetCategoryAttributesResponse, error) {
url := "/v1/description-category/attribute"
resp := &GetCategoryAttributesResponse{}
@@ -157,39 +152,55 @@ type GetAttributeDictionaryParams struct {
CategoryId int64 `json:"category_id"`
// Response language
// The default language is Russian
Language Language `json:"language" default:"DEFAULT"`
Language Language `json:"language"`
// Identifier of the directory to start the response with.
// If `last_value_id` is 10, the response will contain directories starting from the 11th
LastValueId int64 `json:"last_value_id"`
// Number of values in the response:
// - maximum — 5000
// - minimum — 1
//
// - maximum—5000,
// - minimum—1.
Limit int64 `json:"limit"`
// Product type identifier
TypeId int64 `json:"type_id"`
}
type GetAttributeDictionaryResponse struct {
core.CommonResponse
// Indication that only part of characteristic values was returned in the response:
//
// - true—make a request with a new last_value_id parameter value for getting the rest of characteristic values;
// - false—all characteristic values were returned
HasNext bool `json:"has_next"`
// Method result
// Characteristic values
Result []GetAttributeDictionaryResult `json:"result"`
}
type GetAttributeDictionaryResult struct {
Id int64 `json:"id"`
Info string `json:"info"`
// Characteristic value identifier
Id int64 `json:"id"`
// Additional description
Info string `json:"info"`
// Image link
Picture string `json:"picture"`
// Product characteristic value
Value string `json:"value"`
}
// You can use the `/v3/category/attribute` method to check if an attribute has a nested directory.
// If there are directories, get them using this method
func (c Categories) AttributesDictionary(ctx context.Context, params *GetAttributeDictionaryParams) (*GetAttributeDictionaryResponse, error) {
url := "/v2/category/attribute/values"
// Returns characteristics value directory.
//
// To check if an attribute has a nested directory,
// use the `/v1/description-category/attribute` method.
func (c *Categories) AttributesDictionary(ctx context.Context, params *GetAttributeDictionaryParams) (*GetAttributeDictionaryResponse, error) {
url := "/v1/description-category/attribute"
resp := &GetAttributeDictionaryResponse{}

View File

@@ -22,14 +22,17 @@ func TestGetProductTree(t *testing.T) {
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetProductTreeParams{
CategoryId: 17034410,
Language: English,
},
`{
"result": [
{
"category_id": 17034410,
"title": "Развивающие игрушки",
"children": []
"category_id": 0,
"category_name": "string",
"children": [],
"disabled": true,
"type_id": 0,
"type_name": "string"
}
]
}`,
@@ -58,14 +61,6 @@ func TestGetProductTree(t *testing.T) {
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.Result) > 0 {
if resp.Result[0].CategoryId != test.params.CategoryId {
t.Errorf("First category ids in request and response are not equal")
}
}
}
}
}
@@ -83,25 +78,23 @@ func TestGetCategoryAttributes(t *testing.T) {
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetCategoryAttributesParams{
CategoryId: []int64{17034410},
CategoryId: 12345,
Language: English,
TypeId: 2,
},
`{
"result": [
{
"category_id": 17034410,
"attributes": [
{
"id": 85,
"name": "Бренд",
"description": "Укажите наименование бренда, под которым произведен товар. Если товар не имеет бренда, используйте значение \"Нет бренда\"",
"type": "String",
"is_collection": false,
"is_required": true,
"group_id": 0,
"group_name": "",
"dictionary_id": 28732849
}
]
"description": "string",
"dictionary_id": 0,
"group_id": 0,
"group_name": "string",
"id": 0,
"is_aspect": true,
"is_collection": true,
"is_required": true,
"name": "string",
"type": "string"
}
]
}`,
@@ -130,17 +123,6 @@ func TestGetCategoryAttributes(t *testing.T) {
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.Result) != len(test.params.CategoryId) {
t.Errorf("Length of categories in request and response are not equal")
}
if len(resp.Result) > 0 {
if resp.Result[0].CategoryId != test.params.CategoryId[0] {
t.Errorf("Category ids in request and response are not equal")
}
}
}
}
}
@@ -158,33 +140,23 @@ func TestGetAttributeDictionary(t *testing.T) {
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetAttributeDictionaryParams{
AttributeId: 10096,
CategoryId: 17028968,
LastValueId: 0,
Limit: 3,
AttributeId: 123456,
CategoryId: 12,
Language: English,
LastValueId: 1,
Limit: 5,
TypeId: 6,
},
`{
"has_next": true,
"result": [
{
"id": 61571,
"value": "белый",
"info": "",
"picture": ""
},
{
"id": 61572,
"value": "прозрачный",
"info": "",
"picture": ""
},
{
"id": 61573,
"value": "бежевый",
"info": "",
"picture": ""
"id": 0,
"info": "string",
"picture": "string",
"value": "string"
}
],
"has_next": true
]
}`,
},
// Test No Client-Id or Api-Key

View File

@@ -128,7 +128,7 @@ type ProductDetails struct {
BuyboxPrice string `json:"buybox_price"`
// Category identifier
CategoryId int64 `json:"category_id"`
DescriptionCategoryId int64 `json:"description_category_id"`
// Marketing color
ColorImage string `json:"color_image"`
@@ -736,7 +736,7 @@ type CreateOrUpdateProductItem struct {
Barcode string `json:"barcode"`
// Category identifier
CategoryId int64 `json:"category_id"`
DescriptionCategoryId int64 `json:"description_category_id"`
// Marketing color.
//
@@ -1378,7 +1378,7 @@ type GetDescriptionOfProductResult struct {
Barcode string `json:"barcode"`
// Category identifier
CategoryId int64 `json:"category_id"`
DescriptionCategoryId int64 `json:"description_category_id"`
// Marketing color
ColorImage string `json:"color_image"`

View File

@@ -124,7 +124,7 @@ func TestGetProductDetails(t *testing.T) {
"7533900005"
],
"buybox_price": "",
"category_id": 17038062,
"description_category_id": 17038062,
"created_at": "2021-10-21T15:48:03.529178Z",
"images": [
"https://cdn1.ozone.ru/s3/multimedia-5/6088931525.jpg",
@@ -286,7 +286,7 @@ func TestGetProductDetails(t *testing.T) {
if resp.Result.OfferId == "" {
t.Errorf("Offer id cannot be empty")
}
if resp.Result.CategoryId == 0 {
if resp.Result.DescriptionCategoryId == 0 {
t.Errorf("Category id cannot be 0")
}
if resp.Result.CurrencyCode == "" {
@@ -658,21 +658,21 @@ func TestCreateOrUpdateProduct(t *testing.T) {
},
},
},
Barcode: "112772873170",
CategoryId: 17033876,
CurrencyCode: "RUB",
Depth: 10,
DimensionUnit: "mm",
Height: 250,
Name: "Комплект защитных плёнок для X3 NFC. Темный хлопок",
OfferId: "143210608",
OldPrice: "1100",
PremiumPrice: "900",
Price: "1000",
VAT: "0.1",
Weight: 100,
WeightUnit: "g",
Width: 150,
Barcode: "112772873170",
DescriptionCategoryId: 17033876,
CurrencyCode: "RUB",
Depth: 10,
DimensionUnit: "mm",
Height: 250,
Name: "Комплект защитных плёнок для X3 NFC. Темный хлопок",
OfferId: "143210608",
OldPrice: "1100",
PremiumPrice: "900",
Price: "1000",
VAT: "0.1",
Weight: 100,
WeightUnit: "g",
Width: 150,
},
},
},
@@ -1339,7 +1339,7 @@ func TestListProductsByIDs(t *testing.T) {
"7533900005"
],
"buybox_price": "",
"category_id": 93726157,
"description_category_id": 93726157,
"created_at": "2021-06-03T03:40:05.871465Z",
"images": [],
"has_discounted_item": true,
@@ -1536,7 +1536,7 @@ func TestGetDescriptionOfProduct(t *testing.T) {
{
"id": 213761435,
"barcode": "",
"category_id": 17038062,
"description_category_id": 17038062,
"name": "Пленка защитная для Xiaomi Redmi Note 10 Pro 5G",
"offer_id": "21470",
"height": 10,