-
-
Notifications
You must be signed in to change notification settings - Fork 312
Product Variants
Joshua Harms edited this page Dec 20, 2023
·
1 revision
A product variant is a different version of a product, such as differing sizes or differing colors. Without product variants, you would have to treat the small, medium and large versions of a t-shirt as three separate products; product variants let you treat the small, medium and large versions of a t-shirt as variations of the same product.
var product = new Product()
{
Title = "Test Product Walter",
Vendor = "Burton",
BodyHtml = "<strong>Good snowboard!</strong>",
ProductType = "Snowboard",
Images = images,
//Make sure to give your product the correct variant option
Options = new List<ProductOption>
{
new ProductOption
{
Name = "Color"
}
},
//And then create a collection of variants or assign the "Variants" property
//to an already defined collection.
Variants = new List<ProductVariant>
{
new ProductVariant
{
Option1 = "Black",
},
new ProductVariant
{
Option1 = "Green",
},
}
};
var service = new ProductVariantService(myShopifyUrl, shopAccessToken);
var variant = await service.CreateAsync(productId, new ProductVariant()
{
Option1 = "blue",
Price = 123.45,
});
var service = new ProductVariantService(myShopifyUrl, shopAccessToken);
var variant = await service.GetAsync(variantId);
var service = new ProductVariantService(myShopifyUrl, shopAccessToken);
var variant = await service.UpdateAsync(variantId, new Variant()
{
Price = 543.21
});
var service = new ProductVariantService(myShopifyUrl, shopAccessToken);
var variants = await service.ListAsync(productId);
var service = new ProductVariantService(myShopifyUrl, shopAccessToken);
var count = await service.CountAsync(productId);
var service = new ProductVariantService(myShopifyUrl, shopAccessToken);
await service.DeleteAsync(productId, variantId);