Esempio n. 1
0
        public async Task <ActionResult> Index(CartPage currentPage)
        {
            var messages = string.Empty;

            if (TempData[Constant.Quote.RequestQuoteStatus] != null)
            {
                var requestQuote = (bool)TempData[Constant.Quote.RequestQuoteStatus];
                if (requestQuote)
                {
                    ViewBag.QuoteMessage = "Request quote successfully";
                }
                else
                {
                    ViewBag.ErrorMessage = "Request quote unsuccessfully";
                }
            }

            if (CartWithValidationIssues.Cart != null && CartWithValidationIssues.ValidationIssues.Any())
            {
                foreach (var item in CartWithValidationIssues.Cart.GetAllLineItems())
                {
                    messages = GetValidationMessages(item, CartWithValidationIssues.ValidationIssues);
                }
            }

            var viewModel = _cartViewModelFactory.CreateLargeCartViewModel(CartWithValidationIssues.Cart, currentPage);

            viewModel.Message = messages;
            var trackingResponse = await _recommendationService.TrackCart(HttpContext, CartWithValidationIssues.Cart);

            //viewModel.Recommendations = trackingResponse.GetCartRecommendations(_referenceConverter);
            return(View("LargeCart", viewModel));
        }
        public async Task <ActionResult> Index(CartPage currentPage)
        {
            var messages = string.Empty;

            if (CartWithValidationIssues.Cart != null && CartWithValidationIssues.ValidationIssues.Any())
            {
                foreach (var item in CartWithValidationIssues.Cart.GetAllLineItems())
                {
                    messages = GetValidationMessages(item, CartWithValidationIssues.ValidationIssues);
                }
            }

            var viewModel = _cartViewModelFactory.CreateLargeCartViewModel(CartWithValidationIssues.Cart, currentPage);

            viewModel.Message = messages;
            var trackingResponse = await _recommendationService.TrackCart(HttpContext, CartWithValidationIssues.Cart);

            //viewModel.Recommendations = trackingResponse.GetCartRecommendations(_referenceConverter);
            return(View("LargeCart", viewModel));
        }
Esempio n. 3
0
        public async Task <ActionResult> AddAllToCart()
        {
            var allLineItem        = WishList.Cart.GetAllLineItems();
            var entriesAddedToCart = true;
            var validationMessage  = "";

            if (Cart.Cart == null)
            {
                _cart = new CartWithValidationIssues
                {
                    Cart             = _cartService.LoadOrCreateCart(_cartService.DefaultCartName),
                    ValidationIssues = new Dictionary <ILineItem, List <ValidationIssue> >()
                };
            }

            foreach (var lineitem in allLineItem)
            {
                var result = _cartService.AddToCart(Cart.Cart,
                                                    new RequestParamsToCart {
                    Code = lineitem.Code, Quantity = lineitem.Quantity, Store = "delivery", SelectedStore = "", DynamicCodes = lineitem.Properties["VariantOptionCodes"]?.ToString().Split(',').ToList()
                });
                entriesAddedToCart &= result.EntriesAddedToCart;
                validationMessage  += result.GetComposedValidationMessage();
            }

            if (entriesAddedToCart)
            {
                _orderRepository.Save(Cart.Cart);
                await _trackingService.TrackCart(HttpContext, Cart.Cart);

                return(Json(new ChangeCartJsonResult
                {
                    StatusCode = 1,
                    Message = "Add all LineItems from the wishlist to the cart.",
                    CountItems = (int)Cart.Cart.GetAllLineItems().Sum(x => x.Quantity),
                }));
            }

            return(new HttpStatusCodeResult(500, validationMessage));
        }
        public async Task <ActionResult> GetRecommendations(string widgetType, string name, string value = "", int numberOfRecs = 4)
        {
            if (string.IsNullOrEmpty(widgetType) || PageEditing.PageIsInEditMode)
            {
                return(new EmptyResult());
            }

            List <Recommendation> recommendations = null;
            TrackingResponseData  response;

            switch (widgetType)
            {
            case "Home":
                response = await _trackingService.TrackHome(ControllerContext.HttpContext);

                recommendations = response.GetRecommendations(_referenceConverter, RecommendationsExtensions.Home)
                                  .ToList();
                break;

            case "Basket":
                response = await _trackingService.TrackCart(ControllerContext.HttpContext, _cartService.LoadCart(_cartService.DefaultCartName, false).Cart);

                recommendations = response.GetRecommendations(_referenceConverter, RecommendationsExtensions.Basket)
                                  .ToList();
                break;

            case "Checkout":
                response = await _trackingService.TrackCheckout(ControllerContext.HttpContext);

                recommendations = response.GetRecommendations(_referenceConverter, "Checkout")
                                  .ToList();
                break;

            case "Wishlist":
                response = await _trackingService.TrackWishlist(ControllerContext.HttpContext);

                recommendations = response.GetRecommendations(_referenceConverter, "Wishlist")
                                  .ToList();
                break;

            case "Order":
                IPurchaseOrder order = null;
                if (PageEditing.PageIsInEditMode)
                {
                    break;
                }
                if (int.TryParse(ControllerContext.HttpContext.Request.QueryString["orderNumber"], out var orderNumber))
                {
                    order = _confirmationService.GetOrder(orderNumber);
                }
                if (order == null)
                {
                    break;
                }
                response = await _trackingService.TrackOrder(ControllerContext.HttpContext, order);

                recommendations = response.GetRecommendations(_referenceConverter, "orderWidget")
                                  .ToList();
                break;

            default:
                response = await _trackingService.TrackAttribute(ControllerContext.HttpContext, name, value);

                recommendations = response.GetRecommendations(_referenceConverter, "attributeWidget")
                                  .ToList();
                break;
            }

            if (recommendations == null)
            {
                return(new EmptyResult());
            }
            recommendations = recommendations.Take(numberOfRecs).ToList();

            return(PartialView("/Features/Recommendations/Index.cshtml", _productService.GetRecommendedProductTileViewModels(recommendations)));
        }