Dynamics Retail Discount Concepts: Discountable Item Group

In Dynamics Retail, we allow retailer to configure whether to aggregate the newly scanned product into an existing one if it already has the product. For example, when you scan two of the same keyboard, you may see one line of quantity two, or two lines, each of quantity one. For discount, it makes no difference functionally. However, technically, in combinatorial and knapsack algorithm, it can make a huge difference. In general one line of multiple quantity works far superior in performance.

Introduce DiscountableItemGroup: discountable item group. Item group index will be the index of the fixed array of discountable item groups.

The first and obvious task is that it holds similar products together, aggregating quantity for discount. By similar, as of this writing, it means same product Id (or variant Id if it is a variant), same price, same unit of measure, etc.

The second, less obvious but important responsibility is to allocate discount details to the sales lines after the discount engine figures out the deal. Let’s have some examples, say in the cart, you have 4 keyboards and you have applied 2 discount applications, mix and match of 3 with 20% off, and a simple discount of 1 with $5 off.

Example 1: Discountable item group with one sales line of quantity four

We will split the sales line into 2: one with quantity three for mix and match of 20% off, and the other one with quantity one for simple discount of $5 off.

Example 2: Discountable item group with two sales lines, of quantity one and three

Perfect match: one with quantity three for mix and match of 20% off, and the other one with quantity one for simple discount of $5 off.

Example 3: Discountable item group with four sales lines, each of quantity one

Three sales lines will get mix and match of 20% off, and the other one will get simple discount of $5 off.

Example 4: Discountable item group with two sales lines, each of quantity two

We will make one of sales lines for mix and match of 20% off. Then we will split the other sales line into two, each of quantity one: one for mix and match and one for simple discount.

We have not touched compounding and priority yet. They would make the allocation more complicated, especially the compounding.

Note: in the blog posts, I mostly talk about product, while in Dynamics Retail Pricing Engine, we often use item. They are mostly the same thing.

Related: Retail Discount Concurrency – Best Deal Knapsack Problem