Place order, clear Cart

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
How can Place order from cart and clear cart.
I want to do this in my own controller and not by checkout page.

I try to use this, but thats not work

//place order
                    var processPaymentRequest = HttpContext.Session.Get<ProcessPaymentRequest>("OrderPaymentInfo");
                    if (processPaymentRequest == null)
                    {
                        //Check whether payment workflow is required
                       if (_orderProcessingService.IsPaymentWorkflowRequired(cart))
                           return RedirectToRoute("CheckoutPaymentInfo");

                        processPaymentRequest = new ProcessPaymentRequest();
                    }
                    GenerateOrderGuid(processPaymentRequest);
                    processPaymentRequest.StoreId = _storeContext.CurrentStore.Id;
                    processPaymentRequest.CustomerId = _workContext.CurrentCustomer.Id;
                    processPaymentRequest.PaymentMethodSystemName = _genericAttributeService.GetAttribute<string>(_workContext.CurrentCustomer,
                        NopCustomerDefaults.SelectedPaymentMethodAttribute, _storeContext.CurrentStore.Id);
                    HttpContext.Session.Set<ProcessPaymentRequest>("OrderPaymentInfo", processPaymentRequest);
                    var placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest);
4 years ago
So this is code from nopCommerce42\Presentation\Nop.Web\Controllers\CheckoutController.cs and you have copied it into your controller
[quote=I try to use this, but thats not work[/quote]
What is the problem what does "thats not work" mean ?
4 years ago
Yes , i had copy some code from controllers. Code dont save anything to order, orderitems and i want also clear cart
4 years ago
I dont get any errors
4 years ago
Is your procedure being called ?
Are you using the VS debug to step through the program and see what is happening ?

Clearing the cart happens in MoveShoppingCartItemsToOrderItems
See nopCommerce42\Libraries\Nop.Services\Orders\OrderProcessingService.cs

            //clear shopping cart
            details.Cart.ToList().ForEach(sci => _shoppingCartService.DeleteShoppingCartItem(sci, false));
4 years ago
processPaymentRequest = null i think thats are problem.
How can i select paymentmethod in controller?
I use payment in page Cart, and dont use checkoutpage
4 years ago
Still same problem, but i find whats missing; processPaymentRequest.OrderGuid = Guid.NewGuid();
4 years ago
My problem was i had done wrong in; IPaymentMethod. Thats was reason
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.