I'm creating some products, all of the same product type. I've created variants for each product because each product has 5 sizes which all have different prices. However, the size/price variations for each product are always the same. eg. Size 0 is $100, Size 1 is $120 etc.
Should I really be creating the same variants every time I create a product? I guess all the variants have to have different sku's (or do they?) but I'm wondering if there's a shortcut I'm missing out on.
You can make this easier by doing a small custom piece of code.
You can do this by creating a hidden master product, which holds the template for your standard variants.
Create one product, call it "MyProductType", with all the variants defined. You then create the rest of the products without variants, call them "MyProductType-MyProduct".
On the page where customers add to basket you could use both products. Basically grab the product itself, "MyProduct", and grab "MyProductType-MyProduct" by SKU. With that you can present "MyProduct", but with the variants from "MyProductType", which will include sizes and prices.
Basically you grab the price from the MyProductType and put it on a custom order line.
In Razor/.NET you could create a custom order line like so:
// Grab the actual product
var myProduct = Product.All().Single(x => x.Sku == "MyProduct" && x.ParentProductId == null);
// Grab the "template" variant
var myProductTypeVariant = Product.All().Single(x => x.Sku == "MyProductType" && x.VariantSku == "selectedSku")
// Grab the basket for the customer. We need it to associate the order line with.
var basket = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
// Create a custom order line with the SKU from the actual product,
// some made up variant SKU, and the price from the template product.
var orderLine = new OrderLine();
orderLine.OrderId = basket.OrderId;
orderLine.Sku = "MyProduct";
orderLine.VariantSku = "Size 0";
// Assuming only one price group
orderLine.Price = myProductTypeVariant.GetPrice(PriceGroups.All().Where(x => !x.Deleted).First()).Value;
orderLine.Save();
There's not really a way to accomplish with the XSLT API unless you write an extension yourself, which allows you to specify the price of the product.
Product variants
Hi
I'm creating some products, all of the same product type. I've created variants for each product because each product has 5 sizes which all have different prices. However, the size/price variations for each product are always the same. eg. Size 0 is $100, Size 1 is $120 etc.
Should I really be creating the same variants every time I create a product? I guess all the variants have to have different sku's (or do they?) but I'm wondering if there's a shortcut I'm missing out on.
Thanks in advance.
You can make this easier by doing a small custom piece of code.
You can do this by creating a hidden master product, which holds the template for your standard variants.
Create one product, call it "MyProductType", with all the variants defined. You then create the rest of the products without variants, call them "MyProductType-MyProduct".
On the page where customers add to basket you could use both products. Basically grab the product itself, "MyProduct", and grab "MyProductType-MyProduct" by SKU. With that you can present "MyProduct", but with the variants from "MyProductType", which will include sizes and prices.
Basically you grab the price from the MyProductType and put it on a custom order line.
In Razor/.NET you could create a custom order line like so:
There's not really a way to accomplish with the XSLT API unless you write an extension yourself, which allows you to specify the price of the product.
Cool, thanks!
is working on a reply...