Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Danzig 32 posts 52 karma points
    May 10, 2011 @ 11:04
    Danzig
    0

    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.

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 10, 2011 @ 12:14
    Søren Spelling Lund
    0

    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.

  • Danzig 32 posts 52 karma points
    May 12, 2011 @ 10:12
    Danzig
    0

    Cool, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft