Developer forum

Forum » Development » Access OrderContext carts outside of Cart module

Access OrderContext carts outside of Cart module

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I need to be able to access the OrderContext carts outside of the Cart module, in Rapido.

Mainly, In the Minicart block. 

I would use the API for this purpose but I could not find a suitable way.

What I need is very basic information. I need to know if a cart on a specific ORDERCONTEXT has any products in it.

Any idea how to get this information?

Thank you,

Adrian


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Adrian,

You can use Dynamicweb.Ecommerce.Common.Context.CartContext to get the current order context.

- Jeppe

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Jeppe,

Thank you very much for the answer.

What about the content of a specific Context?

To put it into perspective, I have one order context where I add a specific type of products.

I need to be able to show in the minicart if I have products in either the new CartContext or the default cart context.

Right now, I can only access the current cart using Model.Cart or your suggestion.

How do I access a specific Context?

Thank you,
Adrian 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

There isn't really a good way to do that. I can only think of one way: 

  • Save a backup of the current CartContext
  • Get all contexts (OrderContext.GetOrderContexts())
  • Loop through them and set Dynamicweb.Ecommerce.Common.Context.CartContext for each
  • After setting the context, call Dynamicweb.Ecommerce.Common.Context.Cart to get the cart for that context
  • After looping, set the order context back to the backup

As you can see, this is very hacky, so I would not recommend it. However, I can't really see any other way of doing it with the current API. Also, this will give you the Cart (Dynamicweb.Ecommerce.Orders.Order) not the CartViewModel.

- Jeppe

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Jeppe,

Thank you very much.

This seems indeed hacky.

I will try the handlebars approach in this case. It will require some more development than what I was expecting but it seems the only way for now.

Maybe it would worth including a friendlier way of accessing the OrderContext in the upcoming versions.

Thank you very much for all your suggestions, they were very useful.

Thank you,

Adrian

 

You must be logged in to post in the forum