Exemplo n.º 1
0
        private Dictionary <string, Dictionary <string, decimal> > GetDefaultPrices(VariationContent variation)
        {
            var prices = new Dictionary <string, Dictionary <string, decimal> >();

            foreach (var market in _marketService.GetAllMarkets())
            {
                if (!variation.IsAvailableInMarket(market.MarketId))
                {
                    continue;
                }

                prices.Add(market.MarketId.Value, new Dictionary <string, decimal>());

                var variantPrices = _priceDetailService.List(variation.ContentLink, market.MarketId,
                                                             new PriceFilter
                {
                    Quantity        = 0,
                    CustomerPricing = new[] { CustomerPricing.AllCustomers }
                },
                                                             0,
                                                             9999,
                                                             out var totalCount
                                                             ); // we are using 9,999 price values as the theoretical maximum

                if (variantPrices == null || totalCount <= 0)
                {
                    continue;
                }

                foreach (var price in variantPrices)
                {
                    if (price.MinQuantity != 0 || price.CustomerPricing != CustomerPricing.AllCustomers)
                    {
                        continue;                                                                                 // this is a default price
                    }
                    if (!prices.ContainsKey(price.UnitPrice.Currency.CurrencyCode))
                    {
                        prices[market.MarketId.Value].Add(price.UnitPrice.Currency.CurrencyCode, 0);
                    }

                    prices[market.MarketId.Value][price.UnitPrice.Currency.CurrencyCode] = price.UnitPrice.Amount;
                }
            }

            return(prices);
        }
        private Dictionary <string, Dictionary <string, decimal> > GetDefaultPrices(VariationContent variation)
        {
            var prices = new Dictionary <string, Dictionary <string, decimal> >();

            var priceDetailService = ServiceLocator.Current.GetInstance <IPriceDetailService>();

            foreach (var market in ServiceLocator.Current.GetInstance <IMarketService>().GetAllMarkets())
            {
                if (variation.IsAvailableInMarket(market.MarketId)) // no point adding price if not available in that market
                {
                    prices.Add(market.MarketId.Value, new Dictionary <string, decimal>());

                    int totalCount;

                    var variantPrices = priceDetailService.List(variation.ContentLink, market.MarketId, new PriceFilter()
                    {
                        Quantity = 0, CustomerPricing = new[] { CustomerPricing.AllCustomers }
                    }, 0, 9999, out totalCount);                                                                                                                                                                                // we are using 9,999 price values as the theoretical maximum

                    if (variantPrices != null && totalCount > 0)
                    {
                        foreach (var price in variantPrices)
                        {
                            if (price.MinQuantity == 0 && price.CustomerPricing == Mediachase.Commerce.Pricing.CustomerPricing.AllCustomers) // this is a default price
                            {
                                if (!prices.ContainsKey(price.UnitPrice.Currency.CurrencyCode))
                                {
                                    prices[market.MarketId.Value].Add(price.UnitPrice.Currency.CurrencyCode, 0);
                                }

                                prices[market.MarketId.Value][price.UnitPrice.Currency.CurrencyCode] = price.UnitPrice.Amount;
                            }
                        }
                    }
                }
            }

            return(prices);
        }