/// <summary> /// Allows you to populate the current product property object using a ProductPropertyDTO instance /// </summary> /// <param name="dto">An instance of the ProductProperty from the REST API</param> public void FromDto(ProductPropertyDTO dto) { if (dto == null) { return; } Choices.Clear(); if (dto.Choices != null) { foreach (var c in dto.Choices) { var pc = new ProductPropertyChoice(); pc.FromDto(c); Choices.Add(pc); } } CultureCode = dto.CultureCode; DefaultValue = dto.DefaultValue; DisplayName = dto.DisplayName; DisplayOnSite = dto.DisplayOnSite; DisplayToDropShipper = dto.DisplayToDropShipper; Id = dto.Id; PropertyName = dto.PropertyName; StoreId = dto.StoreId; TypeCode = (ProductPropertyType)(int)dto.TypeCode; LastUpdatedUtc = dto.LastUpdatedUtc; }
public void FromDto(ProductPropertyDTO dto) { if (dto == null) { return; } this.Choices.Clear(); if (dto.Choices != null) { foreach (ProductPropertyChoiceDTO c in dto.Choices) { ProductPropertyChoice pc = new ProductPropertyChoice(); pc.FromDto(c); this.Choices.Add(pc); } } this.CultureCode = dto.CultureCode; this.DefaultValue = dto.DefaultValue; this.DisplayName = dto.DisplayName; this.DisplayOnSite = dto.DisplayOnSite; this.DisplayToDropShipper = dto.DisplayToDropShipper; this.Id = dto.Id; this.PropertyName = dto.PropertyName; this.StoreId = dto.StoreId; this.TypeCode = (ProductPropertyType)((int)dto.TypeCode); this.LastUpdatedUtc = dto.LastUpdatedUtc; }
public void ProductProperty_CreateUpdateDelete() { //Create API Proxy. var proxy = CreateApiProxy(); //Create Product Property var productProperty = new ProductPropertyDTO { DisplayName = "TestCase Property", DefaultValue = "test", PropertyName = "TestCaseProperty", TypeCode = ProductPropertyTypeDTO.TextField, StoreId = 1 }; var createResponse = proxy.ProductPropertiesCreate(productProperty); CheckErrors(createResponse); Assert.IsFalse(createResponse.Content.Id == 0); //Find Product Property var findResponse = proxy.ProductPropertiesFind(createResponse.Content.Id); CheckErrors(findResponse); Assert.AreEqual(createResponse.Content.DisplayName, findResponse.Content.DisplayName); Assert.AreEqual(createResponse.Content.PropertyName, findResponse.Content.PropertyName); //Update product property createResponse.Content.DefaultValue = "testupdate"; var updateResponse = proxy.ProductPropertiesUpdate(createResponse.Content); CheckErrors(updateResponse); Assert.AreEqual(createResponse.Content.DefaultValue, updateResponse.Content.DefaultValue); //Set Product properties value var setValueResponse = proxy.ProductPropertiesSetValueForProduct(updateResponse.Content.Id, TestConstants.TestProductBvin, "settestvalue", 0); CheckErrors(setValueResponse); Assert.IsTrue(setValueResponse.Content); //Delete Product properties var deleteResponse = proxy.ProductPropertiesDelete(createResponse.Content.Id); CheckErrors(deleteResponse); Assert.IsTrue(deleteResponse.Content); }
//DTO public ProductPropertyDTO ToDto() { ProductPropertyDTO dto = new ProductPropertyDTO(); foreach (ProductPropertyChoice c in this.Choices) { dto.Choices.Add(c.ToDto()); } dto.CultureCode = this.CultureCode; dto.DefaultValue = this.DefaultValue; dto.DisplayName = this.DisplayName; dto.DisplayOnSite = this.DisplayOnSite; dto.DisplayToDropShipper = this.DisplayToDropShipper; dto.Id = this.Id; dto.PropertyName = this.PropertyName; dto.StoreId = this.StoreId; dto.TypeCode = (ProductPropertyTypeDTO)((int)this.TypeCode); dto.LastUpdatedUtc = this.LastUpdatedUtc; return(dto); }
/// <summary> /// Allows you to convert the current product property object to the DTO equivalent for use with the REST API /// </summary> /// <returns>A new instance of ProductPropertyDTO</returns> public ProductPropertyDTO ToDto() { var dto = new ProductPropertyDTO(); foreach (var c in Choices) { dto.Choices.Add(c.ToDto()); } dto.CultureCode = CultureCode; dto.DefaultValue = DefaultValue; dto.DisplayName = DisplayName; dto.DisplayOnSite = DisplayOnSite; dto.DisplayToDropShipper = DisplayToDropShipper; dto.Id = Id; dto.PropertyName = PropertyName; dto.StoreId = StoreId; dto.TypeCode = (ProductPropertyTypeDTO)(int)TypeCode; dto.LastUpdatedUtc = LastUpdatedUtc; return(dto); }
/// <summary> /// Allows the REST API to create or update a product property /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the product property ID (bvin) and that this is an update, otherwise it assumes /// to create a product property. /// </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 ProductPropertyDTO object</param> /// <returns>ProductPropertyDTO - Serialized (JSON) version of the ProductProperty</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var ids = FirstParameter(parameters); long id = 0; long.TryParse(ids, out id); var isValueSetRequest = GetParameterByIndex(1, parameters); if (isValueSetRequest.Trim().ToLowerInvariant() == "valuesforproduct") { // Set Property value Request var response = new ApiResponse <bool>(); var productBvin = GetParameterByIndex(2, parameters); var propertyValue = postdata; var property = HccApp.CatalogServices.ProductProperties.Find(id); response.Content = HccApp.CatalogServices.ProductPropertyValues.SetPropertyValue(productBvin, property, propertyValue); data = Json.ObjectToJson(response); } else { // Regular Create or Update Request var response = new ApiResponse <ProductPropertyDTO>(); ProductPropertyDTO postedItem = null; try { postedItem = Json.ObjectFromJson <ProductPropertyDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } var item = new ProductProperty(); item.FromDto(postedItem); // Check for existing and create base property var existing = HccApp.CatalogServices.ProductProperties.FindByName(item.DisplayName); if (existing == null) { // Create HccApp.CatalogServices.ProductProperties.Create(item); id = item.Id; } else { // Update HccApp.CatalogServices.ProductProperties.Update(item); id = existing.Id; } var resultItem = HccApp.CatalogServices.ProductProperties.Find(id); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = Json.ObjectToJson(response); } return(data); }
public void ProductTypes_TestCreateAndFindAndDelete() { //Create API Proxy var proxy = CreateApiProxy(); //Create Product Type var productType = new ProductTypeDTO { ProductTypeName = "UnitTest Type", TemplateName = "TestTemplate", StoreId = 1, IsPermanent = true }; var createResponse = proxy.ProductTypesCreate(productType); CheckErrors(createResponse); Assert.IsFalse(string.IsNullOrEmpty(createResponse.Content.Bvin)); //Find Product Type by its unique identifier var findResponse = proxy.ProductTypesFind(createResponse.Content.Bvin); CheckErrors(findResponse); Assert.AreEqual(createResponse.Content.ProductTypeName, findResponse.Content.ProductTypeName); Assert.AreEqual(createResponse.Content.TemplateName, findResponse.Content.TemplateName); //Update Product Type createResponse.Content.IsPermanent = false; var updateResponse = proxy.ProductTypesUpdate(createResponse.Content); CheckErrors(updateResponse); Assert.AreEqual(createResponse.Content.IsPermanent, updateResponse.Content.IsPermanent); //Create Product Property var productProperty = new ProductPropertyDTO { DefaultValue = "5", DisplayName = "UnitTestTypeProperty", PropertyName = "UnitTestTypeProperty", StoreId = 1, TypeCode = ProductPropertyTypeDTO.TextField }; var propertyCreateResponse = proxy.ProductPropertiesCreate(productProperty); CheckErrors(propertyCreateResponse); Assert.IsFalse(propertyCreateResponse.Content.Id == 0); //Add Product Property to Product Type. var addPropertyResponse = proxy.ProductTypesAddProperty(createResponse.Content.Bvin, propertyCreateResponse.Content.Id, 1); Assert.IsTrue(addPropertyResponse.Content); //Remove Product Property from Product Type. var removePropertyResponse = proxy.ProductTypesRemoveProperty(createResponse.Content.Bvin, propertyCreateResponse.Content.Id); Assert.IsTrue(removePropertyResponse.Content); //Delete Product Type. var deleteResponse = proxy.ProductTypesDelete(createResponse.Content.Bvin); CheckErrors(deleteResponse); Assert.IsTrue(deleteResponse.Content); }
// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string ids = FirstParameter(parameters); long id = 0; long.TryParse(ids, out id); string isValueSetRequest = GetParameterByIndex(1, parameters); if (isValueSetRequest.Trim().ToLowerInvariant() == "valuesforproduct") { // Set Property value Request ApiResponse <bool> response = new ApiResponse <bool>(); string productBvin = GetParameterByIndex(2, parameters); string propertyValue = postdata; response.Content = MTApp.CatalogServices.ProductPropertyValues.SetPropertyValue(productBvin, id, propertyValue); data = MerchantTribe.Web.Json.ObjectToJson(response); } else { // Regular Create or Update Request ApiResponse <ProductPropertyDTO> response = new ApiResponse <ProductPropertyDTO>(); ProductPropertyDTO postedItem = null; try { postedItem = MerchantTribe.Web.Json.ObjectFromJson <ProductPropertyDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(MerchantTribe.Web.Json.ObjectToJson(response)); } ProductProperty item = new ProductProperty(); item.FromDto(postedItem); // Check for existing and create base property ProductProperty existing = MTApp.CatalogServices.ProductProperties.FindByName(item.DisplayName); if (existing == null) { // Create MTApp.CatalogServices.ProductProperties.Create(item); id = item.Id; //// Merge Properties //foreach (ProductPropertyChoice ppc in item.Choices) //{ // ppc.PropertyId = item.Id; // ProductPropertyChoice.Insert(ppc); //} } else { // Update MTApp.CatalogServices.ProductProperties.Update(item); id = existing.Id; //// Merge Properties //if (item.Choices.Count > 0) //{ // List<ProductPropertyChoice> existingChoices = ProductPropertyChoice.FindByPropertyID(existing.Id); // foreach (ProductPropertyChoice newChoice in item.Choices) // { // var existCount = existingChoices.Where(y => y.Id == newChoice.Id).Count(); // if (existCount < 1) // { // newChoice.PropertyId = existing.Id; // ProductPropertyChoice.Insert(newChoice); // } // else // { // ProductPropertyChoice.Update(newChoice); // } // } //} } ProductProperty resultItem = MTApp.CatalogServices.ProductProperties.Find(id); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = MerchantTribe.Web.Json.ObjectToJson(response); } return(data); }