Guest User

Untitled

a guest
Jun 20th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.76 KB | None | 0 0
  1. <%@ Master Language="C#" MasterPageFile="~/masterpages/uCommerce.master" AutoEventWireup="true" %>
  2.  
  3. <asp:content ContentPlaceHolderId="PageContentPlaceholder" runat="server">
  4.  
  5. <umbraco:Macro runat="server" language="cshtml">
  6. @using UCommerce.EntitiesV2;
  7. @using UCommerce.Runtime;
  8. @using UCommerce.Xslt;
  9. @{
  10.     ProductCatalog catalog = ProductCatalog.All().Single(x => x.Name == "Hardware");
  11.    
  12.     // Check if we're dealing with a post
  13.     if (!string.IsNullOrEmpty(Request["masterSku"]))
  14.     {
  15.         var basket = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
  16.        
  17.         // Add the master order line
  18.         var mainProduct = Product.All().Single(x => x.Sku == Request["masterSku"] && x.ParentProductId == null);
  19.         var masterOrderLine = basket.AddProduct(catalog, mainProduct, 1, false);
  20.            
  21.         // Mark the master as such
  22.         masterOrderLine["master"] = true.ToString();
  23.      
  24.         // Save basket to generate ids for the order line
  25.         basket.Save();
  26.            
  27.         // Add each product option to the basket
  28.         foreach (string key in Request.Params.AllKeys.Where(x => x.Substring(0, 3) == "SKU"))
  29.         {
  30.             // Split the value of the posted skus to get both sku and variant sku (where applicable)
  31.             // Example Intel-Core-CPU,i7-1.7
  32.             string[] skus = Request[key].Split(',');
  33.             string sku = skus[0];
  34.             string variantSku = skus.Length == 2 ? skus[1] : null;
  35.                
  36.             // Add the option order line
  37.             var optionProduct = Product.All().Single(x => x.Sku == sku && x.VariantSku == variantSku);
  38.             OrderLine subOrderLine = basket.AddProduct(catalog, optionProduct, 1, false);
  39.      
  40.             // Add a reference back to the master order line
  41.             subOrderLine["masterOrderlineId"] = masterOrderLine.OrderLineId.ToString();
  42.         }
  43.      
  44.         basket.Save();
  45.  
  46.         // Execute the basket pipeline to recalculate basket
  47.         Library.ExecuteBasketPipeline();
  48.     }  
  49.  
  50.     // Grab a price group to work from
  51.     var priceGroup = ProductCatalog.All().Single(x => x.Name == "Hardware").PriceGroup;
  52.  
  53.     // Load MacBook Air product
  54.     Product macbookAir = Product.All().Single(x => x.Sku == "Acer Aspire");
  55.  
  56.     // Load options relationship kind
  57.     ProductRelationType optionRelation = ProductRelationType.All().Single(x => x.Name == "Option");
  58.  
  59.     // Load the product options, "Option" relation kind only
  60.     var options = macbookAir.GetRelatedProducts()[optionRelation];
  61. }
  62.  
  63. <h1>@macbookAir.Name</h1>
  64. <form>
  65. <input type="hidden" name="masterSku" value="@macbookAir.Sku"/>
  66. @foreach (Product option in options)
  67. {
  68.     <h2>@option.GetDescription("en-us").DisplayName</h2>
  69.     if (option.ProductDefinition.IsProductFamily())
  70.     {
  71.         foreach (Product selectableOption in option.Variants)
  72.         {
  73.             <input type="radio" group="@option.Name" name="SKU,@option.Sku" value="@option.Sku,@selectableOption.VariantSku">@selectableOption.GetDescription("en-us").DisplayName</input>
  74.             if (selectableOption.GetPrice(priceGroup).Price > 0)
  75.             {
  76.                 <span>@selectableOption["Type"].Value [Add $@selectableOption.GetPrice(priceGroup).Price.Value.ToString("#.00")]</span>
  77.             }
  78.             <br />
  79.         }
  80.     }
  81.     else
  82.     {
  83.         <input type="radio" group="@option.Name" name="SKU,@option.Name" value="@option.Sku">@option.GetDescription("en-us").DisplayName</input>
  84.         if (option.GetPrice(priceGroup).Price > 0)
  85.         {
  86.             <span>[Add $@option.GetPrice(priceGroup).Price.Value.ToString("#.00")]</span>
  87.         }
  88.         <br />  
  89.     }
  90. }
  91. <br />
  92. <input type="submit" value="Add to basket" />
  93. </form>
  94. </umbraco:Macro>
  95.  
  96. </asp:content>
Advertisement
Add Comment
Please, Sign In to add comment