Exemple #1
0
        private void AddPrices(ISearchDocument document, IEnumerable <EntryContentBase> skuEntries)
        {
            var prices      = _pricingService.GetCatalogEntryPrices(skuEntries.Select(x => new CatalogKey(x.Code))).ToList();
            var validPrices = prices.Where(x => x.ValidFrom <= DateTime.Now && (x.ValidUntil == null || x.ValidUntil >= DateTime.Now));

            foreach (var marketPrices in validPrices.GroupBy(x => x.MarketId))
            {
                foreach (var currencyPrices in marketPrices.GroupBy(x => x.UnitPrice.Currency))
                {
                    var topPrice = currencyPrices.OrderByDescending(x => x.UnitPrice).FirstOrDefault();
                    if (topPrice == null)
                    {
                        continue;
                    }

                    var variationPrice = new SearchField(IndexingHelper.GetOriginalPriceField(topPrice.MarketId, topPrice.UnitPrice.Currency),
                                                         topPrice.UnitPrice.Amount);

                    var discountedPrice = new SearchField(IndexingHelper.GetPriceField(topPrice.MarketId, topPrice.UnitPrice.Currency),
                                                          _pricingService.GetDiscountPrice(topPrice.CatalogKey, topPrice.MarketId, topPrice.UnitPrice.Currency).UnitPrice.Amount);

                    document.Add(variationPrice);
                    document.Add(discountedPrice);
                }
            }
        }