Exemplo n.º 1
0
        public ActionResult Add(int id)
        {
            // Add the specified content id to the shopping cart with a quantity of 1.
            _shoppingCart.Add(id, 1);

            // Redirect the user to the Index action
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public void AddAChip_TotalIsOne()
        {
            // Arrange
            const int expectedTotal = 1;

            // Act
            _shoppingCart.Add(new Chips());
            var result = _shoppingCart.ItemCount;

            // Assert
            Assert.That(result, Is.EqualTo(expectedTotal));
        }
        public async Task <IActionResult> Item(string id, AddItemModel addItem)
        {
            _Logger.LogInformation($"starting to add item to cart {id}");

            Activity activity = new Activity("cart.put.item");

            activity.Start();

            if (string.IsNullOrEmpty(id))
            {
                id = _IdGenerator.New();
            }

            string actorType = "ShoppingCartActor";

            ActorId actorId = new ActorId(id);

            IShoppingCart cart = ActorProxy.Create <IShoppingCart>(actorId, actorType);

            await cart.Add(addItem.Id, addItem.Name, addItem.Quantity);

            activity.Stop();

            return(Ok());
        }
Exemplo n.º 4
0
        public ActionResult AddToCart(int wishListItemId, int wishListId, int quantity = 1)
        {
            WishListListPart wishList;

            if (_wishListServices.TryGetWishList(out wishList, wishListId))
            {
                if (wishList.Ids.Contains(wishListItemId))
                {
                    //these checks reduce the likelihood that we get here even though someone has tampered with the page.
                    var wishListItem = _contentManager.Get <WishListItemPart>(wishListItemId);
                    if (wishListItem != null)
                    {
                        _shoppingCart.Add(wishListItem.Item.ProductId, quantity, wishListItem.Item.AttributeIdsToValues);

                        var newItem = new ShoppingCartItem(
                            wishListItem.Item.ProductId, quantity, wishListItem.Item.AttributeIdsToValues);
                        foreach (var handler in _cartLifeCycleEventHandlers)
                        {
                            handler.ItemAdded(newItem);
                        }

                        return(RedirectToAction("Index", new { controller = "ShoppingCart" }));
                    }
                }
            }
            //in case we failed adding the product to the cart
            return(RedirectToAction("Index", new { id = wishList != null ? wishList.ContentItem.Id : 0 }));
        }
        public ActionResult Add(int id, int quantity = 1, bool isAjaxRequest = false)
        {
            // Manually parse product attributes because of a breaking change
            // in MVC 5 dictionary model binding
            var form              = HttpContext.Request.Form;
            var files             = HttpContext.Request.Files;
            var productattributes = form.AllKeys
                                    .Where(key => key.StartsWith(AttributePrefix))
                                    .ToDictionary(
                key => int.Parse(key.Substring(AttributePrefix.Length)),
                key => {
                var extensionProvider = _attributeExtensionProviders.SingleOrDefault(e => e.Name == form[ExtensionPrefix + key + ".provider"]);
                Dictionary <string, string> extensionFormValues = null;
                if (extensionProvider != null)
                {
                    extensionFormValues = form.AllKeys.Where(k => k.StartsWith(ExtensionPrefix + key + "."))
                                          .ToDictionary(
                        k => k.Substring((ExtensionPrefix + key + ".").Length),
                        k => form[k]);
                    return(new ProductAttributeValueExtended {
                        Value = form[key],
                        ExtendedValue = extensionProvider.Serialize(form[ExtensionPrefix + key], extensionFormValues, files),
                        ExtensionProvider = extensionProvider.Name
                    });
                }
                return(new ProductAttributeValueExtended {
                    Value = form[key],
                    ExtendedValue = null,
                    ExtensionProvider = null
                });
            });

            // Retrieve minimum order quantity
            var productPart = _contentManager.Get <ProductPart>(id);

            if (productPart != null)
            {
                if (quantity < productPart.MinimumOrderQuantity)
                {
                    quantity = productPart.MinimumOrderQuantity;
                }
            }

            _shoppingCart.Add(id, quantity, productattributes);

            _workflowManager.TriggerEvent("CartUpdated",
                                          _wca.GetContext().CurrentSite,
                                          () => new Dictionary <string, object> {
                { "Cart", _shoppingCart }
            });

            // Test isAjaxRequest too because iframe posts won't return true for Request.IsAjaxRequest()
            if (Request.IsAjaxRequest() || isAjaxRequest)
            {
                return(new ShapePartialResult(
                           this,
                           BuildCartShape(true, _shoppingCart.Country, _shoppingCart.ZipCode)));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        public void Adding_A_Valid_Product_Fire_Event()
        {
            // Setup our product so that it always returns true on a IsValid verification
            Mock <IProduct> product = new Mock <IProduct>();

            product.Setup(currentProduct => currentProduct.IsValid).Returns(true);

            // setup an event argument for our event
            ProductEventArgs productEventArgs = new ProductEventArgs(product.Object);

            // setup a mocked shopping cart to create our mocked event handler and a true shopping cart to test
            Mock <ShoppingCart> mockedShoppingCart = new Mock <ShoppingCart>();

            //creating the event a mocked event
            // Raising an event on the mock mock.Raise(m => m.FooEvent += null, new FooEventArgs(fooValue));
            // Causing an event to raise automatically when Submit is invoked mock.Setup(foo => foo.Submit()).Raises(f => f.Sent += null, EventArgs.Empty);
            //DEPRICATED MockedEvent<ProductEventArgs> mockedEvent = mockedShoppingCart.CreateEventHandler<ProductEventArgs>();
            //mockedShoppingCart.Object.ProductAdded += mockedEvent;
            mockedShoppingCart.Setup(shopping => shopping.Add(product.Object))
            .Raises(f => f.ProductAdded += null, new ProductEventArgs(product.Object))
            .Verifiable();

            //making the test
            IShoppingCart myShoppingCart = mockedShoppingCart.Object;

            myShoppingCart.Add(product.Object);

            mockedShoppingCart.Verify();
        }
 public ActionResult Add(int id, int quantity)
 {
     _shoppingCart.Add(id, quantity);
     if (Request.IsAjaxRequest())
     {
         return(new ShapePartialResult(this, BuildCartShape(true)));
     }
     return(RedirectToAction("Index"));
 }
        public async Task <IActionResult> Store(int id)
        {
            var product = await(from current in _context.Products
                                where current.Id == id
                                select current).FirstAsync();

            await _shoppingCart.Add(product);

            return(RedirectToAction("Index", "ShoppingCart"));
        }
 public ActionResult Add(int id)
 {
     _shoppingCart.Add(id, 1);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 10
0
 public static bool Add(ShoppingCartInfo shoppingcartinfo)
 {
     return(dal.Add(shoppingcartinfo));
 }
        public ActionResult Add(int id, int quantity = 1, bool isAjaxRequest = false)
        {
            // Manually parse product attributes because of a breaking change
            // in MVC 5 dictionary model binding
            var form              = HttpContext.Request.Form;
            var files             = HttpContext.Request.Files;
            var productattributes = form.AllKeys
                                    .Where(key => key.StartsWith(AttributePrefix))
                                    .ToDictionary(
                key => int.Parse(key.Substring(AttributePrefix.Length)),
                key => {
                var extensionProvider = _attributeExtensionProviders.SingleOrDefault(e => e.Name == form[ExtensionPrefix + key + ".provider"]);
                Dictionary <string, string> extensionFormValues = null;
                if (extensionProvider != null)
                {
                    extensionFormValues = form.AllKeys.Where(k => k.StartsWith(ExtensionPrefix + key + "."))
                                          .ToDictionary(
                        k => k.Substring((ExtensionPrefix + key + ".").Length),
                        k => form[k]);
                    return(new ProductAttributeValueExtended {
                        Value = form[key],
                        ExtendedValue = extensionProvider.Serialize(form[ExtensionPrefix + key], extensionFormValues, files),
                        ExtensionProvider = extensionProvider.Name
                    });
                }
                return(new ProductAttributeValueExtended {
                    Value = form[key],
                    ExtendedValue = null,
                    ExtensionProvider = null
                });
            });

            // Retrieve minimum order quantity
            Dictionary <int, List <string> > productMessages = new Dictionary <int, List <string> >();
            var    productPart  = _contentManager.Get <ProductPart>(id);
            string productTitle = _contentManager.GetItemMetadata(productPart.ContentItem).DisplayText;

            if (productPart != null)
            {
                if (quantity < productPart.MinimumOrderQuantity)
                {
                    quantity = productPart.MinimumOrderQuantity;
                    if (productMessages.ContainsKey(id))
                    {
                        productMessages[id].Add(T("Quantity increased to match minimum possible for {0}.", productTitle).Text);
                    }
                    else
                    {
                        productMessages.Add(id, new List <string>()
                        {
                            T("Quantity increased to match minimum possible for {0}.", productTitle).Text
                        });
                    }
                }
                //only add to cart if there are at least as many available products as the requested quantity
                if (quantity > productPart.Inventory && !productPart.AllowBackOrder &&
                    (!productPart.IsDigital || (productPart.IsDigital && productPart.ConsiderInventory))
                    )
                {
                    quantity = productPart.Inventory;
                    if (productMessages.ContainsKey(id))
                    {
                        productMessages[id].Add(T("Quantity decreased to match inventory for {0}.", productTitle).Text);
                    }
                    else
                    {
                        productMessages.Add(id, new List <string>()
                        {
                            T("Quantity decreased to match inventory for {0}.", productTitle).Text
                        });
                    }
                }
            }

            _shoppingCart.Add(id, quantity, productattributes);

            var newItem = new ShoppingCartItem(id, quantity, productattributes);

            foreach (var handler in _cartLifeCycleEventHandlers)
            {
                handler.ItemAdded(newItem);
            }

            // Test isAjaxRequest too because iframe posts won't return true for Request.IsAjaxRequest()
            if (Request.IsAjaxRequest() || isAjaxRequest)
            {
                return(new ShapePartialResult(
                           this,
                           BuildCartShape(true, _shoppingCart.Country, _shoppingCart.ZipCode, null, productMessages)));
            }
            return(RedirectToAction("Index", productMessages));
        }
Exemplo n.º 12
0
 public HttpResponseMessage Add(int id)
 {
     _shoppingCart.Add(id);
     return(Request.CreateResponse(HttpStatusCode.OK,
                                   new { Success = true }));
 }
Exemplo n.º 13
0
 public void ScanItemCode(string code) => _shoppingCart.Add(new CartItem(code));
Exemplo n.º 14
0
 public Task AddToCart(int itemId)
 {
     return(_cart.Add(itemId));
 }