Developer forum

Forum » Ecommerce - Standard features » Automatic activate the last created cart

Automatic activate the last created cart

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a solution where we allow the customer to create multiple carts. And we need to automatically set the last created cart as an active cart.

Is there any easy way to accomplish this? Maybe by adding an additional parameter to the call?

Or getting a "last added cart ID" as a response? Or as a tag?

Thank you,


Adrian


Replies

 
Nicolai Pedersen
Reply

Hi Adrian

All commands are fully up to date on the Cart Commands page - take a look at the Cart Management section - i.e. SetCart command: https://doc.dynamicweb.com/documentation-9/ecommerce/frontend/cart-commands#10191

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you. I have read them.

I don't see any explicit way of setting the last added cart as active.

The setcart command requires a CartID which I don't have before the cart is created.

Does this mean I don't have a way to set it active automatically upon creation? 

Thank you,

Adrian

 
Nicolai Pedersen
Reply

Hi Adrian

I do not understand your setup. But I am pretty sure you can use cart commands to create the carts and keep track of the latest cart id in a cookie or look it up on the database - carts/orders have a created timestamp you can use.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

It should be a straightforward approach. Users can create new carts and upon creation of the new cart, when the page refreshes, I should set the newly created cart as Active.

I am sure I can probably query it in the database but I was hoping for a more straightforward approach, like a tag similar to "LastProductAdded" or something like that.

I could surely save something in the cookie/session if that information is available. But since it is a new cart, I cannot predict the ID of the newly created cart, especially because there can be other users creating carts at the same time.

Thank you,

Adrian

 
Nicolai Pedersen
Reply

Hi Adrian

What you describe is exactly what is supported using the linked cart commands. If you use the Createnew cart command, a new cart is created and set as active...

https://doc.dynamicweb.com/documentation-9/ecommerce/frontend/cart-commands#10190

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Ok. I was not sure that's the behavior. We have used it to create the new cart but it seemed that the active cart is still the previously active cart.

My bad. I apologize. I will ask the developer to look for this behavior and adjust the implementation.

Thank you,
Adrian

 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

We have tested with the code from the documentation page and the new cart is created but it is not set as active.

We are using DW 9.8.4. Can this be a version issue?

From you, I understand that the expected behavior is to have the new cart set as active upon creation.

Thank you,
Adrian

 
Nicolai Pedersen
Reply

No, it is not a version issue - it is me remembering wrong. From the customer center you create carts - and from there you can also switch active cart using the setcartcommand.

You have to find a way using those commands to create the cart and set it active, or add a bit of custom code to achieve it.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for your answer.

I have no problem to add custom code. I just need to know if I can somehow get the latest added cart for the user or if I need to perform a database select.

Thank you,
Adrian

 

 
Nicolai Pedersen
Reply

Was that a re-question? You have to query the database if your flow does not handle this for you.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Ok. I will figure it out somehow.

Thank you,
Adrian

 

You must be logged in to post in the forum