public void ProductVariantUpdateSKU() { //Create API Proxy. var proxy = CreateApiProxy(); //Get Product Variants by Product. var res2 = proxy.ProductVariantsFindByProduct(TestConstants.TestProductBvin); var listMatchingOptions = new List <VariantOptionDataDTO>(); foreach (var item in res2.Content.First().Selections) { var variantOption = new VariantOptionDataDTO { ChoiceId = item.OptionBvin, ChoiceItemId = item.SelectionData }; listMatchingOptions.Add(variantOption); } //Update SKU for the Product Variant. var productvariant = new ProductVariantSkuUpdateDTO { ProductBvin = TestConstants.TestProductBvin, Sku = TestConstants.TestProduct1Sku, MatchingOptions = listMatchingOptions }; var updateResponse = proxy.ProductVariantUpdateSku(productvariant); CheckErrors(updateResponse); Assert.IsTrue(updateResponse.Content); }
/// <summary> /// Allows the REST API to update the SKU for a specific variant in a product /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. The first parameter found in the URL is the /// product ID (bvin). /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the ProductVariantSkuUpdateDTO object</param> /// <returns>Boolean - Serialized (JSON) version of the boolean ApiResponse</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var bvin = FirstParameter(parameters); var response = new ApiResponse <bool>(); ProductVariantSkuUpdateDTO postedItem = null; try { postedItem = Json.ObjectFromJson <ProductVariantSkuUpdateDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } // locate the existing product var existing = HccApp.CatalogServices.Products.Find(bvin); // only proceed if the product is found in the catalog if (existing != null && existing.Bvin != string.Empty) { // iterate through each variant in the existing product foreach (var variant in existing.Variants) { // in order to proceed... // the selections in the existing variant must match the options posted in the API call if (SelectionDataMatches(variant.Selections, postedItem.MatchingOptions)) { // update the variant with the new SKU variant.Sku = postedItem.Sku; // update the existing product in the catalog HccApp.CatalogServices.Products.Update(existing); // the update was successful response.Content = true; break; } } } data = Json.ObjectToJson(response); return(data); }