Dynamics Retail Discount Extensibility – Register a New Discount Type


We have some code snippets of how to register your new discount type.

Customized retail discount store

    public class CustomizedRetailDiscountStore : RetailDiscountStore
    {
        protected override DiscountBase CreateDiscount(PeriodicDiscount discountAndLine)
        {
            if ((int)discountAndLine.PeriodicDiscountType == TeaserDiscount.PeriodicDiscountOfferTypeTeaser)
            {
                return new TeaserDiscount(discountAndLine.ValidationPeriod);
            }
            else if (discountAndLine.PeriodicDiscountType == PeriodicDiscountOfferType.Offer)
            {
                object quantityLimitObject = discountAndLine.GetProperty(ExtensionDiscountOfferQuantityLimitString);
                if (quantityLimitObject != null)
                {
                    int quantityLimit = (int)quantityLimitObject;
                    if (quantityLimit > 0)
                    {
                        return new OfferDiscountWithQuantityControl(discountAndLine.ValidationPeriod, quantityLimit);
                    }
                }

                return new OfferDiscountWithLineFilter(discountAndLine.ValidationPeriod);
            }
            else
            {
                return base.CreateDiscount(discountAndLine);
            }
        }

        protected override RetailDiscountLine CreateRetailDiscountLine(
            PeriodicDiscount discountAndLine,
            DiscountBase discount)
        {
            RetailDiscountLine retailDiscountLine = base.CreateRetailDiscountLine(discountAndLine, discount);

            ValidationPeriod lineValidationPeriod = discountAndLine.GetProperty(ExtensionLinePeriodString) as ValidationPeriod;
            if (lineValidationPeriod != null)
            {
                retailDiscountLine.SetProperty(ExtensionLinePeriodString, lineValidationPeriod);
            }

            return retailDiscountLine;
        }
    }

Register customized retail discount store

At the top of the customized pricing service call, register the customized retail discount store.

    public class PricingServiceSampleCustomization : IRequestHandler
    {
        public Response Execute(Request request)
        {
            // Register customized components here.
            if (!PricingEngineExtensionRepository.IsInitialized)
            {
                PricingEngineExtensionRepository.RegisterRetailDiscountStore(new CustomizedRetailDiscountStore());
                PricingEngineExtensionRepository.IsInitialized = true;
            }

            …

        }
    }

Related: Dynamics Retail Discount Extensibility Overall Approach

Related: Dynamics Retail Discount Extensibility – Three Discount Categories

Comments (0)

Skip to main content