/// <summary>
        /// Add or remove any required setup fees before calculating pricing for cart.
        /// Setup fee items are marked with "NotRemovable" custom attributes as help to e.g. GUI code.
        /// </summary>
        public Cart CalculatePricing(Cart cart)
        {
            var setupFee = apiProductsProvider.GetProductsByCategories(new List <string>()
            {
                SetupFeeCategory
            }).FirstOrDefault();

            if (setupFee != null)
            {
                var allSetupFeeProducts = apiProductsProvider.GetProductsByCategories(ProductCategoriesWithSetupFee.ToList());
                var freePackageProducts = apiProductsProvider.GetProductsByCategories(new List <string> {
                    FreePackageCategory
                });
                var setupFeeProducts = allSetupFeeProducts.Where(s => !freePackageProducts.Any(f => s.ArticleNumber == f.ArticleNumber));

                var shouldHaveSetupFee = setupFeeProducts.Any(p => cart.CartItems.Any(ci => ci.ArticleNumber == p.ArticleNumber));
                var hasSetupFee        = cart.CartItems.Any(ci => ci.ArticleNumber == setupFee.ArticleNumber);

                if (shouldHaveSetupFee && !hasSetupFee)
                {
                    var setupFeeItem = new CartItem
                    {
                        ArticleNumber    = setupFee.ArticleNumber,
                        Quantity         = 1,
                        RenewalPeriod    = null,
                        CustomAttributes = new List <Core.CustomAttribute>()
                        {
                            new Core.CustomAttribute {
                                Name = "NotRemovable", Value = "true"
                            }
                        }
                    };

                    cart.AddItem(setupFeeItem);
                }
                else if (!shouldHaveSetupFee && hasSetupFee)
                {
                    var setupFeeItem = cart.CartItems.First(ci => ci.ArticleNumber == setupFee.ArticleNumber);

                    cart.RemoveItem(setupFeeItem.Id);
                }
            }

            var calculatedCart = baseCartPricingService.CalculatePricing(cart);

            return(calculatedCart);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Construct a new instance
        /// </summary>
        public DomainsProvider(
            IResellerDataProvider resellerDataProvider,
            ICurrencyPreferenceProvider currencyPreferenceProvider,
            ApiProductsProvider apiProductsProvider,
            ProductMapper productMapper,
            PublicBillingApiProxy billingApi,
            IShopNameProvider shopNameProvider) : base(billingApi)
        {
            if (resellerDataProvider == null)
            {
                throw new ArgumentException("resellerDataProvider");
            }

            if (currencyPreferenceProvider == null)
            {
                throw new ArgumentException("currencyPreferenceProvider");
            }

            if (apiProductsProvider == null)
            {
                throw new ArgumentNullException("apiProductsProvider");
            }

            if (productMapper == null)
            {
                throw new ArgumentNullException("productMapper");
            }

            if (shopNameProvider == null)
            {
                throw new ArgumentNullException("shopNameProvider");
            }

            var resellerData = resellerDataProvider.GetResellerAccountData();

            this.resellerId       = resellerData.Id;
            this.countryCode      = resellerData.DefaultCountry.Code;
            this.currencyCode     = currencyPreferenceProvider.GetCurrentCurrency().Code;
            this.productMapper    = productMapper;
            this.shopNameProvider = shopNameProvider;

            this.tldProducts = apiProductsProvider.GetProductsByCategories(new List <string> {
                "TLD"
            });
        }
        /// <summary>
        /// Construct a new instance
        /// </summary>
        public DomainsProvider(
            IResellerDataProvider resellerDataProvider, 
            ICurrencyPreferenceProvider currencyPreferenceProvider, 
            ApiProductsProvider apiProductsProvider, 
            ProductMapper productMapper,
            PublicBillingApiProxy billingApi,
            IShopNameProvider shopNameProvider) : base(billingApi)
        {
            if (resellerDataProvider == null)
            {
                throw new ArgumentException("resellerDataProvider");
            }

            if (currencyPreferenceProvider == null)
            {
                throw new ArgumentException("currencyPreferenceProvider");
            }

            if (apiProductsProvider == null)
            {
                throw new ArgumentNullException("apiProductsProvider");
            }

            if (productMapper == null)
            {
                throw new ArgumentNullException("productMapper");
            }

            if (shopNameProvider == null)
            {
                throw new ArgumentNullException("shopNameProvider");
            }

            var resellerData = resellerDataProvider.GetResellerAccountData();

            this.resellerId = resellerData.Id;
            this.countryCode = resellerData.DefaultCountry.Code;
            this.currencyCode = currencyPreferenceProvider.GetCurrentCurrency().Code;
            this.productMapper = productMapper;
            this.shopNameProvider = shopNameProvider;

            this.tldProducts = apiProductsProvider.GetProductsByCategories(new List<string> { "TLD" });
        }
        /// <summary>
        /// Get products by category. The value of the first <see cref="Atomia.Store.Core.SearchTerm"/> will be used as the category name to list products from.
        /// </summary>
        /// <param name="terms">Search terms, the first of which should have the value of category to find products from</param>
        /// <returns>Any found products for the category, ordered by price.</returns>
        public IEnumerable <CoreProduct> GetProducts(ICollection <SearchTerm> terms)
        {
            var category = terms.First().Value;
            var products = new List <CoreProduct>();

            var apiProducts = apiProductsProvider.GetProductsByCategories(new List <string>()
            {
                category
            });

            foreach (var apiProduct in apiProducts)
            {
                var product = this.productMapper.Map(apiProduct);

                products.Add(product);
            }

            var sortedProducts = products.Where(p => p.PricingVariants.Any(v => v.FixedPrice)).OrderBy(p => p.PricingVariants.Min(v => v.Price)).ToList();

            sortedProducts.AddRange(products.Where(p => !p.PricingVariants.Any(v => v.FixedPrice)).OrderBy(p => p.PricingVariants.Min(v => v.CounterType.Ranges.Min(r => r.Price))).ToList());
            return(sortedProducts);
        }