an ASP.NET Open Source CMS & eCommerce platform
Search:
Skip Navigation LinksHome > DotShoppingCart Forums > Support > Using DotShoppingCart > "Add to Cart" button
Last Post 12/31/2013 10:33:13 AM By timofeia. 3 replies.
12/27/2013 8:33:05 AM
timofeia
Posts: 31
Joined: 3/21/2013
"Add to Cart" button
Is there any way when the customer clicks "Add to Cart" button from Product description screen, the application will not go to Store/ItemAddedToCart.aspx but instead will go directly to  Store/Cart.aspx ? The reason is we have only one product to sell, and we want to eliminate one extra click. Please help.Thank you.
12/29/2013 6:34:57 PM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: "Add to Cart" button
If you are using deault product template, you can update Web\Store\ProductDetail\DefaultTemplate.ascx.cs file.
 
Change
 
    private void addToCard_AddingToCart(object sender, EventArgs e) {
        if (!Product.Status.Orderable)
            return;
        lblNotEnoughStock.Visible = !AddToCart(addToCard.Quantity, SelectedAttributeValueIds, CustomField);
    }
 
to 
 
    private void addToCard_AddingToCart(object sender, EventArgs e) {
        if (!Product.Status.Orderable)
            return;
        lblNotEnoughStock.Visible = !GoStraightToCheckout(true, 1);
    }
 
DotShoppingCart Staff
12/31/2013 8:43:48 AM
timofeia
Posts: 31
Joined: 3/21/2013
Re: "Add to Cart" button
I changed lblNotEnoughStock.Visible = !AddToCart(addToCard.Quantity, SelectedAttributeValueIds, CustomField); to:
lblNotEnoughStock.Visible = !GoStraightToCheckout(true, 1);
Now the Web\Store\ProductDetail\DefaultTemplate.ascx.cs file gives me an error message:
The name 'GoStraightToCheckout' does not exist in the current context.
What should I check to fix this error message? Thank you.
12/31/2013 10:33:13 AM
timofeia
Posts: 31
Joined: 3/21/2013
Re: "Add to Cart" button
I found working solution. Please tell me I did not screw up anything by this change.
In DotShoppingCart.OpenSource.Core.ProductDetailTemplate.sc I changed:

public bool AddToCart(int count, List<int> selectedAttributeValueIds) {
            int quantity = Product.GetStockQuantity(count, selectedAttributeValueIds);
            if (0 == quantity)
                return false;
            else {
                int cartId = Cart.AddItem(Utils.GetUserName(), Product.ProductId,
                    Utils.GetSorted(selectedAttributeValueIds), quantity);
                Response.Redirect(string.Format("{0}?cartitemid={1}&quantity={2}", SiteNavigation.ItemAddedToCartPage, cartId, count));
                
            }
            return true;
        }

 to:

public bool AddToCart(int count, List<int> selectedAttributeValueIds) {
            int quantity = Product.GetStockQuantity(count, selectedAttributeValueIds);
            if (0 == quantity)
                return false;
            else {
                int cartId = Cart.AddItem(Utils.GetUserName(), Product.ProductId,
                    Utils.GetSorted(selectedAttributeValueIds), quantity);
                Response.Redirect(SiteNavigation.CartPage); OR ALTERNATIVELY:
        Response.Redirect(SiteNavigation.CheckoutPage);

                
            }
            return true;
        }

I tested, it looks like it’s working properly. Please tell me, if I can do it this way. Thank you.