add to cart button link

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
How to construct the url link to be used to be able to create an add to cart button from an external page to add a product into nopcommerce. When the user click on add button from external page what url link can be used to do this? Thank you
15 years ago
Postbacks are used to add to cart.

But it's very easy to add a custom page for adding to cart. Use ShoppingCartManager.AddToCart method.
14 years ago
I am a newby to .net can you please explain just a little more about the add to cart method. Maybe an example please. Thank you
14 years ago
Have a look at the following code from the add to cart button:


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,
                    new List<int>(), 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);
            }
        }


Basically you can create a page or handler that accepts a product id in as a querystring an pass this ID to the ShoppingCartManager.AddToCart method.

Hope this helps,
Ben
12 years ago
nopCommerce team | retroviz wrote:
Have a look at the following code from the add to cart button:


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,
                    new List<int>(), 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);
            }
        }


Basically you can create a page or handler that accepts a product id in as a querystring an pass this ID to the ShoppingCartManager.AddToCart method.

Hope this helps,
Ben

i want to do a product customizable in flash, so customer design the product (colors etc), then the customer press a button handler that pass through the cart process.
can you explain me please, what are the steps you describe avobe , i have to create a page and paste that code?and then?
how can i know the url to put the link in my product to  "land" in the shopping cart with the product added? what about the price?

thank you !!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.