public override bool UpdateItem(IEditableObject item, Control editor) { CheckBoxList checkBoxList = (CheckBoxList)editor; Product product = (Product)item; // Clear any existing variation configurations. foreach (VariationConfiguration variationConfiguration in product.GetChildren<VariationConfiguration>().ToArray()) Context.Persister.Delete(variationConfiguration); foreach (ListItem listItem in checkBoxList.Items.Cast<ListItem>().Where(li => li.Selected)) { VariationPermutation variationPermutation = new VariationPermutation(); int[] variationIDs = listItem.Value.Split(',').Select(s => Convert.ToInt32(s)).ToArray(); foreach (int variationID in variationIDs) variationPermutation.Variations.Add(Context.Persister.Get(variationID)); VariationConfiguration variationConfiguration = new VariationConfiguration { Permutation = variationPermutation, Available = true }; variationConfiguration.AddTo(product); } return true; }
public virtual void AddItem(Shop shop, Product product, IEnumerable<Variation> variations) { ShoppingBasket shoppingBasket = GetCurrentShoppingBasketInternal(shop, true); // If card is already in basket, just increment quantity, otherwise create a new item. ShoppingBasketItem item = shoppingBasket.GetChildren<ShoppingBasketItem>().SingleOrDefault(i => i.Product == product && ((variations == null && i.Variations == null) || EnumerableUtility.Equals(i.Variations, variations))); if (item == null) { VariationPermutation variationPermutation = null; if (variations != null && variations.Any()) { variationPermutation = new VariationPermutation(); foreach (Variation variation in variations) variationPermutation.Variations.Add(variation); } item = new ShoppingBasketItem { Product = product, VariationPermutation = variationPermutation, Quantity = 1 }; item.AddTo(shoppingBasket); } else { item.Quantity += 1; } _persister.Save(shoppingBasket); }
public virtual void UpdateQuantity(Shop shop, Product product, VariationPermutation variationPermutation, int newQuantity) { if (newQuantity < 0) throw new ArgumentOutOfRangeException("newQuantity", "Quantity must be greater than or equal to 0."); ShoppingBasket shoppingBasket = GetCurrentShoppingBasketInternal(shop, true); ShoppingBasketItem item = shoppingBasket.GetChildren<ShoppingBasketItem>().SingleOrDefault(i => i.Product == product && i.VariationPermutation == variationPermutation); if (item == null) return; if (newQuantity == 0) { shoppingBasket.Children.Remove(item); _persister.Delete(item); } else item.Quantity = newQuantity; _persister.Save(shoppingBasket); }
public virtual void RemoveItem(Shop shop, Product product, VariationPermutation variationPermutation) { UpdateQuantity(shop, product, variationPermutation, 0); }