Displaying discounts on category and product pages

Vote:
 

This page mentions using the StoreHelper fro getting discounted prices

https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-Commerce/9/Catalogs/Displaying-products/

However, those methods are marked as Obsolete, and they do not indicate what to use instead?

What is the appripriate way to show that a product is part of a promotion, and showing to discounted price?

#195995
Aug 15, 2018 11:33
Vote:
 

StoreHelper uses the old promotion system internally, and well, the old promotion system itself is marked as obsolete.

We would suggest to use the new promotion system, and you can use methods like this (from QuickSilver):

public IPriceValue GetDiscountPrice(CatalogKey catalogKey, MarketId marketId, Currency currency)
        {
            var market = _marketService.GetMarket(marketId);

            currency = currency != Currency.Empty ? currency : market.DefaultCurrency;

            var priceFilter = new PriceFilter
            {
                CustomerPricing = new[] { CustomerPricing.AllCustomers },
                Quantity = 1,
                ReturnCustomerPricing = true,
                Currencies = new[] { currency } 
            };
           
            var prices = _priceService.GetPrices(marketId, DateTime.Now, catalogKey, priceFilter)
                .OrderBy(x => x.UnitPrice.Amount)
                .ToList();

            foreach (var entry in GetEntries(prices))
            {
                var price = prices
                    .FirstOrDefault(x => x.CatalogKey.CatalogEntryCode.Equals(entry.Code) && x.UnitPrice.Currency.Equals(currency));
                if (price == null)
                {
                    continue;
                }

                var discountPrices = GetDiscountedPrices(entry.ContentLink, market, currency);
                if (!discountPrices.Any())
                {
                    return price;
                }

                return new PriceValue
                {
                    CatalogKey = price.CatalogKey,
                    CustomerPricing = CustomerPricing.AllCustomers,
                    MarketId = price.MarketId,
                    MinQuantity = 1,
                    UnitPrice = discountPrices.SelectMany(x => x.DiscountPrices).OrderBy(x => x.Price).First().Price,
                    ValidFrom = DateTime.UtcNow,
                    ValidUntil = null
                };
            }

            return null;
        }
        protected virtual IEnumerable<DiscountedEntry> GetDiscountedPrices(ContentReference contentLink, IMarket market, Currency currency)
        {
            return _promotionEngine.GetDiscountPrices(new[] { contentLink }, market, currency, _referenceConverter, _lineItemCalculator);
        }
#195996
Aug 15, 2018 11:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.