Exemplo n.º 1
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            foreach (RepeaterItem item in rptShoppingCart.Items)
            {
                var lblShoppingCartItemId = item.FindControl("lblShoppingCartItemId") as Label;
                var cbAddToCart           = item.FindControl("cbAddToCart") as CheckBox;

                int shoppingCartItemId = 0;
                if (lblShoppingCartItemId != null && cbAddToCart != null)
                {
                    int.TryParse(lblShoppingCartItemId.Text, out shoppingCartItemId);
                    if (cbAddToCart.Checked)
                    {
                        var sci = ShoppingCartManager.GetShoppingCartItemById(shoppingCartItemId);
                        if (sci != null)
                        {
                            ShoppingCartManager.AddToCart(
                                ShoppingCartTypeEnum.ShoppingCart,
                                sci.ProductVariantId,
                                sci.AttributesXml,
                                sci.CustomerEnteredPrice,
                                sci.Quantity);
                        }
                    }
                }
            }

            Response.Redirect("~/shoppingcart.aspx");
        }
Exemplo n.º 2
0
        protected void btnAddToCart_Click(object sender, CommandEventArgs e)
        {
            int productID        = Convert.ToInt32(e.CommandArgument);
            int productVariantID = 0;

            if (ProductManager.DirectAddToCartAllowed(productID, out productVariantID))
            {
                List <string> addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                                                                                productVariantID, string.Empty, 1);
                if (addToCartWarnings.Count == 0)
                {
                    Response.Redirect("~/ShoppingCart.aspx");
                }
                else
                {
                    string productURL = SEOHelper.GetProductURL(productID);
                    Response.Redirect(productURL);
                }
            }
            else
            {
                string productURL = SEOHelper.GetProductURL(productID);
                Response.Redirect(productURL);
            }
        }
Exemplo n.º 3
0
        protected void lbOrderAndCheckout_Click(object sender, CommandEventArgs e)
        {
            int productID = Convert.ToInt32(e.CommandArgument);
            int productVariantID = 0;
            if (ProductManager.DirectAddToCartAllowed(productID, out productVariantID))
                ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart, productVariantID, string.Empty, 1);

            Response.Redirect("/ShoppingCart.aspx");
        }
Exemplo n.º 4
0
        public ActionResult AddToCart(int id)
        {
            ShoppingCartManager shoppingCart = new ShoppingCartManager(this.sessionManager, this.db);

            shoppingCart.AddToCart(id);



            return(RedirectToAction("Index", "Cart"));
        }
Exemplo n.º 5
0
        public ActionResult AddToCart(int id)
        {
            ShoppingCartManager shoppingCart = new ShoppingCartManager(this.sessionManager, this.db);

            shoppingCart.AddToCart(id);

            logger.Info("Added product {0} to cart", id);

            //return Json("Index", JsonRequestBehavior.AllowGet);
            return(RedirectToAction("Index", "Cart"));
        }
Exemplo n.º 6
0
        protected void btnAddToCart_Click(object sender, CommandEventArgs e)
        {
            int productId        = Convert.ToInt32(e.CommandArgument);
            int productVariantId = 0;

            if (ProductManager.DirectAddToCartAllowed(productId, out productVariantId))
            {
                var addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                                                                      productVariantId, string.Empty, decimal.Zero, 1);
                if (addToCartWarnings.Count == 0)
                {
                    bool displayCart = true;
                    if (this.RedirectCartAfterAddingProduct.HasValue)
                    {
                        displayCart = this.RedirectCartAfterAddingProduct.Value;
                    }
                    else
                    {
                        displayCart = SettingManager.GetSettingValueBoolean("Display.Products.DisplayCartAfterAddingProduct");
                    }

                    if (displayCart)
                    {
                        //redirect to shopping cart page
                        Response.Redirect(SEOHelper.GetShoppingCartUrl());
                    }
                    else
                    {
                        //display notification message
                        this.DisplayAlertMessage(GetLocaleResourceString("Products.ProductHasBeenAddedToTheCart"));
                    }
                }
                else
                {
                    string productURL = SEOHelper.GetProductUrl(productId);
                    Response.Redirect(productURL);
                }
            }
            else
            {
                string productURL = SEOHelper.GetProductUrl(productId);
                Response.Redirect(productURL);
            }
        }
Exemplo n.º 7
0
 protected void ddlVariantPrice_ItemCommand(object source, DataListCommandEventArgs e)
 {
     if (e.CommandName == "AddToCart")
     {
         var pv = ProductManager.GetProductVariantById(Convert.ToInt32(e.CommandArgument.ToString()));
         if (pv == null)
         {
             return;
         }
         Label   lblPrice = e.Item.FindControl("lblPrice") as Label;
         var     ctrlProductAttributes = e.Item.FindControl("ctrlProductAttributes") as ProductAttributesControl;
         decimal price;
         if (decimal.TryParse(lblPrice.Text, out price))
         {
             string        attributes        = ctrlProductAttributes.SelectedAttributes;
             List <string> addToCartWarnings = ShoppingCartManager.AddToCart(
                 ShoppingCartTypeEnum.ShoppingCart,
                 pv.ProductVariantId,
                 attributes,
                 price,
                 1);
             if (addToCartWarnings.Count == 0)
             {
                 Response.Redirect("~/shoppingcart.aspx");
             }
             else
             {
                 string productURL = SEOHelper.GetProductUrl(Product.ProductId);
                 Response.Redirect(productURL);
             }
         }
         else
         {
             string productURL = SEOHelper.GetProductUrl(Product.ProductId);
             Response.Redirect(productURL);
         }
     }
 }
 public ActionResult AddToCart(int id)
 {
     shoppingCartManager.AddToCart(id);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 9
0
        protected void rptVariants_OnItemCommand(Object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart" || e.CommandName == "AddToWishlist")
            {
                var txtQuantity             = e.Item.FindControl("txtQuantity") as NumericTextBox;
                var txtCustomerEnteredPrice = e.Item.FindControl("txtCustomerEnteredPrice") as NumericTextBox;
                var productVariantId        = e.Item.FindControl("ProductVariantId") as Label;
                var ctrlProductAttributes   = e.Item.FindControl("ctrlProductAttributes") as ProductAttributesControl;
                var txtRecipientName        = e.Item.FindControl("txtRecipientName") as TextBox;
                var txtRecipientEmail       = e.Item.FindControl("txtRecipientEmail") as TextBox;
                var txtSenderName           = e.Item.FindControl("txtSenderName") as TextBox;
                var txtSenderEmail          = e.Item.FindControl("txtSenderEmail") as TextBox;
                var txtGiftCardMessage      = e.Item.FindControl("txtGiftCardMessage") as TextBox;
                var lblError = e.Item.FindControl("lblError") as Label;

                var pv = ProductManager.GetProductVariantById(Convert.ToInt32(productVariantId.Text));
                if (pv == null)
                {
                    return;
                }

                string  attributes                    = ctrlProductAttributes.SelectedAttributes;
                decimal customerEnteredPrice          = txtCustomerEnteredPrice.Value;
                decimal customerEnteredPriceConverted = CurrencyManager.ConvertCurrency(customerEnteredPrice, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                int     quantity = txtQuantity.Value;

                //gift cards
                if (pv.IsGiftCard)
                {
                    string recipientName   = txtRecipientName.Text;
                    string recipientEmail  = txtRecipientEmail.Text;
                    string senderName      = txtSenderName.Text;
                    string senderEmail     = txtSenderEmail.Text;
                    string giftCardMessage = txtGiftCardMessage.Text;

                    attributes = ProductAttributeHelper.AddGiftCardAttribute(attributes,
                                                                             recipientName, recipientEmail, senderName, senderEmail, giftCardMessage);
                }

                try
                {
                    if (e.CommandName == "AddToCart")
                    {
                        string        sep = "<br />";
                        List <string> addToCartWarnings = ShoppingCartManager.AddToCart(
                            ShoppingCartTypeEnum.ShoppingCart,
                            pv.ProductVariantId,
                            attributes,
                            customerEnteredPriceConverted,
                            quantity);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect("~/shoppingcart.aspx");
                        }
                        else
                        {
                            StringBuilder addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append(sep);
                                }
                            }
                            string errorFull = addToCartWarningsSb.ToString();
                            lblError.Text = errorFull;
                            if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                            {
                                this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                            }
                        }
                    }

                    if (e.CommandName == "AddToWishlist")
                    {
                        string sep = "<br />";
                        var    addToCartWarnings = ShoppingCartManager.AddToCart(
                            ShoppingCartTypeEnum.Wishlist,
                            pv.ProductVariantId,
                            attributes,
                            customerEnteredPriceConverted,
                            quantity);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect("~/wishlist.aspx");
                        }
                        else
                        {
                            var addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append(sep);
                                }
                            }
                            string errorFull = addToCartWarningsSb.ToString();
                            lblError.Text = errorFull;
                            if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                            {
                                this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.CustomerError, exc.Message, exc);
                    lblError.Text = Server.HtmlEncode(exc.Message);
                }
            }
        }
 //id ident produktu który chcemy dodac
 public ActionResult AddToCart(int id)
 {
     shoppingCartManager.AddToCart(id);
     //gdy uzytokownik wywola akcje addtocart do trafi do akcji index
     return(RedirectToAction("Index"));
 }
Exemplo n.º 11
0
        protected void rptVariants_OnItemCommand(Object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart" || e.CommandName == "AddToWishlist")
            {
                NumericTextBox           txtQuantity           = e.Item.FindControl("txtQuantity") as NumericTextBox;
                Label                    productVariantID      = e.Item.FindControl("ProductVariantID") as Label;
                ProductAttributesControl ctrlProductAttributes = e.Item.FindControl("ctrlProductAttributes") as ProductAttributesControl;
                Label                    lblError = e.Item.FindControl("lblError") as Label;

                try
                {
                    if (e.CommandName == "AddToCart")
                    {
                        List <string> addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                                                                                        Convert.ToInt32(productVariantID.Text),
                                                                                        ctrlProductAttributes.SelectedAttributes,
                                                                                        txtQuantity.Value);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect("~/ShoppingCart.aspx");
                        }
                        else
                        {
                            StringBuilder addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append("<br />");
                                }
                            }
                            lblError.Text = addToCartWarningsSb.ToString();
                        }
                    }

                    if (e.CommandName == "AddToWishlist")
                    {
                        List <string> addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.Wishlist,
                                                                                        Convert.ToInt32(productVariantID.Text),
                                                                                        ctrlProductAttributes.SelectedAttributes,
                                                                                        txtQuantity.Value);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect("~/Wishlist.aspx");
                        }
                        else
                        {
                            StringBuilder addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append("<br />");
                                }
                            }
                            lblError.Text = addToCartWarningsSb.ToString();
                        }
                    }
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.CustomerError, exc.Message, exc);
                    lblError.Text = Server.HtmlEncode(exc.Message);
                }
            }
        }
Exemplo n.º 12
0
 public ActionResult AddToCart(int id)
 {
     shoppingCartManager.AddToCart(id);
     return(RedirectToAction("Index")); //after add to cart go to Indext action from this controller
 }
Exemplo n.º 13
0
        protected void OnCommand(object source, CommandEventArgs e)
        {
            var pv = ProductVariant;

            if (pv == null)
            {
                return;
            }

            string  attributes                    = ctrlProductAttributes.SelectedAttributes;
            decimal customerEnteredPrice          = txtCustomerEnteredPrice.Value;
            decimal customerEnteredPriceConverted = CurrencyManager.ConvertCurrency(customerEnteredPrice, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
            int     quantity = txtQuantity.Value;

            //gift cards
            if (pv.IsGiftCard)
            {
                string recipientName   = ctrlGiftCardAttributes.RecipientName;
                string recipientEmail  = ctrlGiftCardAttributes.RecipientEmail;
                string senderName      = ctrlGiftCardAttributes.SenderName;
                string senderEmail     = ctrlGiftCardAttributes.SenderEmail;
                string giftCardMessage = ctrlGiftCardAttributes.GiftCardMessage;

                attributes = ProductAttributeHelper.AddGiftCardAttribute(attributes, recipientName, recipientEmail, senderName, senderEmail, giftCardMessage);
            }

            try
            {
                if (e.CommandName == "AddToCart")
                {
                    string sep = "<br />";
                    var    addToCartWarnings = ShoppingCartManager.AddToCart(
                        ShoppingCartTypeEnum.ShoppingCart,
                        pv.ProductVariantId,
                        attributes,
                        customerEnteredPriceConverted,
                        quantity);
                    if (addToCartWarnings.Count == 0)
                    {
                        if (SettingManager.GetSettingValueBoolean("Display.Products.DisplayCartAfterAddingProduct"))
                        {
                            //redirect to shopping cart page
                            Response.Redirect(SEOHelper.GetShoppingCartUrl());
                        }
                        else
                        {
                            //display notification message
                            this.DisplayAlertMessage(GetLocaleResourceString("Products.ProductHasBeenAddedToTheCart"));
                        }
                    }
                    else
                    {
                        var addToCartWarningsSb = new StringBuilder();
                        for (int i = 0; i < addToCartWarnings.Count; i++)
                        {
                            addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                            if (i != addToCartWarnings.Count - 1)
                            {
                                addToCartWarningsSb.Append(sep);
                            }
                        }
                        string errorFull = addToCartWarningsSb.ToString();
                        lblError.Text = errorFull;
                        if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                        {
                            this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                        }
                    }
                }

                if (e.CommandName == "AddToWishlist")
                {
                    string sep = "<br />";
                    var    addToCartWarnings = ShoppingCartManager.AddToCart(
                        ShoppingCartTypeEnum.Wishlist,
                        pv.ProductVariantId,
                        attributes,
                        customerEnteredPriceConverted,
                        quantity);
                    if (addToCartWarnings.Count == 0)
                    {
                        Response.Redirect(SEOHelper.GetWishlistUrl());
                    }
                    else
                    {
                        var addToCartWarningsSb = new StringBuilder();
                        for (int i = 0; i < addToCartWarnings.Count; i++)
                        {
                            addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                            if (i != addToCartWarnings.Count - 1)
                            {
                                addToCartWarningsSb.Append(sep);
                            }
                        }
                        string errorFull = addToCartWarningsSb.ToString();
                        lblError.Text = errorFull;
                        if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                        {
                            this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                LogManager.InsertLog(LogTypeEnum.CustomerError, exc.Message, exc);
                lblError.Text = Server.HtmlEncode(exc.Message);
            }
        }