Automatic discount based on customer discount-level with set amounts per product

So it got me wondering, after looking at the gigantic Rule-set: Is it worth it? It looks overly-complex to me at first glance. Happy Hour in itself is fairly simple. As is VIP discounts. But put them together and it looks scary. I can’t help but think there must be some opportunity for optimization in there somewhere…

Ticket States (named VIP) used:

  • Active: customer has a VIP Level (1,2,3)
  • InActive: customer does not have a VIP Level, or there is no customer assigned to the Ticket

Order States (named DiscountType) used:

  • <> : (blank) when an Order is first added; will be updated immediately to ND
  • ND : No Discount (same as blank, but easier to identify and work with)
  • VIP : VIP Discount as defined by D1/D2/D3 Product Tags
  • HH : Happy Hour Discount as defined by HH Product Tag; overrides VIP
  • VR : VIP Removed (temporary holding State when VIP Customer removed from Ticket, or Customer changed to non-VIP Customer)
  • HP : Happy Hour Pending (temporary holding State until we verify whether Item Order Time fell within the HH timeframe)

This is where I think I might be able to get rid of 1 or 2 States and Rules:

As I developed the flow, VR was necessary so that VIP-removal would not automatically become HH. Then I figured: why couldn’t it become HH if it qualified? We can check Order Time and apply HH if it qualified. So then I created HP to use while checking the Order Time, and would update it to HH or ND as applicable.

ND > VIP > VR > HP > HH or ND

If HH overrides VIP, how could that happen? In testing, I had manual control over turning HH on and off, and modifying the HH Start/End Times, that’s how. If I didn’t have that control, the above scenario would theoretically never come into play. So why do we need that flow? We probably don’t! This would be because: if the original Order Time was inside the HH Window, the flow would have been:

ND > HH

That should be the case whether or not a VIP Customer is selected on the Ticket. Now what happens when we are not inside HH Window? Depending on Customer VIP Level:

ND > VIP or simply ND … let’s assume ND > VIP

Now we remove VIP Level Customer:

VIP > VR

Why? So it doesn’t become HH. Why would it become HH? Because I wasn’t checking Order Time, it would automatically become HH if the HH PriceList was defined, which I was switching on/off at will. I shouldn’t be checking the PriceList status at all; instead I should be checking the HH Start/End Time and comparing it to the Order Time. But through development, that came later.