Developer forum

Forum » Ecommerce - Standard features » Session based basket for some not all

Session based basket for some not all

Martin Grønbekk Moen
Reply

We have a special request from one of our customers.
90% of all users have their own username, log in to DW the regular way, and have their own user based basket. This basket is persistent through sessions, browsers and everything. This works perfect.

Then we have 10% who visit the shop through a government purchasing system. In this scenario the customer might have 10 users, but they all use the same username, and there is nothing we can do about it. We have made a single sign on solution from the purchasing system to DW, and it works. But the downside is that the purchasing system can only send one username for all users of the purchasing system.

So basically we need to make sure that for the 90% of users tha basket should work as it does, but for the other 10% we need to make sure that the basket is not stored in SQL, but instead stored in the browser session to make sure that alle the users with same username does not see each others baskets.

Any thoughts on how to achieve this?


Replies

 
Nicolai Høeg Pedersen
Reply

You can empty the cart when they login:


namespace CustomLoginCartHandler
{
    [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.User.OnExtranetLogin)]
    public class OnExtranetLoginObserver : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            if (args == null)
                return;

            if (!(args is Dynamicweb.Notifications.Standard.User.OnExtranetLoginArgs))
                return;
            Dynamicweb.Notifications.Standard.User.OnExtranetLoginArgs item = (Dynamicweb.Notifications.Standard.User.OnExtranetLoginArgs)args;

            Dynamicweb.eCommerce.Frontend.Cart.CartCatch.ClearCart();
            
        }
    }
}

 
Martin Grønbekk Moen
Reply

Ok, so...

User A (username = USER) log in at 09.00, the cart is empty and he add two items to the basket.
User B (username = USER) log in at 09.05, the cart is empty and he add two items to the basket.

Is it then zero or two items in user A's basket?

 
Adrian Ursu
Reply

How many users are we talking about?

Maybe you can use context carts.
Define a bunch of context carts and everytime a user loggs in, you assign the first empty cart.

It's not easy but I believe it's achievable and you use more standard functionality

Adrian

 
Martin Grønbekk Moen
Reply

There are 5-10 customers with this setup, and each have 2-20 users.
So potentially we need 20 context carts.

Im not that familiar with the concept of context carts, so not sure how to approach that kind of setup.

 
Adrian Ursu
Reply

You can define them from the backend (Management Center/Ecommerce/Orders/OrderContext

Usually they will have an ID of the form: ORDERCONTEXT1,ORDERCONTEXT2 etc

There is an ORDERCONTEXT Loop available.

You can parse the loop and find the first order context that is empty and assign it to the use in a cookie.

You can have a default one for the usual users (I believe this can be set at SHOP level)

Then, for each Add to cart Button you have to add the ORDERCONTEXT parameter that has the value you have stored previously in the cookie of the user.

The same goes for listing the cart. You will have to list the cart for the OrderCOntext of the user, based on the Cookie.

Probably it would be wise to destroy the carts after a certain period of time, using the code Nicolai suggested.

I hope this helps.

Adrian

 

 

You must be logged in to post in the forum