Beispiel #1
0
        public async Task <IActionResult> UpdateProduct([FromRoute] int id, [FromBody] UpdateProductResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var product = _mapper.Map <UpdateProductResource, Product>(resource);
                product.ModifiedBy = _admin.Fullname;
                await _productService.UpdateProduct(id, product);

                return(Ok(new { message = "Məhsul yeniləndi" }));
            }
            catch (HttpException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a custom property on a Magento product
        /// </summary>
        /// <param name="magentoProduct">Magento product to update </param>
        /// <param name="categoryIds">Magento categories, required for updating</param>
        /// <param name="attrCode">Code of value to add</param>
        /// <param name="attrValue">Value to add</param>
        public void AddCustomAttributeToProduct(ProductResource magentoProduct, List <int> categoryIds, string attrCode, string attrValue)
        {
            var endpoint = UrlFormatter.MagentoCreateProductUrl();

            var client  = new RestClient(endpoint);
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", string.Format("Bearer {0}", AuthToken));
            request.AddHeader("Content-Type", "application/json");

            var customAttributes = new List <CustomAttributeRefResource>
            {
                new CustomAttributeRefResource {
                    attribute_code = ConfigReader.MagentoCategoryCode, value = categoryIds
                },
                new CustomAttributeRefResource {
                    attribute_code = attrCode, value = attrValue
                }
            };

            //Format update request body
            var updateProduct = new UpdateProductResource
            {
                product = new UpdateProductBodyResource
                {
                    id  = magentoProduct.id,
                    sku = magentoProduct.sku,
                    custom_attributes = customAttributes
                }
            };

            request.AddJsonBody(updateProduct);

            var response = client.Execute(request);

            //Ensure we get the right code
            CheckStatusCode(response.StatusCode);
        }