Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ Master Language="C#" MasterPageFile="~/masterpages/uCommerce.master" AutoEventWireup="true" %>
- <asp:content ContentPlaceHolderId="PageContentPlaceholder" runat="server">
- <umbraco:Macro runat="server" language="cshtml">
- @using UCommerce.EntitiesV2;
- @using UCommerce.Runtime;
- @using UCommerce.Xslt;
- @{
- ProductCatalog catalog = ProductCatalog.All().Single(x => x.Name == "Hardware");
- // Check if we're dealing with a post
- if (!string.IsNullOrEmpty(Request["masterSku"]))
- {
- var basket = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
- // Add the master order line
- var mainProduct = Product.All().Single(x => x.Sku == Request["masterSku"] && x.ParentProductId == null);
- var masterOrderLine = basket.AddProduct(catalog, mainProduct, 1, false);
- // Mark the master as such
- masterOrderLine["master"] = true.ToString();
- // Save basket to generate ids for the order line
- basket.Save();
- // Add each product option to the basket
- foreach (string key in Request.Params.AllKeys.Where(x => x.Substring(0, 3) == "SKU"))
- {
- // Split the value of the posted skus to get both sku and variant sku (where applicable)
- // Example Intel-Core-CPU,i7-1.7
- string[] skus = Request[key].Split(',');
- string sku = skus[0];
- string variantSku = skus.Length == 2 ? skus[1] : null;
- // Add the option order line
- var optionProduct = Product.All().Single(x => x.Sku == sku && x.VariantSku == variantSku);
- OrderLine subOrderLine = basket.AddProduct(catalog, optionProduct, 1, false);
- // Add a reference back to the master order line
- subOrderLine["masterOrderlineId"] = masterOrderLine.OrderLineId.ToString();
- }
- basket.Save();
- // Execute the basket pipeline to recalculate basket
- Library.ExecuteBasketPipeline();
- }
- // Grab a price group to work from
- var priceGroup = ProductCatalog.All().Single(x => x.Name == "Hardware").PriceGroup;
- // Load MacBook Air product
- Product macbookAir = Product.All().Single(x => x.Sku == "Acer Aspire");
- // Load options relationship kind
- ProductRelationType optionRelation = ProductRelationType.All().Single(x => x.Name == "Option");
- // Load the product options, "Option" relation kind only
- var options = macbookAir.GetRelatedProducts()[optionRelation];
- }
- <h1>@macbookAir.Name</h1>
- <form>
- <input type="hidden" name="masterSku" value="@macbookAir.Sku"/>
- @foreach (Product option in options)
- {
- <h2>@option.GetDescription("en-us").DisplayName</h2>
- if (option.ProductDefinition.IsProductFamily())
- {
- foreach (Product selectableOption in option.Variants)
- {
- <input type="radio" group="@option.Name" name="SKU,@option.Sku" value="@option.Sku,@selectableOption.VariantSku">@selectableOption.GetDescription("en-us").DisplayName</input>
- if (selectableOption.GetPrice(priceGroup).Price > 0)
- {
- <span>@selectableOption["Type"].Value [Add $@selectableOption.GetPrice(priceGroup).Price.Value.ToString("#.00")]</span>
- }
- <br />
- }
- }
- else
- {
- <input type="radio" group="@option.Name" name="SKU,@option.Name" value="@option.Sku">@option.GetDescription("en-us").DisplayName</input>
- if (option.GetPrice(priceGroup).Price > 0)
- {
- <span>[Add $@option.GetPrice(priceGroup).Price.Value.ToString("#.00")]</span>
- }
- <br />
- }
- }
- <br />
- <input type="submit" value="Add to basket" />
- </form>
- </umbraco:Macro>
- </asp:content>
Advertisement
Add Comment
Please, Sign In to add comment