Developer forum

Forum » Development » Question regarding eCom cart rendering

Question regarding eCom cart rendering

Dmitrij Jazel
Reply

Hello DW guys,

 

I have a situation here,

 

I made a Custom price provider, this provider is calculating custom price for product.

This price is calculated on external data I receive from other place. The calculation process as itself, is taking quite alot of time...

 

Eventually when I use it - it looks like it has something to do with shopping cart aswell!?

When I use price provider, and fill up the cart, it takes about 30-60sec. to load the cart with 20 products.

 

When I remove the price provider, the cart seams to work ok...

So I wanted to know:

1) What relation does price provider has towards the cart?

2) Is there a way to boost the cart, or something I could improve to make cart a bit faster?

 

Here is the implementation of my price provider (see the attachment).

 

kind regards,

Dmitrij


Replies

 
Vladimir
Reply

 

Hi Dmitrij!
 
Yes, you are right, price provider is called by cart several times on each step(until order not completed).
I think it better to make cache for product price for each user
 
Best regards,
Vladimir

 

 
Dmitrij Jazel
Reply

Hi Vladimir,

 

This could sound like an option, but could you maybe have an example for me (if possible)?

And Is there any limitation of how much products I put into cache per user?

 

I will take a look at the price provider example here, but at the same time could you please provide me a simple example of how this could be done (in your way)? Cause that example is all I have right now, and that is a bit limiting :( ...

 

Edit...:

But as far as I understand now, I have to check price in cache first, and if it does not exist, than look for it and add it if needed.

So my current implementation (looking prices in DB) will be used for lookup of prices.

Lookup of prices must be done once I get new imported prices - after the import I will have to update caches (via db lookup).

 

So eventually when I am calling price provider I will have to check the cache first and get the price from there, instead of db lookup how it is done now.

 

Does that sound like the right thing to do? :-) 

And does Cache is accessible within whole application (like session object for example)?

 

Regards,

Dmitrij

 
Vladimir
Reply

 Hi Dmitrij!

That sound right)

Few moments:

1) There is no need to cache products - only dictionsary

2) Session object to store dictionsary is  most suitable I think

 

Simple example:

        public static double CheckIsPriceCached(string productID, string discountCode)
        {
            double rslt = 0;

            if ((HttpContext.Current.Session["MyPriceProvider"+discountCode] != null))
            {
                Dictionary<string, double> cachedPrices = (Dictionary<string, double>)HttpContext.Current.Session["MyPriceProvider"+discountCode];
                if (cachedPrices.ContainsKey(productID))
                {
                    rslt = cachedPrices(productID);
                }
            }

            return rslt;
        }

        public static void CachePrice(string productID, string discountCode, double price)
        {
            Dictionary<string, double> cachedPrices;
			
            if ((HttpContext.Current.Session["MyPriceProvider"+discountCode] != null))
                cachedPrices = (Dictionary<string, double>)HttpContext.Current.Session["MyPriceProvider"+discountCode];
            else 
                cachedPrices = new Dictionary<string, double>();

            if (!cachedPrices.ContainsKey(productID)) cachedPrices.Add(productID, price);
            HttpContext.Current.Session["MyPriceProvider"+discountCode] = cachedPrices;  
        }

Best regards,
Vladimir

 

 
Dmitrij Jazel
Reply

Hej Vladimir,

 

Just got an answer from Imar regarding issue so far.

Application variable. Just got solved. Thanks alot for help :-)

 

 

Regards,

Dmitrij

 

 

You must be logged in to post in the forum