Share cart between users (contact / customerId) within the same organization

Vote:
 

Hi,

I'm implementing a B2B solution where users within the same organization should share the same cart. All APIs for loading carts requires a customerId [sic] which relates to a contact ID, i.e. we will always load or create a cart for just that user. How do we implement this in the best way? I see a few different approaches:

  • Share same contact, regardless user in same org. No the best solution because then we won't be able to se who created or updated the order.
  • Create custom implementation of ICartProvider and inherit from SerializableCartProvider. Seems to be the best approach, but potentially requires a lot of coding. This way we can remove the CartFilter that filters on customer ID and add our own filter for organization.

Has someone already implemented this, how did you do this, any drawbacks, pitfalls?

Thank you!

#191180
Apr 23, 2018 14:57
Vote:
 

I haven't implemented it but i would like to suggest two different approaches:

  • Organization has a primary contact, you could use it for a placeholder contact and place the shared cart on it.
  • There is an API Load function on IOrderRepository that takes an int orderGroupId, if you extended Organization with a custom metafield containing that id.

The primary contact would be my first try on implementing this, if you need/want to use the primary contact for other things then a new metafield for a contact guid can easily be added.

#191190
Apr 23, 2018 16:42
Vote:
 

I haven't implemented it (I hardly do except some quick dirty PoC), but I think this will work:

  • Intercept the IOrderRepository.Load(customerId, name).
  • Check if the customer belongs to an organization. If yes, load the cart belong to that organization primary contact. otherwise fall back to the default implementation.

Of course that would mean a customer belongs to a company will always access the organization's cart. If you want it to be case by case (personal cart, or company cart), then it will be much trickier. 

#191192
Apr 23, 2018 16:51
Vote:
 

Thanks for your feedback!

I rather not create organizations in Commerce database, these are stored elsewhere and I don't want to keep the different sources in sync, but I do already have an ID for the organization (not Commerce organization) stored on the cart (and order).

@Quan are there any reasons I still want to create an organization and primary contact in Commerce? I want to touch as few subsystems as possible, since we're not using organization to anything else.

@Erik regarding your second approach, I then have to update the organization with a new ID everytime a new cart is created. Seems error prone.

#191196
Apr 23, 2018 17:40
Vote:
 

You still need to map between customers and organization. You can implement that yourself if you don't like Business Foundation, but something is still needed.

#191198
Apr 23, 2018 19:27
Vote:
 

Why do I need to implement organizations in Commerce? From what I can see only contacts are connected to an OrderForm and they doesn't need to belong to an organization. In a B2C scenario, do you then need to implement organizations as well? That seems weird.

I was just thinking if there were any benefits implementing organizations in Commerce as well? I already know which "organization" a user/contact/customer belongs to and that is already stored on the cart by an extended property.

#191200
Apr 23, 2018 19:44
Vote:
 

Well, if you already have that information somehow, then you don't have to implement it. However for SerializableCart it'll be tricky to search for carts by metafields.

#191203
Apr 24, 2018 1:50
Vote:
 

Aha. Ok, so then we're back on square one :) I'm leaning towards my first approach then - sharing the same contact for everyone within the same organization. Not optimal.

This might be something for your backlog Quan, better API support for retrieving carts.

#191213
Apr 24, 2018 9:21
Vote:
 

We actually have something in backlog - an unified APIs for searching for carts. But it is still a long way to get there.

As always, too many things to do, too little time.

#191215
Apr 24, 2018 9:24
Vote:
 

However sharing carts between contacts seems to be a fairly common request. I'll see if we can do something about it. 

#191219
Apr 24, 2018 9:42
Vote:
 

A bit stunned that nobody else has run in to this issue... or maybe I'm just not able to find those threads.

#191220
Apr 24, 2018 9:42
Vote:
 

Not here, but in other internal channels. I said what I think will work (as above), but of course we might want to make thing easier from the framework. 

#191221
Apr 24, 2018 9:45
Vote:
 

I don't think I need to intercept any services. I just need to pass in the correct and same customerId (which should be named contactId, because that's what it is) for everyone within the same organization.

Thanks for you feedback!

#191224
Apr 24, 2018 10:16
Vote:
 

How's about the case for normal users? Well, if you don't have to handle that then it's much easier. Intercept is to make sure you can fallback to default behavior if you have company-users and private users, which is a fairly common scenario. 

#191225
Apr 24, 2018 10:20
Vote:
 

In this case all users belongs to an organization. If we would enable a B2C scenario I would imagine that it still would work, because then they would get their own contact and not share the same.

#191226
Apr 24, 2018 10:28
Vote:
 

It isn't mandatory to delete carts after placing an order, you can just clear the cart items and keep any additional info for the next time. Especially in a B2B case it could make sense to adopt that approach.

#191239
Apr 24, 2018 15:05
Vote:
 

Yepp, i do believe the customerId doesn't even have to be a contactId, that is there doesn't have to be a contact matching it. Because anonymous purchases gets a customerId guid as well.

You can store such an id in a custom metafield on contact as well. I suggested organization to avoid redundancy but if you have the organization info from another source you can skip it. Having an existing contact and organization in episerver would make order handling in episerver easier for the customer service/administrators, but i don't know if your case includes using episerver for those functions.

#191241
Apr 24, 2018 15:16
Vote:
 

Great input Erik. Thanks. Unfortunately our ID for organizations is not a guid. So I have to create a common contact anyway to get a guid.

#191246
Apr 24, 2018 16:28
Vote:
 

Or any form of mapping table organizationid=>guid that Quan mentioned earlier.

#191247
Apr 24, 2018 16:32
Vote:
 

If your organization ids are static and unique integers/longs you can even just build your own psuedo-guids from that identifier like 00000000-0000-0000-0000-000000001234.
A bit too quick and dirty maybe? :)

#191529
Apr 25, 2018 9:07
Vote:
 

Hehe, nice solution Patrick. They are indeed static but not sure which value type they are. We recieve them as strings from an ERP and eventually we will bring on more ERPs when we launch in more markets. So the type might change.

#191532
Apr 25, 2018 9:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.