public void Exercise_10_1_Get_Product_Type() { //Create a new ProductType resource var productTypeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.ProductTypeResource(_apiContext); //Now that you're more familiar with using the Mozu API documentation, I'll just give you the link for the ProductType JSON information //http://developer.mozu.com/content/api/APIResources/commerce/commerce.catalog/commerce.catalog.admin.attributedefinition.producttypes.htm //Add Your Code: //Get list of attributes with max page size and starting index at the beginning var productTypes = productTypeResource.GetProductTypesAsync(startIndex: 0, pageSize: 200).Result; //Add Your Code: //Write total count of producttypes to output window System.Diagnostics.Debug.WriteLine(string.Format("Product Type Total Count: {0}", productTypes.TotalCount)); //Add Your Code: //Get product type filtered by name var typePurse = productTypeResource.GetProductTypesAsync(filter: "Name sw 'Purse'").Result.Items[0]; //Loop through List<AttributeInProductType> foreach (var option in typePurse.Options) { //Loop through List<AttributeVocabularyValueInProductType> foreach (var value in option.VocabularyValues) { //Add Your Code: //Write vocabulary values to output window System.Diagnostics.Debug.WriteLine(string.Format("Product Type [{0}]: Value({1}) StringValue({2})", typePurse.Name, value.Value, value.VocabularyValueDetail.Content.StringValue)); } } }
public void Exercise_10_1_Get_Product_Type() { //Create a new ProductType resource var productTypeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.ProductTypeResource(_apiContext); //Now that you're more familiar with using the Mozu API documentation, I'll just give you the link for the ProductType JSON information //http://developer.mozu.com/content/api/APIResources/commerce/commerce.catalog/commerce.catalog.admin.attributedefinition.producttypes.htm //Add Your Code: //Get list of attributes with max page size and starting index at the beginning var productTypes = productTypeResource.GetProductTypesAsync(startIndex: 0, pageSize: 200).Result; //Add Your Code: //Write total count of producttypes to output window System.Diagnostics.Debug.WriteLine(string.Format("Product Type Total Count: {0}", productTypes.TotalCount)); //Add Your Code: //Get product type filtered by name var typePurse = productTypeResource.GetProductTypesAsync(filter: "name sw 'Purse'").Result.Items[0]; //Loop through List<AttributeInProductType> foreach (var option in typePurse.Options) { //Loop through List<AttributeVocabularyValueInProductType> foreach (var value in option.VocabularyValues) { //Add Your Code: //Write vocabulary values to output window System.Diagnostics.Debug.WriteLine(string.Format("Product Type [{0}]: Value({1}) StringValue({2})", typePurse.Name, value.Value, value.VocabularyValueDetail.Content.StringValue)); } } }
public void Exercise_11_2_Create_New_Product() { var productCode = "LUC-BAG-011"; //Grouped our necessary resources for defining aspects of the new product var productResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.ProductResource(_apiContext); var productTypeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.ProductTypeResource(_apiContext); var categoryResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.CategoryResource(_apiContext); var productAttributeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.AttributeResource(_apiContext); //Wrap the Delete call in a try/catch in case the product doesn't exist try { productResource.DeleteProductAsync(productCode).Wait(); } catch(Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } //Retrieve the objects for later use when constructing our product var monogram = productAttributeResource.GetAttributeAsync("tenant~monogram").Result; var purseSize = productAttributeResource.GetAttributeAsync("tenant~purse-size").Result; var typePurse = productTypeResource.GetProductTypesAsync(filter: "Name eq 'Purse'").Result; var bagCategory = categoryResource.GetCategoryAsync(2).Result; Assert.IsNotNull(monogram); Assert.IsNotNull(purseSize); Assert.IsNotNull(typePurse); Assert.IsNotNull(bagCategory); //Define the monogram as a ProductExtra to use when defining the Product var monogramContract = new Mozu.Api.Contracts.ProductAdmin.ProductExtra() { AttributeFQN = monogram.AttributeFQN }; //The actual List<ProductExtra> object added to the Product Contract var productExtraList = new List<Mozu.Api.Contracts.ProductAdmin.ProductExtra>() { monogramContract }; //Construct a List<ProductOptionValue> using the purse-size Attribute Values var purseSizeValuesList = new List<Mozu.Api.Contracts.ProductAdmin.ProductOptionValue>(); //Use this option to catch each Value we want to add for this Product var purseSizeOptionValue = new Mozu.Api.Contracts.ProductAdmin.ProductOptionValue(); //Include only the values specified in the if-clause within the foreach loop foreach(var value in purseSize.VocabularyValues) { //If we wanted to include all sizes, we would remove this if-clause if (value.Content.StringValue.ToLower() == "petite" || value.Content.StringValue.ToLower() == "classic") { //We instantiate a new object each time to avoid reference errors purseSizeOptionValue = new Mozu.Api.Contracts.ProductAdmin.ProductOptionValue(); purseSizeOptionValue.AttributeVocabularyValueDetail = value; purseSizeOptionValue.Value = value.Value; purseSizeValuesList.Add(purseSizeOptionValue); } } //Define the purse-size as a ProductOption to use when defining the Product -- we use the purseSizeValuesList to add Values for the ProdcutOption var purseSizeContract = new Mozu.Api.Contracts.ProductAdmin.ProductOption() { AttributeFQN = purseSize.AttributeFQN, Values = purseSizeValuesList }; //The actual Option object added to the Product Contract var productOptionList = new List<Mozu.Api.Contracts.ProductAdmin.ProductOption>() { purseSizeContract }; //Construct a Product contract to submit to the API var product = new Mozu.Api.Contracts.ProductAdmin.Product() { Content = new Mozu.Api.Contracts.ProductAdmin.ProductLocalizedContent() { ProductName = "Api Handbag", LocaleCode = "en-US" }, FulfillmentTypesSupported = new List<string>() { "DirectShip" }, HasConfigurableOptions = true, IsTaxable = true, Extras = productExtraList, Options = productOptionList, PublishingInfo = new Mozu.Api.Contracts.ProductAdmin.ProductPublishingInfo() { PublishedState = "Live" }, PackageHeight = new Mozu.Api.Contracts.Core.Measurement() { Unit = "in", Value = 7 }, PackageWidth = new Mozu.Api.Contracts.Core.Measurement() { Unit = "in", Value = 3 }, PackageLength = new Mozu.Api.Contracts.Core.Measurement() { Unit = "in", Value = 10.25m }, PackageWeight = new Mozu.Api.Contracts.Core.Measurement() { Unit = "lbs", Value = 2.25m }, Price = new Mozu.Api.Contracts.ProductAdmin.ProductPrice() { Price = 175m, SalePrice = 125m }, ProductUsage = "Configurable", ProductCode = productCode, //Add the ProductType "purse" that we retrieved earlier ProductTypeId = typePurse.Items.FirstOrDefault().Id, HasStandAloneOptions = false, InventoryInfo = new Mozu.Api.Contracts.ProductAdmin.ProductInventoryInfo() { ManageStock = true, OutOfStockBehavior = "DisplayMessage" }, MasterCatalogId = 1, ProductInCatalogs = new List<Mozu.Api.Contracts.ProductAdmin.ProductInCatalogInfo>() { new Mozu.Api.Contracts.ProductAdmin.ProductInCatalogInfo() { CatalogId = 1, IsActive = true, IsContentOverridden = false, IsPriceOverridden = false, IsseoContentOverridden = false, Content = new Mozu.Api.Contracts.ProductAdmin.ProductLocalizedContent() { LocaleCode = "en-US", ProductName = "Api Handbag", }, ProductCategories = new List<Mozu.Api.Contracts.ProductAdmin.ProductCategory>() { new Mozu.Api.Contracts.ProductAdmin.ProductCategory() { //Add the product to the "bag" category using what we retrieved earlier CategoryId = bagCategory.Id.Value, } } } }, }; //The API call used to add a new product var newProduct = productResource.AddProductAsync(product).Result; var variationResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Products.ProductVariationResource(_apiContext); }
public void Exercise_11_2_Create_New_Product() { var productCode = "LUC-BAG-011"; //Grouped our necessary resources for defining aspects of the new product var productResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.ProductResource(_apiContext); var productTypeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.ProductTypeResource(_apiContext); var categoryResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.CategoryResource(_apiContext); var productAttributeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.AttributeResource(_apiContext); //Wrap the Delete call in a try/catch in case the product doesn't exist try { productResource.DeleteProductAsync(productCode).Wait(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } //Retrieve the objects for later use when constructing our product var monogram = productAttributeResource.GetAttributeAsync("tenant~monogram").Result; var purseSize = productAttributeResource.GetAttributeAsync("tenant~purse-size").Result; var typePurse = productTypeResource.GetProductTypesAsync(filter: "Name eq 'Purse'").Result; var bagCategory = categoryResource.GetCategoryAsync(2).Result; Assert.IsNotNull(monogram); Assert.IsNotNull(purseSize); Assert.IsNotNull(typePurse); Assert.IsNotNull(bagCategory); //Define the monogram as a ProductExtra to use when defining the Product var monogramContract = new Mozu.Api.Contracts.ProductAdmin.ProductExtra() { AttributeFQN = monogram.AttributeFQN }; //The actual List<ProductExtra> object added to the Product Contract var productExtraList = new List <Mozu.Api.Contracts.ProductAdmin.ProductExtra>() { monogramContract }; //Construct a List<ProductOptionValue> using the purse-size Attribute Values var purseSizeValuesList = new List <Mozu.Api.Contracts.ProductAdmin.ProductOptionValue>(); //Use this option to catch each Value we want to add for this Product var purseSizeOptionValue = new Mozu.Api.Contracts.ProductAdmin.ProductOptionValue(); //Include only the values specified in the if-clause within the foreach loop foreach (var value in purseSize.VocabularyValues) { //If we wanted to include all sizes, we would remove this if-clause if (value.Content.StringValue.ToLower() == "petite" || value.Content.StringValue.ToLower() == "classic") { //We instantiate a new object each time to avoid reference errors purseSizeOptionValue = new Mozu.Api.Contracts.ProductAdmin.ProductOptionValue(); purseSizeOptionValue.AttributeVocabularyValueDetail = value; purseSizeOptionValue.Value = value.Value; purseSizeValuesList.Add(purseSizeOptionValue); } } //Define the purse-size as a ProductOption to use when defining the Product -- we use the purseSizeValuesList to add Values for the ProdcutOption var purseSizeContract = new Mozu.Api.Contracts.ProductAdmin.ProductOption() { AttributeFQN = purseSize.AttributeFQN, Values = purseSizeValuesList }; //The actual Option object added to the Product Contract var productOptionList = new List <Mozu.Api.Contracts.ProductAdmin.ProductOption>() { purseSizeContract }; //Construct a Product contract to submit to the API var product = new Mozu.Api.Contracts.ProductAdmin.Product() { Content = new Mozu.Api.Contracts.ProductAdmin.ProductLocalizedContent() { ProductName = "Api Handbag", LocaleCode = "en-US" }, FulfillmentTypesSupported = new List <string>() { "DirectShip" }, HasConfigurableOptions = true, IsTaxable = true, Extras = productExtraList, Options = productOptionList, PublishingInfo = new Mozu.Api.Contracts.ProductAdmin.ProductPublishingInfo() { PublishedState = "Live" }, PackageHeight = new Mozu.Api.Contracts.Core.Measurement() { Unit = "in", Value = 7 }, PackageWidth = new Mozu.Api.Contracts.Core.Measurement() { Unit = "in", Value = 3 }, PackageLength = new Mozu.Api.Contracts.Core.Measurement() { Unit = "in", Value = 10.25m }, PackageWeight = new Mozu.Api.Contracts.Core.Measurement() { Unit = "lbs", Value = 2.25m }, Price = new Mozu.Api.Contracts.ProductAdmin.ProductPrice() { Price = 175m, SalePrice = 125m }, ProductUsage = "Configurable", ProductCode = productCode, //Add the ProductType "purse" that we retrieved earlier ProductTypeId = typePurse.Items.FirstOrDefault().Id, HasStandAloneOptions = false, InventoryInfo = new Mozu.Api.Contracts.ProductAdmin.ProductInventoryInfo() { ManageStock = true, OutOfStockBehavior = "DisplayMessage" }, MasterCatalogId = 1, ProductInCatalogs = new List <Mozu.Api.Contracts.ProductAdmin.ProductInCatalogInfo>() { new Mozu.Api.Contracts.ProductAdmin.ProductInCatalogInfo() { CatalogId = 1, IsActive = true, IsContentOverridden = false, IsPriceOverridden = false, IsseoContentOverridden = false, Content = new Mozu.Api.Contracts.ProductAdmin.ProductLocalizedContent() { LocaleCode = "en-US", ProductName = "Api Handbag", }, ProductCategories = new List <Mozu.Api.Contracts.ProductAdmin.ProductCategory>() { new Mozu.Api.Contracts.ProductAdmin.ProductCategory() { //Add the product to the "bag" category using what we retrieved earlier CategoryId = bagCategory.Id.Value, } } } }, }; //The API call used to add a new product var newProduct = productResource.AddProductAsync(product).Result; var variationResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Products.ProductVariationResource(_apiContext); }
public void Exercise_10_2_Update_ProductTypes() { #region Add "Monogram" as an Extra //Create a new ProductType resource var producttypeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.ProductTypeResource(_apiContext); //Add Your Code: //Get product type filtered by name var typePurse = (producttypeResource.GetProductTypesAsync(filter: "name sw 'purse'").Result).Items[0]; //Create an Attribute resource var productAttributeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.AttributeResource(_apiContext); //In case you've forgotten about Product Attributes: //http://developer.mozu.com/content/api/APIResources/commerce/commerce.catalog/commerce.catalog.admin.attributedefinition.attributes.htm //Add Your Code: //Get a monogram attribute var attrMonogram = productAttributeResource.GetAttributeAsync("tenant~monogram").Result; //Add Your Code: //Create new object defining new extra var attributeInProductTypeMonogram = new Mozu.Api.Contracts.ProductAdmin.AttributeInProductType() { AttributeDetail = attrMonogram, AttributeFQN = attrMonogram.AttributeFQN, }; //Test if the Extra already exists if (typePurse.Extras.Find(x => x.AttributeFQN == "tenant~monogram") == null) { //Add Your Code: //Update product type with new extra typePurse.Extras.Add(attributeInProductTypeMonogram); //Update product type var updatedTypeMonogram = producttypeResource.UpdateProductTypeAsync(typePurse, (int)typePurse.Id).Result; } #endregion #region Add "Purse-Size" as an Option //Add Your Code: //Get a purse size attribute var attrSize = productAttributeResource.GetAttributeAsync("tenant~purse-size").Result; //Add Your Code: //Create new object defining new option var attributeInProductTypePurse = new Mozu.Api.Contracts.ProductAdmin.AttributeInProductType() { AttributeDetail = attrSize, AttributeFQN = attrSize.AttributeFQN, VocabularyValues = new List <Mozu.Api.Contracts.ProductAdmin.AttributeVocabularyValueInProductType>(), Order = 0 }; //Add Your Code: //Exclude "Alta" from sizes var doNotInclude = "Alta"; //A variable needed for Option types to providea hierarchical order for each value var sortOrder = 0; foreach (var value in attrSize.VocabularyValues) { if (!doNotInclude.ToLower().Contains(value.Content.StringValue.ToLower())) { attributeInProductTypePurse.VocabularyValues.Add(new Mozu.Api.Contracts.ProductAdmin.AttributeVocabularyValueInProductType { Value = value.Value, VocabularyValueDetail = value, Order = sortOrder++ }); } } //Test if the Option already exists if (typePurse.Options.Find(x => x.AttributeFQN == "tenant~purse-size") == null) { //update product type with new option typePurse.Options.Add(attributeInProductTypePurse); //update product type var updatedTypePurse = producttypeResource.UpdateProductTypeAsync(typePurse, (int)typePurse.Id).Result; } #endregion }