Developer forum

Forum » Development » Show the Created Cart Function

Show the Created Cart Function

Rivan Chandra
Rivan Chandra
Reply

Hi,

I am trying to create the cart automatically after the order completed.

I succeeded to add the cart in admin site but the cart does not show in the front end and I already try to use setCart function.

The code is in the txt file and the result is in the picture.

Is there a way to show the cart in the front end?

Regards,

 

Rivan

admin.png cart.png

Replies

 
Jon Thorne
Jon Thorne
Reply

Hi,

Can anyone help with this issue?

We would like to create a cart programatically. This seems like it works fine, but we cannot seem to get it to replace the current users cart on the front end.

From what I have read this is supposed to do that:

Dynamicweb.Ecommerce.Common.Context.SetCart(newcart);

Even though this is already in the frontend user context we have also set this to ensure the correct context:

Dynamicweb.Security.UserManagement.User user = Dynamicweb.Security.UserManagement.User.GetUserByID(changedArgs.Order.CustomerAccessUserId);
Dynamicweb.Security.UserManagement.User.SetCurrentUser(PagePermissionLevels.Frontend, user);

Any suggestions would be appreciated.

Regards,

Jon.

 

 
Nicolai Pedersen
Reply

I am not sure I fully follow your flow.

Who creates the cart? - is another user - i.e.. User1 creates a cart that has to work for User2? Or is User1 creating a new cart that should work for him or her self?

If you need to create a cart for someone else, you can maybe do it using cart commands:

https://doc.dynamicweb.com/template-tags/introduction/ecommerce/cart-commands#sideNavTitle1-2-3

 
Jon Thorne
Jon Thorne
Reply

Hi Nicolai,

Thanks for respnding to this. There are a few scenarios. The first is that I need to create a cart on a recurring order trigger as a scheduled task. I managed to be able to do this, but not using an event but an external aspx file.

The one that I am confused about is the case where a user completes an order and I would like to recreate the cart and add a product automatically. So this is already in the correct user context using an event "Ecommerce.Order.State.Changed". We can see in the backend that the cart is created, and that is the only cart available for the user, it just does not show up for the user in the frontend. What is required to make that the active cart for the current user?

Yes, I could use the cart commands, but it seems a bit strange to have to call urls in the backend instead of using the API commands. I will do this if I have to in the end.

Regards,

Jon.

 
Nicolai Pedersen
Reply
This post has been marked as an answer

So you create a new cart on the receipt page?

That would probably not work very well since on the receipt page Dynamicweb will reset the cart. So you have to do that so late in the page cycle of the receipt that all of that has happened - i.e. on PageOutput notification subscriber.

BR Nicolai

Votes for this answer: 1
 
Jon Thorne
Jon Thorne
Reply

Thanks Nicolai. That was the issue. All working well now.

 

You must be logged in to post in the forum