Developer forum

Forum » Ecommerce - Standard features » Access context cart outside of cart page.

Access context cart outside of cart page.

Bjørn Kamfjord
Reply

On my site I have an extra order context. How can I on any page target the specific cart and look up how many items there is in the cart?

For the "regular" cart you have the template tag: Ecom:Order.OrderLines.TotalQuantity, can I somehow target a different cart with this, or do I need to make a new provider?

I want to be able to show on any page the amount of products in BOTH carts...


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Bjørn,

You should be able to use the OrderContextCarts loop for that.

Have a look at this thread: Total amount of products in a context cart.

Best regards,
Morten

 

 
Bjørn Kamfjord
Reply

Thanks. But it doesn't really work. Wince I'm using an Ajax to load the page, for some reason the TemplateTag is not working. It works if I put it on another regular page...

Is this a bug? I can access the API, where would I find the ContecxtOrder cart product quantity?

Link to site. http://egwbp-apw-test.azurewebsites.net/preorder

 
Nicolai Pedersen
Reply

Hi Bjørn

It works - it could be something on your ajax page, but you have to debug that your self.

You can access the contexts in the API: https://doc.dynamicweb.com/api/html/c3a50dd6-3679-4380-8380-309802417903.htm

BR Nicolai

 
Bjørn Kamfjord
Reply

Hi Nicolai, I'm trying very hard to get hold of the current ContextCart, but I can't find the cart.

I use this:
    var test2 = Dynamicweb.Ecommerce.Common.Context.Cart.TotalPriceWithoutVatFormatted; but it returns the "default" cart content, not the context cart.

How can I set it to access the content of a context cart ?

I can find the different context with Dynamicweb.Ecommerce.Orders.OrderContext.GetOrderContexts(); but not sure how to get theese two together to list out the products in the context cart?

 

 
Nicolai Pedersen
Reply

ok, try this:

Common.Context.CartContext = context
Order contextCart = Common.Context.Cart

 
Bjørn Kamfjord
Reply

Thanks. But with the risk of looking like a total n00b, but with all fairness I am, how do I do the code you are suggesting?

Can someone give me a quick code example? 

 

You must be logged in to post in the forum