Just continuing to post what we came up with to solve our specific issue. Disclaimer: This logic MAY NOT be correct for your situation, but for us, in the Buy One, Get One of equal or lesser value scenario, this is what we did to make it work.
All edits were made to:
source\BVSoftware.Bvc5.Core\Marketing\BuyXGetYByCategory.vb
First, we changed the logic on the qualifiedQueue, rather than qualifying the X most expensive items, we qualified every "_QualificationQty + 1" items to follow the Buy X Get Y model.
Code:
86: 'Dim qualifyingCount As Integer = CInt(Math.Floor((sortedQualifying.Count * _QualificationQty) / (_QualificationQty + 1)))
87: 'For x As Integer = 0 To qualifyingCount - 1
88: 'qualifiedQueue.Enqueue(sortedQualifying(x))
89: 'Next
90: For i As Int32 = 0 To sortedQualifying.Count - 1 Step (_QualificationQty + 1)
91: qualifiedQueue.Enqueue(sortedQualifying(x))
92: Next
So in our example case above, the old / new code produced the following qualifiedQueue from the sortedQualifying list of [39, 39, 39, 25, 25, 25]:
Old: [39, 39, 39] (positions 0, 1, 2 in sortedQualifying)
New: [39, 39, 25] (positions 0, 2, 4 in sortedQualifying)
Now that the "viable discount" rates were what we needed, we shifted to the discounting logic itself. This was a bit more involved. The basic idea is that I created a new list of LineItemData, where each position in the list represented a single item purchase. However, I still added a handle to the SAME LineItemData values that exist in sortedPromo (Qty and all), so the logic later in the function could be largely preserved. So while it does appear that I am now purchasing 3x the number of items, this is not the case due to the logic further down. I just needed a simple list where I could "skip the first X items" based on what products have already "taken part in" the BoGo special.
For Example:
Code:
sortedPromo: [ { LineItemData price 39 - qty 3 }, { LineItemData price 25 - qty 3 } ]
lstProducts: [ { LineItemData price 39 - qty 3 }, { LineItemData price 39 - qty 3 }, { LineItemData price 39 - qty 3 }, { LineItemData price 25 - qty 3 }, { LineItemData price 25 - qty 3 }, { LineItemData price 25 - qty 3 } ]
Next, I had to keep track of how many products to skip in my new array. I just declared a var outside the "While qualifiedQueue.Count > 0" loop called numToSkipForPromo
Inside the loop, I incremented this value by the qualification qty:
numToSkipForPromo += _QualificationQty
The next change came in the signature for the AttemptToApplyDiscount function. I needed to pass in my new numToSkipForPromo value, and I changed the name of the list of LineItemData var to better describe what I was now passing in:
Private Function AttemptToApplyDiscount(ByVal amount As Decimal, ByVal lstProducts As List(Of LineItemData), ByVal numToSkipForPromo As Int32, ByVal marketingQueue As DiscountQueue) As Boolean
The last change was to the body of the AttemptToApplyDiscount function. I changed the functionality of the outer for loop to use my new list of products, but to start at the appropriate index based on how many products we are to skip for promotion consideration.
Code:
Dim result As Boolean = False
For i As Int32 = numToSkipForPromo To lstProducts.Count - 1
Dim lid As LineItemData = lstProducts.ElementAt(i)
If (lid.QtyLeft > 0) Then
If (lid.ItemAdjustedPrice <= amount) Then
ApplySingleDiscount(lid, marketingQueue)
result = True
Exit For
End If
End If
Next
That's it. Now my Buy 1 Get 1 of equal or lesser value special is returning the correct discounts. Again, full disclaimer, I have NOT tested this code in other scenarios, so take this for what it is. The BV guys may have a better solution, but I'm posting this in case it helps anyone. I will try to attach my .vb file to this post since the code above may be a little difficult to reconstruct.
Thanks!
Jim Carpenter
File Attachment(s):
BuyXGetYByCategory.vb
(14kb) downloaded 0 time(s).You cannot view/download attachments. Try to login or register.