Esempio n. 1
0
        public HttpResponseMessage AddToCart(ItemCmdDTO item)
        {
            try
            {
                int       portalID      = PortalController.Instance.GetCurrentPortalSettings().PortalId;
                StoreInfo storeSettings = StoreController.GetStoreInfo(portalID);

                if (storeSettings.InventoryManagement && storeSettings.AvoidNegativeStock)
                {
                    ProductController controler      = new ProductController();
                    ProductInfo       currentProduct = controler.GetProduct(portalID, item.ID);

                    if (currentProduct.StockQuantity < item.Quantity)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Conflict, LocalizeString("NotEnoughProducts")));
                    }
                }

                CurrentCart.AddItem(portalID, storeSettings.SecureCookie, item.ID, item.Quantity);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("Unexpected.Error")));
            }
        }
Esempio n. 2
0
        protected void btnPayNow_Click(object sender, EventArgs e)
        {
            int orderID;

            if (Int32.TryParse(((Button)sender).CommandArgument, out orderID))
            {
                // Get order details
                List <OrderDetailInfo> details = _orderController.GetOrderDetails(orderID);
                if (details != null)
                {
                    bool secureCookies = StoreSettings.SecureCookie;
                    // Populate cart with order details
                    foreach (OrderDetailInfo detail in details)
                    {
                        CurrentCart.AddItem(PortalId, secureCookies, detail.ProductID, detail.Quantity);
                    }
                    // Set cookie and redirect to checkout page
                    SetOrderIdCookie(orderID);
                    _customerNav = new CustomerNavigation
                    {
                        PageID = "checkout"
                    };
                    Response.Redirect(_customerNav.GetNavigationUrl(), true);
                }
            }
        }
Esempio n. 3
0
      public RedirectToActionResult AddToCurrentCart(int productId, string returnUrl)
      {
          Product product = repository.Products
                            .FirstOrDefault(p => p.Id == productId);

          if (product != null)
          {
              CurrentCart currentCart = GetCurrentCart();
              currentCart.AddItem(product, 1);
              SaveCurrentCart(currentCart);
          }
          return(RedirectToAction("Index", new { returnUrl }));
      }
Esempio n. 4
0
        public async Task AddItemToCart(CartItemDTO item, Guid userId)
        {
            ShoppingCart CurrentCart = await _unit.Carts.GetCartByUserId(userId);

            if (CurrentCart is null)
            {
                CurrentCart = new ShoppingCart(userId);
                await _unit.Carts.CreateCart(CurrentCart);
            }

            CurrentCart.AddItem(_mapper.Map <CartItem>(item));

            _unit.Carts.Update(CurrentCart);
        }
Esempio n. 5
0
        private void AddToCart(int productID, int quantity, bool buyNow)
        {
            if (StoreSettings.InventoryManagement && StoreSettings.AvoidNegativeStock)
            {
                ProductController controler      = new ProductController();
                ProductInfo       currentProduct = controler.GetProduct(PortalId, productID);

                if (currentProduct.StockQuantity < quantity)
                {
                    lblError.Text    = Localization.GetString("DetaiNotEnoughProductslsSEOTitle", LocalResourceFile);
                    divError.Visible = true;
                    return;
                }
            }
            CurrentCart.AddItem(PortalId, StoreSettings.SecureCookie, productID, quantity);
            if (buyNow)
            {
                _catalogNav = new CatalogNavigation
                {
                    TabID = StoreSettings.ShoppingCartPageID
                };
            }
            Response.Redirect(_catalogNav.GetNavigationUrl());
        }
Esempio n. 6
0
 public void AddToCart(IMediaDetail detail)
 {
     CurrentCart.AddItem(detail);
 }