Example #1
0
        public ActionResult AddToBasket(AddToBasketButtonAddToBasketViewModel viewModel)
        {
            var cartServiceProvider = new CartServiceProvider();

            var    contactFactory = new ContactFactory();
            string userId         = contactFactory.GetContact();

            var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId);

            var cart = cartServiceProvider.CreateOrResumeCart(createCartRequest).Cart;

            var cartProduct = new CartProduct
            {
                ProductId = viewModel.ProductSku,
                Price     = new Price(Convert.ToDecimal(viewModel.Price), cart.CurrencyCode)
            };

            cartProduct.Properties.Add("VariantSku", viewModel.VariantSku);

            var cartLines = new ReadOnlyCollection <CartLine>(
                new Collection <CartLine> {
                new CartLine
                {
                    Product  = cartProduct,
                    Quantity = (uint)viewModel.Quantity
                }
            }
                );

            var request = new AddCartLinesRequest(cart, cartLines);

            cartServiceProvider.AddCartLines(request);

            return(Json(_miniBasketService.Refresh(), JsonRequestBehavior.AllowGet));
        }
        public void AddToBasket_When_Data_Is_Valid_Should_Return_Json()
        {
            //Arrange
            var viewModel = new AddToBasketButtonAddToBasketViewModel
            {
                Quantity   = 1,
                ProductSku = "testsku123",
                VariantSku = "variantsku123"
            };

            //Act
            var result = _controller.AddToBasket(viewModel);

            //Assert
            _transactionLibraryInternal.Received().AddToBasket(viewModel.Quantity, viewModel.ProductSku, viewModel.VariantSku);
            var jsonResult = result as JsonResult;

            Assert.NotNull(jsonResult);
        }
        public ActionResult AddToBasket(AddToBasketButtonAddToBasketViewModel viewModel)
        {
            _transactionLibrary.AddToBasket(viewModel.Quantity, viewModel.ProductSku, viewModel.VariantSku);

            return(Json(_miniBasketService.Refresh(), JsonRequestBehavior.AllowGet));
        }