コード例 #1
0
        /// <summary>
        /// Updates the configuration of an extra attribute for the product specified in the request.
        /// <example>
        ///  <code>
        /// var result = ProductExtraFactory.UpdateExtra(handler : handler,  productExtra :  productExtra,  productCode :  productCode,  attributeFQN :  attributeFQN,  responseFields :  responseFields,  dataViewMode: dataViewMode,  expectedCode: expectedCode, successCode: successCode);
        /// var optionalCasting = ConvertClass<ProductExtra/>(result);
        /// return optionalCasting;
        ///  </code>
        /// </example>
        /// </summary>
        public static Mozu.Api.Contracts.ProductAdmin.ProductExtra UpdateExtra(ServiceClientMessageHandler handler,
                                                                               Mozu.Api.Contracts.ProductAdmin.ProductExtra productExtra, string productCode, string attributeFQN, string responseFields = null, DataViewMode dataViewMode = DataViewMode.Live,
                                                                               HttpStatusCode expectedCode = HttpStatusCode.OK, HttpStatusCode successCode = HttpStatusCode.OK)
        {
            SetSdKparameters();
            var currentClassName  = System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.Name;
            var currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            Debug.WriteLine(currentMethodName + '.' + currentMethodName);
            var apiClient = Mozu.Api.Clients.Commerce.Catalog.Admin.Products.ProductExtraClient.UpdateExtraClient(
                productExtra:  productExtra, productCode:  productCode, attributeFQN:  attributeFQN, responseFields:  responseFields, dataViewMode: dataViewMode);

            try
            {
                apiClient.WithContext(handler.ApiContext).Execute();
            }
            catch (ApiException ex)
            {
                // Custom error handling for test cases can be placed here
                Exception customException = TestFailException.GetCustomTestException(ex, currentClassName, currentMethodName, expectedCode);
                if (customException != null)
                {
                    throw customException;
                }
                return(null);
            }
            return(ResponseMessageFactory.CheckResponseCodes(apiClient.HttpResponse.StatusCode, expectedCode, successCode)
                                         ? (apiClient.Result())
                                         : null);
        }
コード例 #2
0
        public virtual Mozu.Api.Contracts.ProductAdmin.ProductExtra UpdateExtra(Mozu.Api.Contracts.ProductAdmin.ProductExtra productExtra, string productCode, string attributeFQN, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.ProductAdmin.ProductExtra> response;
            var client = Mozu.Api.Clients.Commerce.Catalog.Admin.Products.ProductExtraClient.UpdateExtraClient(_dataViewMode, productExtra, productCode, attributeFQN, responseFields);

            client.WithContext(_apiContext);
            response = client.Execute();
            return(response.Result());
        }
        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);
        }
コード例 #5
0
        /// <summary>
        /// Configure an extra attribute for the product specified in the request.
        /// </summary>
        /// <param name="productCode">Merchant-created code that uniquely identifies the product such as a SKU or item number. Once created, the product code is read-only.</param>
        /// <param name="responseFields">Use this field to include those fields which are not included by default.</param>
        /// <param name="productExtra">Properties of an extra attribute to defined for a product that is associated with a product type that uses the extra. Setting up extras for a product enables shopper-entered information, such as initials for a monogram.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.ProductAdmin.ProductExtra"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var productextra = new ProductExtra();
        ///   var productExtra = await productextra.AddExtraAsync(_dataViewMode,  productExtra,  productCode,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.ProductAdmin.ProductExtra> AddExtraAsync(Mozu.Api.Contracts.ProductAdmin.ProductExtra productExtra, string productCode, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.ProductAdmin.ProductExtra> response;
            var client = Mozu.Api.Clients.Commerce.Catalog.Admin.Products.ProductExtraClient.AddExtraClient(_dataViewMode, productExtra, productCode, responseFields);

            client.WithContext(_apiContext);
            response = await client.ExecuteAsync();

            return(await response.ResultAsync());
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributeFQN">Fully qualified name for an attribute.</param>
        /// <param name="productCode">The unique, user-defined product code of a product, used throughout  to reference and associate to a product.</param>
        /// <param name="responseFields">Filtering syntax appended to an API call to increase or decrease the amount of data returned inside a JSON object. This parameter should only be used to retrieve data. Attempting to update data using this parameter may cause data loss.</param>
        /// <param name="productExtra">Properties of an extra attribute to defined for a product that is associated with a product type that uses the extra. Setting up extras for a product enables shopper-entered information, such as initials for a monogram.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.ProductAdmin.ProductExtra"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var productextra = new ProductExtra();
        ///   var productExtra = await productextra.UpdateExtraAsync(_dataViewMode,  productExtra,  productCode,  attributeFQN,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.ProductAdmin.ProductExtra> UpdateExtraAsync(Mozu.Api.Contracts.ProductAdmin.ProductExtra productExtra, string productCode, string attributeFQN, string responseFields = null, CancellationToken ct = default(CancellationToken))
        {
            MozuClient <Mozu.Api.Contracts.ProductAdmin.ProductExtra> response;
            var client = Mozu.Api.Clients.Commerce.Catalog.Admin.Products.ProductExtraClient.UpdateExtraClient(_dataViewMode, productExtra, productCode, attributeFQN, responseFields);

            client.WithContext(_apiContext);
            response = await client.ExecuteAsync(ct).ConfigureAwait(false);

            return(await response.ResultAsync());
        }
コード例 #7
0
        /// <summary>
        /// Updates the configuration of an extra attribute for the product specified in the request.
        /// </summary>
        /// <param name="attributeFQN">The fully qualified name of the attribute, which is a user defined attribute identifier.</param>
        /// <param name="productCode">Merchant-created code that uniquely identifies the product such as a SKU or item number. Once created, the product code is read-only.</param>
        /// <param name="responseFields">Use this field to include those fields which are not included by default.</param>
        /// <param name="productExtra">Properties of an extra attribute to defined for a product that is associated with a product type that uses the extra. Setting up extras for a product enables shopper-entered information, such as initials for a monogram.</param>
        /// <returns>
        ///  <see cref="Mozu.Api.MozuClient" />{<see cref="Mozu.Api.Contracts.ProductAdmin.ProductExtra"/>}
        /// </returns>
        /// <example>
        /// <code>
        ///   var mozuClient=UpdateExtra(dataViewMode,  productExtra,  productCode,  attributeFQN,  responseFields);
        ///   var productExtraClient = mozuClient.WithBaseAddress(url).Execute().Result();
        /// </code>
        /// </example>
        public static MozuClient <Mozu.Api.Contracts.ProductAdmin.ProductExtra> UpdateExtraClient(DataViewMode dataViewMode, Mozu.Api.Contracts.ProductAdmin.ProductExtra productExtra, string productCode, string attributeFQN, string responseFields = null)
        {
            var          url        = Mozu.Api.Urls.Commerce.Catalog.Admin.Products.ProductExtraUrl.UpdateExtraUrl(productCode, attributeFQN, responseFields);
            const string verb       = "PUT";
            var          mozuClient = new MozuClient <Mozu.Api.Contracts.ProductAdmin.ProductExtra>()
                                      .WithVerb(verb).WithResourceUrl(url)
                                      .WithBody <Mozu.Api.Contracts.ProductAdmin.ProductExtra>(productExtra).WithHeader(Headers.X_VOL_DATAVIEW_MODE, dataViewMode.ToString())
            ;

            return(mozuClient);
        }