Exemplo n.º 1
0
 private void ApplyPricesWithExchangeRates(IEnumerable <Currency> allCurrencies)
 {
     //Need add product price for all currencies (even if not returned from API need make it by currency exchange conversation)
     foreach (var currency in allCurrencies)
     {
         var price = Prices.FirstOrDefault(x => x.Currency == currency);
         if (price == null)
         {
             price = new ProductPrice(currency);
             //Convert exist price to new currency
             if (Prices.Any())
             {
                 price = Prices.First().ConvertTo(currency);
                 price.TierPrices.Add(new TierPrice(price.SalePrice, 1));
             }
             Prices.Add(price);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Apply prices to product
        /// </summary>
        /// <param name="prices"></param>
        /// <param name="currentCurrency"></param>
        /// <param name="allCurrencies"></param>
        public void ApplyPrices(IEnumerable <ProductPrice> prices, Currency currentCurrency, IEnumerable <Currency> allCurrencies)
        {
            Prices.Clear();
            Price = null;

            Currency = currentCurrency;
            //group prices by currency
            var groupByCurrencyPrices = prices.GroupBy(x => x.Currency).Where(x => x.Any());

            foreach (var currencyGroup in groupByCurrencyPrices)
            {
                //For each currency need get nominal price (with min qty)
                var orderedPrices = currencyGroup.OrderBy(x => x.MinQuantity ?? 0).ThenBy(x => x.ListPrice);
                var nominalPrice  = orderedPrices.FirstOrDefault();
                //and add to nominal price other prices as tier prices
                nominalPrice.TierPrices.AddRange(orderedPrices.Select(x => new TierPrice(x.SalePrice, x.MinQuantity ?? 1)));
                //Add nominal price to product prices list
                Prices.Add(nominalPrice);
            }
            //Need add product price for all currencies (even if not returned from API need make it by currency exchange conversation)
            foreach (var currency in allCurrencies)
            {
                var price = Prices.FirstOrDefault(x => x.Currency == currency);
                if (price == null)
                {
                    price = new ProductPrice(currency);
                    //Convert exist price to new currency
                    if (Prices.Any())
                    {
                        price = Prices.First().ConvertTo(currency);
                        price.TierPrices.Add(new TierPrice(price.SalePrice, 1));
                    }
                    Prices.Add(price);
                }
            }
            //Set current product price for current currency
            Price = Prices.FirstOrDefault(x => x.Currency == currentCurrency);
        }
Exemplo n.º 3
0
 public Product(Currency currency, Language language)
     : this()
 {
     Currency = currency;
     Price    = new ProductPrice(currency);
 }