Developer forum

Forum » Development » NotificationSubscriber not hit in FindPoints

NotificationSubscriber not hit in FindPoints

Anders Ebdrup
Anders Ebdrup
Reply

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


Replies

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Anders,

Sorry for inconvience, I registered bug #73304 to fix this asap

Best regards,
Vladimir

Votes for this answer: 1
 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Anders

The problem regarding #78304 "NotificationSubscriber not hit in FindPoints" has now been resolved in Dynamicweb version 9.8.5

To upgrade please choose this version from download here:

http://doc.dynamicweb.com/releases-and-downloads/releases

Let me know if you need any more help regarding this

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Kristian,

 

Thank you. Please also look at this issue: https://doc.dynamicweb.com/forum/integration/integration/afterconditionrewardcalculation-not-hit-for-orderlines

 

Best regards, Anders

 

You must be logged in to post in the forum