update/6-october-2023 - New Categories' methods version (#43)
This commit is contained in:
@@ -12,17 +12,14 @@ type Categories struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetProductTreeParams struct {
|
type GetProductTreeParams struct {
|
||||||
// Category identifier
|
|
||||||
CategoryId int64 `json:"category_id"`
|
|
||||||
|
|
||||||
// Response language
|
// Response language
|
||||||
Language Language `json:"language" default:"DEFAULT"`
|
Language Language `json:"language"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetProductTreeResponse struct {
|
type GetProductTreeResponse struct {
|
||||||
core.CommonResponse
|
core.CommonResponse
|
||||||
|
|
||||||
// Category list
|
// Categories list
|
||||||
Result []GetProductTreeResult `json:"result"`
|
Result []GetProductTreeResult `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,19 +27,29 @@ type GetProductTreeResult struct {
|
|||||||
// Category identifier
|
// Category identifier
|
||||||
CategoryId int64 `json:"category_id"`
|
CategoryId int64 `json:"category_id"`
|
||||||
|
|
||||||
// Subcategory tree
|
|
||||||
Children []GetProductTreeResponse `json:"children"`
|
|
||||||
|
|
||||||
// Category name
|
// 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.
|
// Returns product categories in the tree view.
|
||||||
|
//
|
||||||
// New products can be created in the last level categories only.
|
// 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.
|
// 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
|
// We don't create new categories by user request.
|
||||||
func (c Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*GetProductTreeResponse, error) {
|
func (c *Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*GetProductTreeResponse, error) {
|
||||||
url := "/v2/category/tree"
|
url := "/v1/description-category/tree"
|
||||||
|
|
||||||
resp := &GetProductTreeResponse{}
|
resp := &GetProductTreeResponse{}
|
||||||
|
|
||||||
@@ -56,14 +63,14 @@ func (c Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*Ge
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetCategoryAttributesParams struct {
|
type GetCategoryAttributesParams struct {
|
||||||
// Filter by characteristics
|
|
||||||
AttributeType AttributeType `json:"attribute_type" default:"ALL"`
|
|
||||||
|
|
||||||
// Category identifier
|
// Category identifier
|
||||||
CategoryId []int64 `json:"category_id"`
|
CategoryId int64 `json:"category_id"`
|
||||||
|
|
||||||
// Response language
|
// Response language
|
||||||
Language Language `json:"language" default:"DEFAULT"`
|
Language Language `json:"language"`
|
||||||
|
|
||||||
|
// Product type identifier
|
||||||
|
TypeId int64 `json:"type_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetCategoryAttributesResponse struct {
|
type GetCategoryAttributesResponse struct {
|
||||||
@@ -74,19 +81,6 @@ type GetCategoryAttributesResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetCategoryAttributesResult 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
|
// Characteristic description
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
|
||||||
@@ -99,26 +93,29 @@ type GetCategoryAttributesResultAttribute struct {
|
|||||||
// Characteristics group name
|
// Characteristics group name
|
||||||
GroupName string `json:"group_name"`
|
GroupName string `json:"group_name"`
|
||||||
|
|
||||||
// Document generation task number
|
// Number of document generation task
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
|
||||||
// Indicates that the attribute is aspect. An aspect attribute is a characteristic that distinguishes products of the same model.
|
// 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:
|
// 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"`
|
IsAspect bool `json:"is_aspect"`
|
||||||
|
|
||||||
// Indicates that the characteristic is a set of values:
|
// 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"`
|
IsCollection bool `json:"is_collection"`
|
||||||
|
|
||||||
// Indicates that the characteristic is mandatory:
|
// 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"`
|
IsRequired bool `json:"is_required"`
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
@@ -128,15 +125,13 @@ type GetCategoryAttributesResultAttribute struct {
|
|||||||
Type string `json:"type"`
|
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.
|
// If the dictionary_id value is 0, there is no directory.
|
||||||
//
|
// If the value is different, there are directories.
|
||||||
// You can check whether the attribute has a nested directory by the `dictionary_id` parameter.
|
// Get them using the `/v1/description-category/attribute/values` method.
|
||||||
// The 0 value means there is no directory. If the value is different, then there are directories.
|
func (c *Categories) Attributes(ctx context.Context, params *GetCategoryAttributesParams) (*GetCategoryAttributesResponse, error) {
|
||||||
// You can get them using the `/v2/category/attribute/values` method
|
url := "/v1/description-category/attribute"
|
||||||
func (c Categories) Attributes(ctx context.Context, params *GetCategoryAttributesParams) (*GetCategoryAttributesResponse, error) {
|
|
||||||
url := "/v3/category/attribute"
|
|
||||||
|
|
||||||
resp := &GetCategoryAttributesResponse{}
|
resp := &GetCategoryAttributesResponse{}
|
||||||
|
|
||||||
@@ -157,39 +152,55 @@ type GetAttributeDictionaryParams struct {
|
|||||||
CategoryId int64 `json:"category_id"`
|
CategoryId int64 `json:"category_id"`
|
||||||
|
|
||||||
// Response language
|
// Response language
|
||||||
// The default language is Russian
|
Language Language `json:"language"`
|
||||||
Language Language `json:"language" default:"DEFAULT"`
|
|
||||||
|
|
||||||
|
// 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"`
|
LastValueId int64 `json:"last_value_id"`
|
||||||
|
|
||||||
// Number of values in the response:
|
// Number of values in the response:
|
||||||
// - maximum — 5000
|
//
|
||||||
// - minimum — 1
|
// - maximum—5000,
|
||||||
|
// - minimum—1.
|
||||||
Limit int64 `json:"limit"`
|
Limit int64 `json:"limit"`
|
||||||
|
|
||||||
|
// Product type identifier
|
||||||
|
TypeId int64 `json:"type_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetAttributeDictionaryResponse struct {
|
type GetAttributeDictionaryResponse struct {
|
||||||
core.CommonResponse
|
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"`
|
HasNext bool `json:"has_next"`
|
||||||
|
|
||||||
// Method result
|
// Characteristic values
|
||||||
Result []GetAttributeDictionaryResult `json:"result"`
|
Result []GetAttributeDictionaryResult `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetAttributeDictionaryResult struct {
|
type GetAttributeDictionaryResult struct {
|
||||||
|
// Characteristic value identifier
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
|
||||||
|
// Additional description
|
||||||
Info string `json:"info"`
|
Info string `json:"info"`
|
||||||
|
|
||||||
|
// Image link
|
||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
|
|
||||||
// Product characteristic value
|
// Product characteristic value
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can use the `/v3/category/attribute` method to check if an attribute has a nested directory.
|
// Returns characteristics value directory.
|
||||||
// If there are directories, get them using this method
|
//
|
||||||
func (c Categories) AttributesDictionary(ctx context.Context, params *GetAttributeDictionaryParams) (*GetAttributeDictionaryResponse, error) {
|
// To check if an attribute has a nested directory,
|
||||||
url := "/v2/category/attribute/values"
|
// 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{}
|
resp := &GetAttributeDictionaryResponse{}
|
||||||
|
|
||||||
|
|||||||
@@ -22,14 +22,17 @@ func TestGetProductTree(t *testing.T) {
|
|||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
&GetProductTreeParams{
|
&GetProductTreeParams{
|
||||||
CategoryId: 17034410,
|
Language: English,
|
||||||
},
|
},
|
||||||
`{
|
`{
|
||||||
"result": [
|
"result": [
|
||||||
{
|
{
|
||||||
"category_id": 17034410,
|
"category_id": 0,
|
||||||
"title": "Развивающие игрушки",
|
"category_name": "string",
|
||||||
"children": []
|
"children": [],
|
||||||
|
"disabled": true,
|
||||||
|
"type_id": 0,
|
||||||
|
"type_name": "string"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
@@ -58,14 +61,6 @@ func TestGetProductTree(t *testing.T) {
|
|||||||
if resp.StatusCode != test.statusCode {
|
if resp.StatusCode != test.statusCode {
|
||||||
t.Errorf("got wrong status code: got: %d, expected: %d", 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,
|
http.StatusOK,
|
||||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
&GetCategoryAttributesParams{
|
&GetCategoryAttributesParams{
|
||||||
CategoryId: []int64{17034410},
|
CategoryId: 12345,
|
||||||
|
Language: English,
|
||||||
|
TypeId: 2,
|
||||||
},
|
},
|
||||||
`{
|
`{
|
||||||
"result": [
|
"result": [
|
||||||
{
|
{
|
||||||
"category_id": 17034410,
|
"description": "string",
|
||||||
"attributes": [
|
"dictionary_id": 0,
|
||||||
{
|
|
||||||
"id": 85,
|
|
||||||
"name": "Бренд",
|
|
||||||
"description": "Укажите наименование бренда, под которым произведен товар. Если товар не имеет бренда, используйте значение \"Нет бренда\"",
|
|
||||||
"type": "String",
|
|
||||||
"is_collection": false,
|
|
||||||
"is_required": true,
|
|
||||||
"group_id": 0,
|
"group_id": 0,
|
||||||
"group_name": "",
|
"group_name": "string",
|
||||||
"dictionary_id": 28732849
|
"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 {
|
if resp.StatusCode != test.statusCode {
|
||||||
t.Errorf("got wrong status code: got: %d, expected: %d", 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,
|
http.StatusOK,
|
||||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
&GetAttributeDictionaryParams{
|
&GetAttributeDictionaryParams{
|
||||||
AttributeId: 10096,
|
AttributeId: 123456,
|
||||||
CategoryId: 17028968,
|
CategoryId: 12,
|
||||||
LastValueId: 0,
|
Language: English,
|
||||||
Limit: 3,
|
LastValueId: 1,
|
||||||
|
Limit: 5,
|
||||||
|
TypeId: 6,
|
||||||
},
|
},
|
||||||
`{
|
`{
|
||||||
|
"has_next": true,
|
||||||
"result": [
|
"result": [
|
||||||
{
|
{
|
||||||
"id": 61571,
|
"id": 0,
|
||||||
"value": "белый",
|
"info": "string",
|
||||||
"info": "",
|
"picture": "string",
|
||||||
"picture": ""
|
"value": "string"
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 61572,
|
|
||||||
"value": "прозрачный",
|
|
||||||
"info": "",
|
|
||||||
"picture": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 61573,
|
|
||||||
"value": "бежевый",
|
|
||||||
"info": "",
|
|
||||||
"picture": ""
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"has_next": true
|
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
// Test No Client-Id or Api-Key
|
// Test No Client-Id or Api-Key
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ type ProductDetails struct {
|
|||||||
BuyboxPrice string `json:"buybox_price"`
|
BuyboxPrice string `json:"buybox_price"`
|
||||||
|
|
||||||
// Category identifier
|
// Category identifier
|
||||||
CategoryId int64 `json:"category_id"`
|
DescriptionCategoryId int64 `json:"description_category_id"`
|
||||||
|
|
||||||
// Marketing color
|
// Marketing color
|
||||||
ColorImage string `json:"color_image"`
|
ColorImage string `json:"color_image"`
|
||||||
@@ -736,7 +736,7 @@ type CreateOrUpdateProductItem struct {
|
|||||||
Barcode string `json:"barcode"`
|
Barcode string `json:"barcode"`
|
||||||
|
|
||||||
// Category identifier
|
// Category identifier
|
||||||
CategoryId int64 `json:"category_id"`
|
DescriptionCategoryId int64 `json:"description_category_id"`
|
||||||
|
|
||||||
// Marketing color.
|
// Marketing color.
|
||||||
//
|
//
|
||||||
@@ -1378,7 +1378,7 @@ type GetDescriptionOfProductResult struct {
|
|||||||
Barcode string `json:"barcode"`
|
Barcode string `json:"barcode"`
|
||||||
|
|
||||||
// Category identifier
|
// Category identifier
|
||||||
CategoryId int64 `json:"category_id"`
|
DescriptionCategoryId int64 `json:"description_category_id"`
|
||||||
|
|
||||||
// Marketing color
|
// Marketing color
|
||||||
ColorImage string `json:"color_image"`
|
ColorImage string `json:"color_image"`
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func TestGetProductDetails(t *testing.T) {
|
|||||||
"7533900005"
|
"7533900005"
|
||||||
],
|
],
|
||||||
"buybox_price": "",
|
"buybox_price": "",
|
||||||
"category_id": 17038062,
|
"description_category_id": 17038062,
|
||||||
"created_at": "2021-10-21T15:48:03.529178Z",
|
"created_at": "2021-10-21T15:48:03.529178Z",
|
||||||
"images": [
|
"images": [
|
||||||
"https://cdn1.ozone.ru/s3/multimedia-5/6088931525.jpg",
|
"https://cdn1.ozone.ru/s3/multimedia-5/6088931525.jpg",
|
||||||
@@ -286,7 +286,7 @@ func TestGetProductDetails(t *testing.T) {
|
|||||||
if resp.Result.OfferId == "" {
|
if resp.Result.OfferId == "" {
|
||||||
t.Errorf("Offer id cannot be empty")
|
t.Errorf("Offer id cannot be empty")
|
||||||
}
|
}
|
||||||
if resp.Result.CategoryId == 0 {
|
if resp.Result.DescriptionCategoryId == 0 {
|
||||||
t.Errorf("Category id cannot be 0")
|
t.Errorf("Category id cannot be 0")
|
||||||
}
|
}
|
||||||
if resp.Result.CurrencyCode == "" {
|
if resp.Result.CurrencyCode == "" {
|
||||||
@@ -659,7 +659,7 @@ func TestCreateOrUpdateProduct(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Barcode: "112772873170",
|
Barcode: "112772873170",
|
||||||
CategoryId: 17033876,
|
DescriptionCategoryId: 17033876,
|
||||||
CurrencyCode: "RUB",
|
CurrencyCode: "RUB",
|
||||||
Depth: 10,
|
Depth: 10,
|
||||||
DimensionUnit: "mm",
|
DimensionUnit: "mm",
|
||||||
@@ -1339,7 +1339,7 @@ func TestListProductsByIDs(t *testing.T) {
|
|||||||
"7533900005"
|
"7533900005"
|
||||||
],
|
],
|
||||||
"buybox_price": "",
|
"buybox_price": "",
|
||||||
"category_id": 93726157,
|
"description_category_id": 93726157,
|
||||||
"created_at": "2021-06-03T03:40:05.871465Z",
|
"created_at": "2021-06-03T03:40:05.871465Z",
|
||||||
"images": [],
|
"images": [],
|
||||||
"has_discounted_item": true,
|
"has_discounted_item": true,
|
||||||
@@ -1536,7 +1536,7 @@ func TestGetDescriptionOfProduct(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"id": 213761435,
|
"id": 213761435,
|
||||||
"barcode": "",
|
"barcode": "",
|
||||||
"category_id": 17038062,
|
"description_category_id": 17038062,
|
||||||
"name": "Пленка защитная для Xiaomi Redmi Note 10 Pro 5G",
|
"name": "Пленка защитная для Xiaomi Redmi Note 10 Pro 5G",
|
||||||
"offer_id": "21470",
|
"offer_id": "21470",
|
||||||
"height": 10,
|
"height": 10,
|
||||||
|
|||||||
Reference in New Issue
Block a user