Developer forum

Forum » Development » Create order and empty cart in razor

Create order and empty cart in razor

Aki Ruuskanen
Reply

Hi,

I'm trying to create an order and empty the cart in a paragraphtemplate using razor. I can create the order but i'm not sure how to empty the cart after the order is created. 

My code is something like this:

    order.ShopID = "SHOP1";
    order.CustomerName = name;
    order.CustomerCompany = company;
    order.Complete = true;
    order.CompletedDate = DateTime.Now;
    order.IsCart = false;
    order.UpdateCartToOrder();
    order.Save();

It creates the order. But I don't know how to (easiest way) to also empty the cart. 

Any ideas?

Regards / Aki


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Aki

I do not understand. When you create the cart, it is empty...? Our empty cart code, deletes the order object, send notifications and clears the cart from session and the user...

You can do the same by calling Order.Delete and then Dynamicweb.Ecommerce.Frontend.Cart.CatchCart.ClearCart();

If you want to override the existing cart, set Common.Context.Cart() to your new order object...

Votes for this answer: 1
 
Aki Ruuskanen
Reply

Thanks dude. You managed to solve even though you didn't understand. :)

"Dynamicweb.Ecommerce.Frontend.Cart.CatchCart.ClearCart()" was what I was looking for. I tried to find something like it in the API but did not look there. 

The reason for this odd way to do is that we are working with the templateframework "handlebars.net" in this project and basically gather and bundle data into json in our razor templates and send them to handlebars templates for the html rendering. So I have very little control over how for example name attributes for input tags are generated. And the checkout process is a bunch of modal windows with asynchrous and bla bla....   :)

 

 
Nicolai Høeg Pedersen
Reply

Rendering with rendering. Nice... Poor customer :-).

 
Aki Ruuskanen
Reply

Hehe.  :)

There are actually good reasons for this "hybrid" solution. 

/Aki

 

You must be logged in to post in the forum