Multi Store Support fro Nop 2.2- Store front

8 years ago
I'm about to finish the Multi store support
I have some problems that needs to be fixed, and help will be appreciated.

Store Demo On
http://demo22.online-ex.com

All is supported part for recurring payments, gift carts and stored procedures.

Orders:
Orders are being divided by stores. A shopping cart will be submitted as one and will be divided by stores.
An Order will be created to each store.

I have an error on One Page Checkout.
On confirm the JSON return success. for some reason, I am  being thrown to home page instead of CheckoutCompleted. please note that I am passing a new string to CheckoutCompleted  called successOrderList.

the thing is I dont get to OpcCompleteRedirectionPayment, The javascrip is throwing me to home page before and i can find where.

full solution http://demo22.online-ex.com/nop22MultiStore.rar


thank you
hezy
8 years ago
for those who does not want to download the full solution following the problem calss:

public ActionResult OpcConfirmOrder()
        {
            try
            {
                //validation
                var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
                if (cart.Count == 0)
                    throw new Exception("Your cart is empty");

                if (!_orderSettings.OnePageCheckoutEnabled)
                    throw new Exception("One page checkout is disabled");

                if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
                    throw new Exception("Anonymous checkout is not allowed");

                //add by hz
                string successOrderslist = "";
                var storeOrders = _storeService.getStoreSoppingCartItems(cart);
                //end by hz

                //place order
                var processPaymentRequest = this.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
                if (processPaymentRequest == null)
                {
                    //Check whether payment workflow is required
                    if (IsPaymentWorkflowRequired(cart))
                    {
                        throw new Exception("Payment information is not entered");
                    }
                    else
                        processPaymentRequest = new ProcessPaymentRequest();
                }

                processPaymentRequest.Customer = _workContext.CurrentCustomer;
                processPaymentRequest.PaymentMethodSystemName = _workContext.CurrentCustomer.SelectedPaymentMethodSystemName;

                //add by hz

                for (int i = 0; i < storeOrders.Count; i++)
                {
                    storeOrders[i].processPaymentRequest = processPaymentRequest;
                    storeOrders[i].placeOrderResult = _orderProcessingService.PlaceOrder(storeOrders[i]);
                    if (storeOrders[i].placeOrderResult.Success)
                    {
                        var postProcessPaymentRequest = new PostProcessPaymentRequest()
                        {
                            Order = storeOrders[i].placeOrderResult.PlacedOrder
                        };

                        var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(storeOrders[i].placeOrderResult.PlacedOrder.PaymentMethodSystemName);
                        if (paymentMethod == null)
                            throw new Exception("Payment method is not available"); //actually it's impossible
                        if (paymentMethod.PaymentMethodType == PaymentMethodType.Redirection)
                        {
                            //Redirection will not work because it's AJAX request.
                            //That's why we don't process it here (we redirect a user to another page where he'll be redirected)

                            //redirect
                            return Json(new { redirect = string.Format("{0}checkout/OpcCompleteRedirectionPayment", _webHelper.GetStoreLocation()) });
                        }
                        else
                        {
                            _paymentService.PostProcessPayment(postProcessPaymentRequest);
                            successOrderslist += storeOrders[i].placeOrderResult.PlacedOrder.Id.ToString();
                            if (i != storeOrders.Count - 1)
                                successOrderslist += ",";
                            else
                            {
                                //success
                                return Json(new { success = 1 });
                            }
                        }
                    }
                    else
                    {
                        //error
                        var confirmOrderModel = new CheckoutConfirmModel();
                        foreach (var error in storeOrders[i].placeOrderResult.Errors)
                            confirmOrderModel.Warnings.Add(error);

                        return Json(new
                        {
                            update_section = new UpdateSectionJsonModel()
                            {
                                name = "confirm-order",
                                html = RenderPartialViewToString("OpcConfirmOrder", confirmOrderModel)
                            },
                            goto_section = "confirm_order"
                        });
                    }
                }
            }
            catch (Exception exc)
            {
                _logger.Warning(exc.Message, exc, _workContext.CurrentCustomer);
                return Json(new { error = 1, message = exc.Message });
            }
            return null;
        }

after the return JSON i am getting thrown to home page
8 years ago
Any one? Them members please
8 years ago
Just tested your solution. You create and init 'successOrderslist' variable in 'OpcConfirmOrder' method. But it's never used and returned as JSON. That's why 'successOrderslist' parameter is never passed to 'Completed' method.

Look at \Scripts\onepagecheckout.js which is used during one-page checkout and investigate how it works. Instead of returning "return Json(new { success = 1 });" from  'OpcConfirmOrder' method do the following:
return Json(new { redirect = string.Format("{0}checkout/Completed?successOrderList={1}", _webHelper.GetStoreLocation(), successOrderList) });

P.S. I haven't tested it.
8 years ago
Thank You, I will try that
8 years ago
Thanks again Andrei, its working perfect
7 years ago
Would you be able to share your Multi Store solution please?
7 years ago
all code on codeplex

http://nopms25.codeplex.com/SourceControl/list/changesets

download the last changeset