예제 #1
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));
        }
예제 #2
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("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);
        }