By default we use a cookie to find your basket so it doesn't matter if you're logged in or not. If you want to support multiple customers logging in from the same machine you can override OrderContext.GetBasket and implement the behavior you want.
Once implemented you register your custom OrderContext in /umbraco/ucommerce/configuration/components.config
There wasn't yesterday when you posted this, but I thought it was an interesting question to make some documentation out of. So I made this article Changing the Default Basket Behavior of uCommerce that outlines how to do it.
If you don't log in it uses one basket, if you do log in it uses a second basket as intended. However this second basket is the same no matter who is logged in. I'm sure i copied your code correctly...
The basket for anonymous users is cookie based so it's effectively tied to the computer (as the cookie is stored there). You could migrate the basket content from the anonymous basket when the customer logs in and clear the anonymous one. Seeing as only one person can use the same computer at once that would fix the issue.
Could I ask what the specifc scenario is that you require behavior like this? Are you dealing with an in store type scenario where multiple people use the same computer to shop?
You need to replace the original LINQ expression for grabbing the basket based on member id with this updated version. Notice that I forgot to look at order properties for individual orders.
private Basket GetBasketForCurrentMember()
{
PurchaseOrder order = PurchaseOrder.SingleOrDefault(
x => x.OrderProperties.Where(y => y.OrderId == x.OrderId && y.Key == "MemberId" && y.Value == Member.CurrentMemberId().ToString()).Count() > 0
&& x.OrderStatusId == 1);
if (order != null) return new Basket(order);
return null;
}
Separate baskets for site members
How does one implement separate baskets for site members?
Ie, if I logon under my account it shows me my basket, if someone else logs on under their account it shows theirs.
uCommerce supports this out of the box.
By default we use a cookie to find your basket so it doesn't matter if you're logged in or not. If you want to support multiple customers logging in from the same machine you can override OrderContext.GetBasket and implement the behavior you want.
Once implemented you register your custom OrderContext in /umbraco/ucommerce/configuration/components.config
Hope this helps.
Thanks for the reply!
Are there any examples of how this is done?
Hi Colin,
There wasn't yesterday when you posted this, but I thought it was an interesting question to make some documentation out of. So I made this article Changing the Default Basket Behavior of uCommerce that outlines how to do it.
Hope it helps.
Thanks a lot for the article, it helped a ton, and got what I needed, functioning in the end!
Wonderful. Glad to hear it.
I seem to have a weird issue with it.
If you don't log in it uses one basket, if you do log in it uses a second basket as intended. However this second basket is the same no matter who is logged in. I'm sure i copied your code correctly...
The basket for anonymous users is cookie based so it's effectively tied to the computer (as the cookie is stored there). You could migrate the basket content from the anonymous basket when the customer logs in and clear the anonymous one. Seeing as only one person can use the same computer at once that would fix the issue.
Could I ask what the specifc scenario is that you require behavior like this? Are you dealing with an in store type scenario where multiple people use the same computer to shop?
Say for example if i create two accounts, User1 and User2, that means if i use my local PC to access the site, there should be 3 baskets:
One for an anonymous user, one for User1 and one for User2.
The anonymous user has a seperate basket which is what I want,
However both User1 and User2 share the same basket... not what i want.
I misunderstodd the problem :)
A tiny snuck into the code.
You need to replace the original LINQ expression for grabbing the basket based on member id with this updated version. Notice that I forgot to look at order properties for individual orders.
Sorry about the inconvenience.
I updated the original article as well to be on the safe side :)
Thanks, everything works now!
Hi all,
I tried this code and I have a problem with LINQ:
int currentMemberId = umbraco.cms.businesslogic.member.Member.CurrentMemberId();
UCommerce.EntitiesV2.PurchaseOrder order = UCommerce.EntitiesV2.PurchaseOrder.SingleOrDefault(
x => x.OrderProperties.Where(y => y.OrderPropertyId == x.OrderId && y.Key == "MemberId" && y.Value == currentMemberId.ToString()).Count() > 0
&& x.OrderStatus.Id == 1);
Error is :
could not resolve property: Id of: UCommerce.EntitiesV2.OrderStatus [.SingleOrDefault[UCommerce.EntitiesV2.PurchaseOrder](NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.PurchaseOrder], Quote((x, ) => (AndAlso(GreaterThan(.Count[UCommerce.EntitiesV2.OrderProperty](.Where[UCommerce.EntitiesV2.OrderProperty](x.OrderProperties, (y, ) => (AndAlso(AndAlso(Equal(y.OrderPropertyId, x.OrderId), String.op_Equality(y.Key, p1)), String.op_Equality(y.Value, p2))), ), ), 0), Equal(x.OrderStatus.Id, 1)))), )]
Any idea what is wrong?
I'm using Umbraco 6.1.6 + uCommerce 4.0.6.
Hi Ivan,
Please try using "&& x.OrderStatusId == 1" instead of "&& x.OrderStatus.Id == 1". Notice the missing dot "."!
Kind regards,
Jesper
Hi all,
I am getting this error -
" The property or indexer 'UCommerce.EntitiesV2.PurchaseOrder.OrderStatusId' cannot be used in this context because the set accessor is inaccessible "
Please advise.
thanks,
balbir
Hi Balbir,
You might be using a single "=" sign instead of two to make the comparison. .NET thinks you're trying to assign a value instead of compare it.
You want:
As opposed to
Hope this helps.
is working on a reply...