// Loop through all possible variants and generate selection data private void GenerateVariantSelections(List <OptionSelectionList> data, List <Option> options, int optionIndex, OptionSelectionList tempSelections) { if (optionIndex > (options.Count - 1)) { // we've hit all options so add the selections to the data OptionSelectionList temp = new OptionSelectionList(); temp.AddRange(tempSelections); //tempSelections.RemoveAt(tempSelections.Count() - 1); //tempSelections.Clear(); data.Add(temp); } else { Option opt = options[optionIndex]; foreach (OptionItem oi in opt.Items) { if (oi.IsLabel == false) { OptionSelectionList localList = new OptionSelectionList(); localList.AddRange(tempSelections); localList.Add(new OptionSelection(opt.Bvin, oi.Bvin)); GenerateVariantSelections(data, options, optionIndex + 1, localList); } } } }
// Products and Line Items public Orders.LineItem ConvertProductToLineItem(Orders.IPurchasable p, OptionSelectionList selections, int quantity, MerchantTribeApplication app) { Orders.LineItem li = new Orders.LineItem(); if (p != null) { Orders.PurchasableSnapshot snapshot = p.AsPurchasable(selections, app, true); if (snapshot != null) { li.BasePricePerItem = snapshot.BasePrice; li.ProductId = snapshot.ProductId; li.ProductName = snapshot.Name; li.ProductShippingHeight = snapshot.ShippingDetails.Height; li.ProductShippingLength = snapshot.ShippingDetails.Length; li.ProductShippingWeight = snapshot.ShippingDetails.Weight; li.ProductShippingWidth = snapshot.ShippingDetails.Width; li.ProductShortDescription = snapshot.Description; li.ProductSku = snapshot.Sku; li.Quantity = quantity; li.SelectionData = snapshot.SelectionData; li.ShippingSchedule = snapshot.ShippingDetails.ShippingScheduleId; li.VariantId = snapshot.VariantId; li.TaxSchedule = snapshot.TaxScheduleId; li.ShipFromAddress = snapshot.ShippingDetails.ShippingSourceAddress; li.ShipFromMode = snapshot.ShippingDetails.ShippingSource; li.ShipFromNotificationId = snapshot.ShippingDetails.ShippingSourceId; li.ShipSeparately = snapshot.ShippingDetails.ShipSeparately; li.ExtraShipCharge = snapshot.ShippingDetails.ExtraShipFee; } } return(li); }
public Variant() { this.StoreId = 0; this.Bvin = string.Empty; this.ProductId = string.Empty; this.Sku = string.Empty; this.Price = -1; this.Selections = new OptionSelectionList(); }
private void PriceForSelections(Catalog.Product p, OptionSelectionList selections) { this.IsValid = true; this.VariantId = string.Empty; this._ModifierAdjustments = 0; if (selections == null) { return; } if (p == null) { return; } // Check for Option Price Modifiers if (!p.HasOptions()) { return; } this._ModifierAdjustments = selections.GetPriceAdjustmentForSelections(p.Options); this.BasePrice += this._ModifierAdjustments; // Check for Variant Changes if (!p.HasVariants()) { return; } Variant v = p.Variants.FindBySelectionData(selections, p.Options); if (v == null) { this.IsValid = false; return; } // Assign Variant Attributes to this price data this.VariantId = v.Bvin; if (v.Sku.Trim().Length > 0) { this.Sku = v.Sku; } if (v.Price >= 0) { this.BasePrice = v.Price + this._ModifierAdjustments; } }
public bool SaveProductToWishList(Orders.IPurchasable p, OptionSelectionList selections, int quantity, MerchantTribeApplication app) { WishListItem wi = new WishListItem(); if (p != null) { Orders.PurchasableSnapshot snapshot = p.AsPurchasable(selections, app, true); if (snapshot != null) { wi.ProductId = snapshot.ProductId; wi.Quantity = quantity; wi.SelectionData = snapshot.SelectionData; wi.CustomerId = app.CurrentCustomerId; } } return(WishListItems.Create(wi)); }
public UserSpecificPrice(Product initialProduct, OptionSelectionList selections) { if (initialProduct == null) { throw new ArgumentNullException("Initial Product can not be null"); } // init this.IsValid = true; this.DiscountDetails = new List <Marketing.DiscountDetail>(); this.VariantId = string.Empty; // Load from Product this.ListPrice = initialProduct.ListPrice; this.Sku = initialProduct.Sku; this.BasePrice = initialProduct.SitePrice; this.OverrideText = initialProduct.SitePriceOverrideText; PriceForSelections(initialProduct, selections); }
public List <OptionSelectionList> VariantsGenerateAllPossibleSelections(OptionList options) { List <OptionSelectionList> data = new List <OptionSelectionList>(); List <Option> variantOptions = options.VariantsOnly(); if (variantOptions == null) { return(data); } if (variantOptions.Count < 1) { return(data); } OptionSelectionList selections = new OptionSelectionList(); GenerateVariantSelections(data, variantOptions, 0, selections); return(data); }
public Variant FindBySelectionData(OptionSelectionList selections, OptionList options) { OptionSelectionList variantSelections = new OptionSelectionList(); foreach (Option opt in options) { if (opt.IsVariant) { OptionSelection sel = selections.FindByOptionId(opt.Bvin); if (sel != null) { variantSelections.Add(sel); } else { return(null); } } } string selectionKey = OptionSelection.GenerateUniqueKeyForSelections(variantSelections); return(this.FindByKey(selectionKey)); }
public string RenderWithSelection(OptionSelectionList selections) { return(this.Processor.RenderWithSelection(this, selections)); }