Ejemplo n.º 1
0
        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);
        }
 private static IEnumerable<IEnumerable<Variation>> GetPermutations(Product product)
 {
     VariationSetContainer variationSets = product.CurrentCategory.Shop.VariationsSet;
     if (variationSets == null)
         return null;
     List<List<Variation>> inputVariationSets = new List<List<Variation>>();
     foreach (VariationSet set in variationSets.Sets)
     {
         List<Variation> inputVariations = new List<Variation>();
         foreach (Variation variation in set.Variations)
             inputVariations.Add(variation);
         inputVariationSets.Add(inputVariations);
     }
     return CartesianProductUtility.Combinations(inputVariationSets[0], inputVariationSets[1]);
 }
 private static bool HasPermutation(Product product, IEnumerable<Variation> permutation)
 {
     return product.VariationConfigurations.Any(vc => vc.Available
         && EnumerableUtility.Equals(vc.Permutation.Variations.Cast<Variation>(), permutation));
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public virtual void RemoveItem(Shop shop, Product product, VariationPermutation variationPermutation)
 {
     UpdateQuantity(shop, product, variationPermutation, 0);
 }
Ejemplo n.º 6
0
        public virtual bool IsValidVariationPermutation(Product product, IEnumerable<Variation> variations)
        {
            if ((variations == null || !variations.Any()) && (product.VariationConfigurations == null || !product.VariationConfigurations.Any()))
                return true;

            return product.VariationConfigurations.Any(vc => vc.Available
                && EnumerableUtility.EqualsIgnoringOrder(vc.Permutation.Variations.Cast<Variation>(), variations));
        }