Пример #1
0
        public ActionResult Index()
        {
            var receiptPage = _contentRepository.Get <ReceiptPage>(_siteConfiguration.GetSettings().ReceiptPage);

            var cartHelper = new CartHelper(Cart.DefaultName);

            if (cartHelper.IsEmpty && !PageEditing.PageIsInEditMode)
            {
                return(View("Error/_EmptyCartError"));
            }

            string         message        = "";
            OrderViewModel orderViewModel = null;

            if (cartHelper.Cart.OrderForms.Count > 0)
            {
                var orderNumber = cartHelper.Cart.GeneratePredictableOrderNumber();

                _log.Debug("Order placed - order number: " + orderNumber);

                cartHelper.Cart.OrderNumberMethod = CartExtensions.GeneratePredictableOrderNumber;

                var results = OrderGroupWorkflowManager.RunWorkflow(cartHelper.Cart, OrderGroupWorkflowManager.CartCheckOutWorkflowName);
                message = string.Join(", ", OrderGroupWorkflowManager.GetWarningsFromWorkflowResult(results));

                if (message.Length == 0)
                {
                    cartHelper.Cart.SaveAsPurchaseOrder();
                    cartHelper.Cart.Delete();
                    cartHelper.Cart.AcceptChanges();
                }

                var order = _orderService.GetOrderByTrackingNumber(orderNumber);

                // Must be run after order is complete,
                // This might release the order for shipment and
                // send the order receipt by email
                _paymentCompleteHandler.ProcessCompletedPayment(order, User.Identity);

                orderViewModel = new OrderViewModel(_currentMarket.GetCurrentMarket().DefaultCurrency.Format, order);
            }

            ReceiptViewModel model = new ReceiptViewModel(receiptPage);

            model.CheckoutMessage = message;
            model.Order           = orderViewModel;

            // Track successfull order in Google Analytics
            TrackAfterPayment(model);

            return(View("ReceiptPage", model));
        }
        public ActionResult ResetPassword(LoginPage currentPage, string token)
        {
            var service = ServiceLocator.Current.GetInstance <IResetPasswordService>();

            MembershipUser user;

            bool isResetUrlValid = service.IsResetUrlValid(token, out user);

            if (isResetUrlValid)
            {
                ResetPasswordViewModel model = new ResetPasswordViewModel(currentPage);
                model.Token             = token;
                model.ResetPasswordForm = new RegisterForm()
                {
                    Token    = token,
                    UserName = user.UserName
                };
                return(View(model));
            }
            else
            {
                // Token is invalid, we redirect to the login page
                string loginUrl = _urlResolver.GetUrl(_siteConfiguration.GetSettings().LoginPage);
                return(new RedirectResult(loginUrl));
            }
        }
        public ReceiptViewModel BuildFor(DibsPaymentProcessingResult processingResult)
        {
            var receiptPage = _contentRepository.Get <ReceiptPage>(_siteConfiguration.GetSettings().ReceiptPage);
            var model       = new ReceiptViewModel(receiptPage);

            model.CheckoutMessage = processingResult.Message;
            model.Order           = new OrderViewModel(_currentMarket.GetCurrentMarket().DefaultCurrency.Format, processingResult.Order);
            return(model);
        }
        /// <summary>
        /// Called before an action result executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            SettingsBlock settings = _siteConfiguration.GetSettings();

            // This can actually be null if we have a problem with our language settings
            if (settings != null)
            {
                var chrome = new Chrome();
                chrome.TopLeftMenu      = settings.TopLeftMenu;
                chrome.TopRightMenu     = settings.TopRightMenu;
                chrome.FooterMenu       = GetFooterMenuContent(settings);
                chrome.SocialMediaIcons = settings.SocialMediaIcons;
                chrome.FooterButtons    = settings.FooterButtons;
                chrome.LoginPage        = settings.LoginPage;
                chrome.AccountPage      = settings.AccountPage;

                chrome.CheckoutPage = settings.CheckoutPage;
                chrome.SearchPage   = settings.SearchPage;
                if (settings.LogoImage != null)
                {
                    chrome.LogoImageUrl = _urlResolver.GetUrl(settings.LogoImage);
                }
                else
                {
                    chrome.LogoImageUrl = new Url("/Content/Images/commerce-shop-logo.png");
                }

                // Set up languages for Chrome
                var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();
                var startPage     = contentLoader.Get <HomePage>(ContentReference.StartPage);
                chrome.Language  = startPage.LanguageBranch;
                chrome.Languages = GetLanguageInfo(startPage);

                filterContext.Controller.ViewBag.Chrome = chrome;
            }
        }
        public ActionResult Index()
        {
            var receiptPage = _contentRepository.Get <ReceiptPage>(_siteConfiguration.GetSettings().ReceiptPage);

            var cartHelper = new CartHelper(Cart.DefaultName);

            if (cartHelper.IsEmpty && !PageEditing.PageIsInEditMode)
            {
                return(View("Error/_EmptyCartError"));
            }

            string         message        = "";
            OrderViewModel orderViewModel = null;

            if (cartHelper.Cart.OrderForms.Count > 0)
            {
                var orderNumber = cartHelper.Cart.GeneratePredictableOrderNumber();

                _log.Debug("Order placed - order number: " + orderNumber);

                cartHelper.Cart.OrderNumberMethod = CartExtensions.GeneratePredictableOrderNumber;

                System.Diagnostics.Trace.WriteLine("Running Workflow: " + OrderGroupWorkflowManager.CartCheckOutWorkflowName);
                var results = OrderGroupWorkflowManager.RunWorkflow(cartHelper.Cart, OrderGroupWorkflowManager.CartCheckOutWorkflowName);
                message = string.Join(", ", OrderGroupWorkflowManager.GetWarningsFromWorkflowResult(results));

                if (message.Length == 0)
                {
                    var purchaseOrder = cartHelper.Cart.SaveAsPurchaseOrder();
                    cartHelper.Cart.Delete();
                    cartHelper.Cart.AcceptChanges();

                    // Track successfull order
                    //var trackingData = _trackingDataFactory.CreateOrderTrackingData(purchaseOrder, HttpContext);
                    //_trackingService.Send(trackingData, HttpContext, RetrieveRecommendationMode.Disabled);
                    _recommendationService.TrackOrder(purchaseOrder, HttpContext, CurrentPage);
                }

                System.Diagnostics.Trace.WriteLine("Loading Order: " + orderNumber);
                var order = _orderService.GetOrderByTrackingNumber(orderNumber);

                // Must be run after order is complete,
                // This might release the order for shipment and
                // send the order receipt by email
                System.Diagnostics.Trace.WriteLine(string.Format("Process Completed Payment: {0} (User: {1})", orderNumber, User.Identity.Name));
                _paymentCompleteHandler.ProcessCompletedPayment(order, User.Identity);

                orderViewModel = new OrderViewModel(_currentMarket.GetCurrentMarket().DefaultCurrency.Format, order);
            }

            ReceiptViewModel model = new ReceiptViewModel(receiptPage);

            model.CheckoutMessage = message;
            model.Order           = orderViewModel;

            // Track successfull order in Google Analytics
            TrackAfterPayment(model);

            _metricsLoggingService.Count("Purchase", "Purchase Success");
            _metricsLoggingService.Count("Payment", "Generic");

            return(View("ReceiptPage", model));
        }