Dear Dynamicweb,
We have an issue with this notification subscriber: Notifications.Ecommerce.Loyalty.AfterConditionRewardCalculation as the result is returned before the notification subscriber is hit.
Can you please remove the line with red?
Public Function FindPoints(product As Products.Product, order As Order, orderTime As Date, unitId As String) As ConditionPointInfo
Dim result As ConditionPointInfo = Nothing
NotificationManager.Notify(Notifications.Ecommerce.Loyalty.BeforeConditionRewardCalculation, New Notifications.Ecommerce.Loyalty.LoyaltyBeforeConditionRewardArgs() With {.Product = product})
CheckProviderTypesInCache()
Dim pointProviders As ArrayList = CType(Cache.Current.Item(PointProvidersCacheKey), ArrayList)
Dim listPointInfo As New List(Of ConditionPointInfo)
Dim orderLine As New OrderLine(order) With {
.ProductId = product.Id,
.ProductVariantId = product.VariantId,
.UnitId = unitId,
.Quantity = 1
}
Dim lineToMerge As OrderLine = order.OrderLines.FirstOrDefault(Function(line) Services.OrderLines.CanBeMerged(line, orderLine))
If lineToMerge Is Nothing Then
lineToMerge = orderLine
Else
orderLine.Quantity = lineToMerge.Quantity + 1
End If
If Not pointProviders Is Nothing Then
For Each pointProviderType As Type In pointProviders
Dim pointProvider As IPointProvider = CType(AddInManager.CreateAddInInstance(pointProviderType), IPointProvider)
Dim pointInfo As IPointInfo
If TypeOf pointProvider Is IStatelessPointProvider Then
With CType(pointProvider, IStatelessPointProvider)
.CountryCode2 = order.VatCountry.Code2
.OrderTime = orderTime
End With
End If
If TypeOf pointProvider Is IConditionPointProvider Then
pointInfo = CType(pointProvider, IConditionPointProvider).FindConditionPoints(orderLine)
Else
pointInfo = pointProvider.FindPoints(orderLine)
End If
If Not IsNothing(pointInfo) Then
Dim conditionalPointInfo As ConditionPointInfo
If TypeOf pointInfo Is ConditionPointInfo Then
conditionalPointInfo = CType(pointInfo, ConditionPointInfo)
Else
conditionalPointInfo = New ConditionPointInfo() With {.Points = pointInfo.Points, .Reward = pointInfo.Reward, .ConditionRewards = Enumerable.Empty(Of ConditionReward)}
End If
listPointInfo.Add(conditionalPointInfo)
End If
Next
' Select only rewards which gives more points than current
Dim perspectiveReward As IPointInfo = listPointInfo.OrderByDescending(Function(pointInfo) pointInfo.Points).FirstOrDefault(Function(pointinfo) pointinfo.Points > lineToMerge.RewardValue.GetValueOrDefault())
Dim perspectiveRewardPoints As Double? = perspectiveReward?.Points
Dim perspectiveConditionRewards As IEnumerable(Of ConditionReward) = listPointInfo.SelectMany(Function(cpi) cpi.ConditionRewards.Where(Function(cr) cr.Points > lineToMerge.RewardValue.GetValueOrDefault() AndAlso cr.Points > perspectiveRewardPoints.GetValueOrDefault()))
perspectiveConditionRewards = perspectiveConditionRewards.
OrderBy(Function(r) r.Condition.ConditionTypes.Count).
ThenByDescending(Function(r) r.Points).
ToList()
If perspectiveReward IsNot Nothing OrElse perspectiveConditionRewards.Any() Then
result = New ConditionPointInfo() With {.ConditionRewards = perspectiveConditionRewards}
If perspectiveReward IsNot Nothing Then
result.Points = perspectiveReward.Points
result.Reward = perspectiveReward.Reward
End If
Return result
End If
End If
NotificationManager.Notify(Notifications.Ecommerce.Loyalty.AfterConditionRewardCalculation, New Notifications.Ecommerce.Loyalty.LoyaltyAfterConditionRewardArgs() With {.Product = product, .PointInfo = result})
Return result
End Function
Best regards, Anders