Developer forum

Forum » Development » Caching salesdiscounts based on language

Caching salesdiscounts based on language

Anders Ebdrup
Anders Ebdrup
Reply

Hi Dynamicweb,

 

We have experienced an issue with caching of sales discounts in 8.8.1 which seems to be done by the website language (and not also by the chosen currency):

        Private Shared Function GetCachedDiscounts(ByVal language As Language) As SalesDiscountCollection
            Const key As String = "SalesDiscounts"
            Dim discounts As SalesDiscountCollection
            Dim caches As Dictionary(Of String, SalesDiscountCollection) = Nothing
            Dim storage As Content.Caching.Storage = Content.Caching.StorageManager.Current.GetStorage("eCommerce")
            Dim ret As SalesDiscountCollection

            If storage.Contains(key) Then
                caches = storage.Get(Of Dictionary(Of String, SalesDiscountCollection))(key)
            End If

            If IsNothing(caches) OrElse Not caches.ContainsKey(language.LanguageID) Then
                caches = New Dictionary(Of String, SalesDiscountCollection)()

                For Each aLanguage As Language In language.getLanguages()

                    ret = New SalesDiscountCollection
                    discounts = New SalesDiscountCollection()
                    discounts.Load("SELECT * FROM EcomSalesDiscount ORDER BY SalesDiscountID", aLanguage)

                    For Each d As SalesDiscount In discounts
                        ret.Add(d)
                    Next
                    caches.Add(aLanguage.LanguageID, ret)
                Next
                storage.Insert(key, caches)
            End If
            Return caches(language.LanguageID)
        End Function

The issue is that you add a discount code (http://screencast.com/t/4YLZCfcdhE) and afterwards change the currency of the website, which does not invalid the cache of discount providers.

Can you reproduce the behaviour and have we hit a (critical) bug?

Best regards, Anders

 


Replies

 
Nicolai Pedersen
Reply

Hi Anders

They are cached by Ecommerce Language because all discounts have a name that can be translated -  changing the currency on a website will not change which discounts are available so the cache should not be reset when website currency changes. When ever a discount is changed, the cache is reset.

But where do you see a calculation that does not change when you change the currency on the website?

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

I think the cache key for the salesdiscount should be dependent of both language and currency as the sales discounts has this property:



        Public ReadOnly Property ValueFixedForCurrency() As Double
            Get
                If ValueFixedByCurrencies.ContainsKey(Dynamicweb.eCommerce.Common.Context.Currency.Code) AndAlso ValueFixedByCurrencies(Dynamicweb.eCommerce.Common.Context.Currency.Code) > 0 Then
                    Return ValueFixedByCurrencies(Dynamicweb.eCommerce.Common.Context.Currency.Code)
                Else
                    Return _ValueFixed
                End If
            End Get
        End Property

And if we cache the sales discounts based on only language then this will not be changed.

 

Does it make sense or should I file in a support case?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Hi Anders

It will still be the same SalesDiscount instance in the cache... The only difference is the name of the discount - the translated values.

I think that the problem you see is that Dynamicweb.eCommerce.Common.Context.Currency.Code does not reflect the change of website currency before you kill your current session. Because it will remember (that is its purpose)... So if you make the same change and close all browsers, I do not think you will run into the issue.

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

I do not think that is the case as the value should be updated in EcomPageLoadNotificationSubscriber, with this code block:

If Base.Request("CurrencyCode") <> String.Empty Then
                        Dynamicweb.eCommerce.Common.Context.CurrencySetByCustomer = True
                        Dynamicweb.eCommerce.Common.Context.Currency = Dynamicweb.eCommerce.Common.Application.Currency(Base.Request("CurrencyCode"))
                        isCurrencyChanged = True
                    End If

 

I still believe the problem is about not refreshing the cache for the currency dependent amounts: http://screencast.com/t/UR2unPWD after the customer changes the currency in the frontend.

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Hi Anders

I am confident that the cache key is not the issue. All discounts are always available on a website - only difference is the name. It must be something in a calculation somewhere else.

In your first post you mention the currency on the website is the one changing. But in your last it is the context currency of the user.

Can you provide "Steps to reproduce" instead? Or a screencast.

Thanks, Nicolai

 
Morten Buhl Dynamicweb Employee
Morten Buhl
Reply
This post has been marked as an answer

Hi Anders

I've reproduced the issue locally and bugged it as TFS-29252

/Morten Buhl, DW

Votes for this answer: 1
 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Morten,

 

When will this be fixed as I cannot see it on the this list: http://doc.dynamicweb.com/releases-and-downloads/releases/known-bugs/known-bugs?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

This has been fixed on head branch and needs to be tested and merged to 8.9 branch.

I'll check why it is not on the known bugs list.

BR Nicolai

 

You must be logged in to post in the forum