add method for updating product characteristics
This commit is contained in:
		@@ -2126,3 +2126,59 @@ func (c Products) NumberOfSubsToProductAvailability(params *NumberOfSubsToProduc
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return resp, nil
 | 
						return resp, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateCharacteristicsParams struct {
 | 
				
			||||||
 | 
						// Products and characteristics to be updated
 | 
				
			||||||
 | 
						Items []UpdateCharacteristicsItem `json:"items"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateCharacteristicsItem struct {
 | 
				
			||||||
 | 
						// Product characteristics
 | 
				
			||||||
 | 
						Attributes []UpdateCharacteristicsItemAttribute `json:"attributes"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Product ID
 | 
				
			||||||
 | 
						OfferId string `json:"offer_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateCharacteristicsItemAttribute struct {
 | 
				
			||||||
 | 
						// Identifier of the characteristic that supports nested properties.
 | 
				
			||||||
 | 
						// Each of the nested characteristics can have multiple value variants
 | 
				
			||||||
 | 
						ComplexId int64 `json:"complex_id"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Characteristic identifier
 | 
				
			||||||
 | 
						Id int64 `json:"id"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Array of nested characteristic values
 | 
				
			||||||
 | 
						Values []UpdateCharacteristicsItemValue `json:"values"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateCharacteristicsItemValue struct {
 | 
				
			||||||
 | 
						// Characteristic identifier in the dictionary
 | 
				
			||||||
 | 
						DictionaryValueId int64 `json:"dictionary_value_id"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Product characteristic value
 | 
				
			||||||
 | 
						Value string `json:"value"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UpdateCharacteristicsResponse struct {
 | 
				
			||||||
 | 
						core.CommonResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Products update task code.
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// To check the update status, pass the received value to the `/v1/product/import/info` method
 | 
				
			||||||
 | 
						TaskId int64 `json:"task_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (c Products) UpdateCharacteristics(params *UpdateCharacteristicsParams) (*UpdateCharacteristicsResponse, error) {
 | 
				
			||||||
 | 
						url := "/v1/product/attributes/update"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp := &UpdateCharacteristicsResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						response.CopyCommonResponse(&resp.CommonResponse)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return resp, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2487,3 +2487,65 @@ func TestNumberOfSubsToProductAvailability(t *testing.T) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestUpdateCharacteristics(t *testing.T) {
 | 
				
			||||||
 | 
						t.Parallel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							statusCode int
 | 
				
			||||||
 | 
							headers    map[string]string
 | 
				
			||||||
 | 
							params     *UpdateCharacteristicsParams
 | 
				
			||||||
 | 
							response   string
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							// Test Ok
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								http.StatusOK,
 | 
				
			||||||
 | 
								map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
				
			||||||
 | 
								&UpdateCharacteristicsParams{
 | 
				
			||||||
 | 
									Items: []UpdateCharacteristicsItem{
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											Attributes: []UpdateCharacteristicsItemAttribute{
 | 
				
			||||||
 | 
												{
 | 
				
			||||||
 | 
													ComplexId: 0,
 | 
				
			||||||
 | 
													Id:        0,
 | 
				
			||||||
 | 
													Values: []UpdateCharacteristicsItemValue{
 | 
				
			||||||
 | 
														{
 | 
				
			||||||
 | 
															DictionaryValueId: 0,
 | 
				
			||||||
 | 
															Value:             "string",
 | 
				
			||||||
 | 
														},
 | 
				
			||||||
 | 
													},
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
											OfferId: "string",
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								`{
 | 
				
			||||||
 | 
									"task_id": 0
 | 
				
			||||||
 | 
								}`,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							// Test No Client-Id or Api-Key
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								http.StatusUnauthorized,
 | 
				
			||||||
 | 
								map[string]string{},
 | 
				
			||||||
 | 
								&UpdateCharacteristicsParams{},
 | 
				
			||||||
 | 
								`{
 | 
				
			||||||
 | 
									"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().UpdateCharacteristics(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