Developer forum

Forum » Development » PriceProvider not called when user changes

PriceProvider not called when user changes

Espen Strømsnes
Espen Strømsnes
Reply

I have a custom priceprovider that retrieves customer specific prices from a backend ERP. My priceprovider extends PriceProvide and overrides the PreparePrices and FindPrice methods.

I have the following use-case:

  • I log in as user A, browse the product catalog and open a product page. I can see in my log that PreparePrices and FindPrice is called.
  • I log out as user A and log in as user B, browse the product catalog and opens the same product page. No entries in my log indicate that PreparePrices and FindPrice is called (for the new user), i.e. prices retrieved for user A is shown to user B.

Am I doing something wrong? Should I do anything when a user logs out?

DW version is 9.4.10

Regards,

Espen

 


Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Espen,

No, it should be good with the example below. Try without your PreparePrices that caches your product prices, and see if this is the "bugger". Is it properly refreshed?

With the example below, all prices are 111 for user "a" and 222 for user "b". And I just log in with user "a", logout again, and the login with user "b".

 public class MyPriceProvider : PriceProvider
    {
        public override PriceRaw FindPrice(Product product, double quantity, string variantID, Currency currency, string unitID, User user)
        {
            if (!User.IsExtranetUserLoggedIn())
                return null;

            // Get the price from the DefaultPriceProvider
            DefaultPriceProvider defaultProvider = new DefaultPriceProvider();
            PriceRaw rawPrice = defaultProvider.FindPrice(product, quantity, variantID, currency, unitID, user);

            if (user.UserName == "a")
            {
                rawPrice.Price = 111;
                return rawPrice;
            }
            if(user.UserName == "b")
            {
                rawPrice.Price = 222;
                return rawPrice;
            }
            return null;
        }
    }

If you need further assistance it would be helpful if you could post your code for us to see.

BR 
Snedker

 
Espen Strømsnes
Espen Strømsnes
Reply

Hi Morten

I have now simplified the provider and it looks like this:

    public class DebugLoggingLiveERPPriceProvider : PriceProvider
    {
        public override PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user)
        {
            // Get the price from the DefaultPriceProvider
            DefaultPriceProvider defaultProvider = new DefaultPriceProvider();
            PriceRaw rawPrice = defaultProvider.FindPrice(product, quantity, variantId, currency, unitId, user);

            if (user != null && user.CustomerNumber == "A") 
            {
                rawPrice.Price = 111;
                return rawPrice;
            }
            if (user != null && user.CustomerNumber == "B") 
            {
                rawPrice.Price = 222;
                return rawPrice;
            } else
            {
                rawPrice.Price = 333;
                return rawPrice;
            }
        }
    }

 

As you see from the code I have 2 users. The strange thing I have discovered now is that the provider is only called one time for each product, causing other users to see the price of the first user that browsed the product (across users in the same browser, and across computers)!

Example:

User A logs in and browses product 1. The price is 111. I log out user A and log in as user B (in the same browser session), browse product 1 and the price is still 111 (here I expected 222).

The interesting part now is that a completely different person on a completely different computer can browse product 1 (without logging in) and the price is still 111 (here I expected 333).

I can also confirm that if the user that is not logged in browses a product that hasn't been displayed before, this user and all other users get the price 333.

The site is hosted in Azure.

With this simplified priceprovider without any caching I would expect the FindPrice method to be called on every product that is displayed to every user, i.e. a lot of times....

Any tips?

Regards

Espen

 
Espen Strømsnes
Espen Strømsnes
Reply
This post has been marked as an answer

Hi again Morten.

I upgraded DW to 9.4.20 and the price provider is now called as expected, for every user+product combination.

Problem solved!

Regards

Espen

Votes for this answer: 1

 

You must be logged in to post in the forum