Skip to content

Instantly share code, notes, and snippets.

@Mozu-CS
Created March 17, 2016 14:11
Show Gist options
  • Save Mozu-CS/6f85132a1b1a0145d85d to your computer and use it in GitHub Desktop.
Save Mozu-CS/6f85132a1b1a0145d85d to your computer and use it in GitHub Desktop.
Add a product and alter the variations of the product
var productResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.ProductResource(_apiContext);
var productVariantResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Products.ProductVariationResource(_apiContext);
var product = new Mozu.Api.Contracts.ProductAdmin.Product()
{
Content = new ProductLocalizedContent()
{
ProductName = "Generated Product with variants",
},
ProductCode = "GEN-WITH-VARS-1",
Price = new ProductPrice()
{
Price = 12m
},
HasConfigurableOptions = true,
FulfillmentTypesSupported = new List<string>()
{
"DirectShip"
},
IsTaxable = true,
PackageHeight = new Mozu.Api.Contracts.Core.Measurement()
{
Unit = "in",
Value = 25
},
PackageLength = new Mozu.Api.Contracts.Core.Measurement()
{
Unit = "in",
Value = 25
},
PackageWidth = new Mozu.Api.Contracts.Core.Measurement()
{
Unit = "in",
Value = 25
},
PackageWeight = new Mozu.Api.Contracts.Core.Measurement()
{
Unit = "lbs",
Value = 10
},
InventoryInfo = new ProductInventoryInfo()
{
ManageStock = true,
OutOfStockBehavior = "DisplayMessage"
},
ProductUsage = "Configurable",
Options = new List<ProductOption>()
{
new ProductOption()
{
AttributeFQN = "tenant~size",
Values = new List<ProductOptionValue>()
{
new ProductOptionValue()
{
AttributeVocabularyValueDetail = new AttributeVocabularyValue()
{
Value = "L",
},
Value = "L"
},
new ProductOptionValue()
{
AttributeVocabularyValueDetail = new AttributeVocabularyValue()
{
Value = "M",
},
Value = "M"
}
}
}
},
ProductTypeId = 3
};
var addedProduct = productResource.AddProductAsync(product).Result;
var productVariationCollection = new Mozu.Api.Contracts.ProductAdmin.ProductVariationCollection()
{
Items = new List<ProductVariation>()
{
new ProductVariation()
{
IsActive = true,
VariationProductCode = "GEN-WITH-VARS-1-L",
Options = new List<ProductVariationOption>()
{
new ProductVariationOption()
{
AttributeFQN = "Tenant~size",
Value = "L"
}
}
},
new ProductVariation()
{
IsActive = true,
VariationProductCode = "GEN-WITH-VARS-1-M",
Options = new List<ProductVariationOption>()
{
new ProductVariationOption()
{
AttributeFQN = "Tenant~size",
Value = "M"
}
}
}
}
};
var returnedVariants = productVariantResource.UpdateProductVariationsAsync(productVariationCollection, "GEN-WITH-VARS-1").Result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment