AX 2012 R3 CU9 has Discount code setup:
But there is no way how to apply Discount Codes to Sales Order. And unfortunately there is no logic in RetailOrderCalculator class which can feed sales order related discount codes to PricingEngine.
Fortunately PricingEngine is reaty to get and consider discount codes.
We need to do following:
1. Create post event to \Classes\RetailSalesOrderCalculator\initializeCrtTransaction method
public static void addSalesOrderDiscountCodes(XppPrePostArgs _args)
Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction crtSalesTransaction = _args.getReturnValue();
RetailSalesOrderCalculator retailSalesOrderCalculator = _args.getThis();
SalesId salesId = retailSalesOrderCalculator.getSalesId();
discountCodesList = crtSalesTransaction.get_DiscountCodes();
while select DiscountCode from salesTableDiscountCodes
where salesTableDiscountCodes.SalesId == salesId
SalesTableDiscountCodes is new table which contains 2 fields:
- SalesId - link to sales order
- DiscountCode - actualy discount code which customers should provide to use related discount
2. Create new method at \Classes\RetailSalesOrderCalculator class:
protected SalesId getSalesId()
3. You also should provide a way to edit SalesTableDiscountCodes table. Basically it could be simple list form which can be shown from SalesTable form.
Classes which also involved in retail price calculation and may help: