コード例 #1
0
        public JsonResult SubmitOrder(SubmitOrderInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, "inputModel");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var response = this.OrderManager.SubmitVisitorOrder(CurrentStorefront, CurrentVisitorContext, inputModel);
                var result   = new SubmitOrderBaseJsonResult(response.ServiceProviderResult);
                if (!response.ServiceProviderResult.Success || response.Result == null || response.ServiceProviderResult.CartWithErrors != null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.Initialize(string.Concat(StorefrontManager.StorefrontUri("checkout/OrderConfirmation"), "?confirmationId=", (response.Result.TrackingNumber)));
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("SubmitOrder", this, e);
                return(Json(new BaseJsonResult("SubmitOrder", e), JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public JsonResult SubmitOrder(SubmitOrderInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, nameof(inputModel));
                if (String.IsNullOrEmpty(inputModel.UserEmail))
                {
                    inputModel.UserEmail = Request.Cookies["email"]?.Value;
                }

                var validationResult = this.CreateJsonResult();
                var response         = OrderManager.SubmitVisitorOrder(CommerceUserContext.Current.UserId, inputModel);
                var result           = new SubmitOrderApiModel(response.ServiceProviderResult);
                if (!response.ServiceProviderResult.Success || response.Result == null || response.ServiceProviderResult.CartWithErrors != null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.Initialize($"checkout/OrderConfirmation?{ConfirmationIdQueryString}={response.Result.OrderID}");
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new ErrorApiModel("SubmitOrder", e), JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        public SubmitOrderBaseJsonResult SubmitOrder(SubmitOrderInputModel inputModel)
        {
            var response = this._orderManager.SubmitVisitorOrder(CurrentStorefront, CurrentVisitorContext, inputModel);
            var result   = new SubmitOrderBaseJsonResult(response.ServiceProviderResult);

            if (response.ServiceProviderResult.Success && response.Result != null && response.ServiceProviderResult.CartWithErrors == null)
            {
                result.Initialize(string.Concat(StorefrontManager.StorefrontUri("checkout/OrderConfirmation"), "?confirmationId=", (response.Result.TrackingNumber)));
            }

            return(result);
        }
        public JsonResult SubmitOrder(SubmitOrderInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, "inputModel");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);

                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var result = _checkoutRepository.SubmitOrder(inputModel);

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                _logger.LogError("SubmitOrder", this, e);
                return(Json(new BaseJsonResult("SubmitOrder", e), JsonRequestBehavior.AllowGet));
            }
        }
        /// <summary>
        /// Submits the visitor order.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="inputModel">The input model.</param>
        /// <returns>
        /// The manager response where the new CommerceOrder is returned in the Result.
        /// </returns>
        public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder([NotNull] CommerceStorefront storefront, [NotNull] IVisitorContext visitorContext, [NotNull] SubmitOrderInputModel inputModel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNull(inputModel, "inputModel");

            SubmitVisitorOrderResult errorResult = new SubmitVisitorOrderResult {
                Success = false
            };

            var response = this._cartManager.GetCurrentCart(storefront, visitorContext, true);

            if (!response.ServiceProviderResult.Success || response.Result == null)
            {
                response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m));
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var cart = (CommerceCart)response.ServiceProviderResult.Cart;

            if (cart.Lines.Count == 0)
            {
                errorResult.SystemMessages.Add(new SystemMessage {
                    Message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.SubmitOrderHasEmptyCart)
                });
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var cartChanges = new CommerceCart();

            cartChanges.Properties["Email"] = inputModel.UserEmail;

            var updateCartResult = this._cartManager.UpdateCart(storefront, visitorContext, cart, cartChanges);

            if (!updateCartResult.ServiceProviderResult.Success)
            {
                response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m));
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var request = new SubmitVisitorOrderRequest(cart);

            request.RefreshCart(true);
            errorResult = this._orderServiceProvider.SubmitVisitorOrder(request);
            if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null)
            {
                var cartCache = ContextTypeLoader.CreateInstance <CartCacheHelper>();
                cartCache.InvalidateCartCache(visitorContext.GetCustomerId());
            }

            //Helpers.LogSystemMessages(errorResult.SystemMessages, errorResult);
            return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, errorResult.Order as CommerceOrder));
        }
コード例 #6
0
        public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder(string userId, SubmitOrderInputModel inputModel)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));

            var errorResult = new SubmitVisitorOrderResult {
                Success = false
            };

            var response = CartManager.GetCart(userId, true);

            if (!response.ServiceProviderResult.Success || response.Result == null)
            {
                response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m));
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            var cart = (CommerceCart)response.ServiceProviderResult.Cart;

            if (cart.Lines.Count == 0)
            {
                errorResult.SystemMessages.Add(new SystemMessage
                {
                    Message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Submit Order Has Empty Cart", "Cannot submit and order with an empty cart.")
                });
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null));
            }

            cart.Email = inputModel.UserEmail;

            var payments = new List <PaymentInfo>();

            if (inputModel.FederatedPayment != null && !string.IsNullOrEmpty(inputModel.FederatedPayment.CardToken))
            {
                payments.Add(ToCreditCardPaymentInfo(inputModel.FederatedPayment));
            }

            if (inputModel.GiftCardPayment != null && !string.IsNullOrEmpty(inputModel.GiftCardPayment.PaymentMethodID))
            {
                payments.Add(ToGiftCardPaymentInfo(inputModel.GiftCardPayment));
            }

            //if (inputModel.LoyaltyCardPayment != null && !string.IsNullOrEmpty(inputModel.LoyaltyCardPayment.PaymentMethodID))
            //{
            //    payments.Add(ToLoyaltyCardPaymentInfo(inputModel.LoyaltyCardPayment));
            //}

            cart.Payment = payments.ToList().AsReadOnly();

            var request = new Sitecore.Commerce.Connect.DynamicsRetail.Services.Orders.SubmitVisitorOrderRequest(cart, cart.Email);

            RefreshCartOnOrdersRequest(request);
            errorResult = OrderServiceProvider.SubmitVisitorOrder(request);
            if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null)
            {
                CartCacheHelper.InvalidateCartCache(userId);

                try
                {
                    var wasEmailSent = MailManager.SendMail("PurchaseConfirmation", inputModel.UserEmail, string.Join(" ", cart.Parties.FirstOrDefault()?.FirstName, cart.Parties.FirstOrDefault()?.LastName), errorResult.Order.TrackingNumber, errorResult.Order.OrderDate, string.Join(", ", cart.Lines.Select(x => x.Product.ProductName)), cart.Total.Amount.ToCurrency(cart.Total.CurrencyCode));
                    if (!wasEmailSent)
                    {
                        var message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Could Not Send Email Error", "Sorry, the email could not be sent");
                        //errorResult.SystemMessages.Add(new SystemMessage(message));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Could not send Purchase Confirmation mail message", ex, this);
                    var message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Could Not Send Email Error", "Sorry, the email could not be sent");
                    errorResult.SystemMessages.Add(new SystemMessage(message));
                }
            }

            errorResult.WriteToSitecoreLog();
            return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult,
                                                                                 errorResult.Order as CommerceOrder));
        }
コード例 #7
0
        public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] SubmitOrderInputModel inputModel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNull(inputModel, "inputModel");

            SubmitVisitorOrderResult result = new SubmitVisitorOrderResult {
                Success = false
            };
            var response = this.CartManager.GetCurrentCart(storefront, visitorContext, true);

            if (!response.ServiceProviderResult.Success || response.Result == null)
            {
                result.SystemMessages.ToList().AddRange(response.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(result, null));
            }

            var cart = (CommerceCart)response.ServiceProviderResult.Cart;

            if (cart.Lines.Count == 0)
            {
                result.SystemMessages.Add(new SystemMessage {
                    Message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.SubmitOrderHasEmptyCart)
                });
                return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(result, null));
            }

            // payments and billing address will be save as part of submit order
            var payments = new List <PaymentInfo>();

            if (inputModel.CreditCardPayment != null && !string.IsNullOrEmpty(inputModel.CreditCardPayment.PaymentMethodID) && inputModel.BillingAddress != null)
            {
                payments.Add(inputModel.CreditCardPayment.ToCreditCardPaymentInfo());
                List <Party> parties = cart.Parties.ToList();
                parties.Add(inputModel.BillingAddress.ToParty());
                cart.Parties = parties.AsSafeReadOnly();
            }

            if (inputModel.GiftCardPayment != null && !string.IsNullOrEmpty(inputModel.GiftCardPayment.PaymentMethodID))
            {
                payments.Add(inputModel.GiftCardPayment.ToGiftCardPaymentInfo());
            }

            if (inputModel.LoyaltyCardPayment != null && !string.IsNullOrEmpty(inputModel.LoyaltyCardPayment.PaymentMethodID))
            {
                payments.Add(inputModel.LoyaltyCardPayment.ToLoyaltyCardPaymentInfo());
            }

            cart.Payment = payments.ToList().AsReadOnly();

            var request = new Sitecore.Commerce.Connect.DynamicsRetail.Services.Orders.SubmitVisitorOrderRequest(cart, inputModel.UserEmail);

            request.RefreshCart(true);
            result = this.OrderServiceProvider.SubmitVisitorOrder(request);
            if (result.Success && result.Order != null && result.CartWithErrors == null)
            {
                var cartCache = CommerceTypeLoader.CreateInstance <CartCacheHelper>();
                cartCache.InvalidateCartCache(visitorContext.GetCustomerId());
            }

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(result, result.Order as CommerceOrder));
        }
 public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder(CommerceStorefront storefront, IVisitorContext visitorContext, SubmitOrderInputModel inputModel)
 {
     return(null);
 }