Remove Qty from Basket Gridview

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
BryanWarmoth
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 44
Joined: Fri May 23, 2008 11:24 am
Location: Puyallup, Wa
Contact:

Remove Qty from Basket Gridview

Post by BryanWarmoth » Wed Jan 14, 2009 6:27 pm

We would like to remove the up-down control from certain item in the Basket Gridview on Basket.aspx. I tried to set the visible property of the up-down control to false, which works but when i update the basket all the items that have the control set to false are deleted from the basket. Is there a way to do this or a way to prevent someone from increasing or decreasing the quantity on that page? Thanks!
Bryan Bingham
Warmoth Guitar Products Inc.
bryan@warmoth.com
http://www.warmoth.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Remove Qty from Basket Gridview

Post by mazhar » Thu Jan 15, 2009 11:18 am

Try the following workaround. Edit the ConLib/Basket.ascx file and locate the following code

Code: Select all

<%--<cb:updowncontrol MinValue="0"  id="Quantity" runat="server" MaxValue="32767" DownImageUrl="~/images/down.gif" UpImageUrl="~/images/up.gif" Columns="2" MaxLength="5" Text='<%# Eval("Quantity") %>' onFocus="this.select()"></cb:updowncontrol>--%>
and make it look like

Code: Select all

<asp:HiddenField ID="Quantity" runat="server" />
                                <%--<cb:updowncontrol MinValue="0"  id="Quantity" runat="server" MaxValue="32767" DownImageUrl="~/images/down.gif" UpImageUrl="~/images/up.gif" Columns="2" MaxLength="5" Text='<%# Eval("Quantity") %>' onFocus="this.select()"></cb:updowncontrol>--%>
Now edit the App_Code/BasketHelper.cs file and make its Save method look like

Code: Select all

public static void SaveBasket(GridView BasketGrid)
    {
        Basket basket = Token.Instance.User.Basket;
        int rowIndex = 0;
        foreach (GridViewRow saverow in BasketGrid.Rows)
        {
            int basketItemId = (int)BasketGrid.DataKeys[rowIndex].Value;
            int itemIndex = basket.Items.IndexOf(basketItemId);
            if ((itemIndex > -1))
            {
                BasketItem item = basket.Items[itemIndex];
                if ((item.OrderItemType == OrderItemType.Product))
                {
                    HiddenField quantity = (HiddenField)saverow.FindControl("Quantity");
                    if (quantity != null)
                    {
						int qty = AlwaysConvert.ToInt(quantity.Value,item.Quantity);
						if(qty > System.Int16.MaxValue)
						{
							item.Quantity = System.Int16.MaxValue;
						}else{
							item.Quantity = (System.Int16)qty;
						}

                        // Update for Minimum Maximum quantity of product
                        if (item.Quantity < item.Product.MinQuantity)
                        {
                            item.Quantity = item.Product.MinQuantity;
                            quantity.Value = item.Quantity.ToString();
                        }
                        else if ((item.Product.MaxQuantity > 0) && (item.Quantity > item.Product.MaxQuantity))
                        {
                            item.Quantity = item.Product.MaxQuantity;
                            quantity.Value = item.Quantity.ToString();
                        }

                        item.Save();
                    }
                    else
                        item.Save();
                }
                rowIndex++;
            }
        }
    }

User avatar
BryanWarmoth
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 44
Joined: Fri May 23, 2008 11:24 am
Location: Puyallup, Wa
Contact:

Re: Remove Qty from Basket Gridview

Post by BryanWarmoth » Fri Jan 16, 2009 10:16 am

Works perfectly! Thanks Mazhar!
Bryan Bingham
Warmoth Guitar Products Inc.
bryan@warmoth.com
http://www.warmoth.com

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Remove Qty from Basket Gridview

Post by CASE » Mon May 11, 2009 9:22 am

Is there a way to do this for specific product types that are all within one category, but allow the user to change quantity on other products?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Remove Qty from Basket Gridview

Post by mazhar » Mon May 11, 2009 10:00 am

You can configure one more product display page with this functionality and then assign that display page to those products where you want not to have quantity option.

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Remove Qty from Basket Gridview

Post by CASE » Mon May 11, 2009 10:26 am

We are adding the products from an external page and not using the Product Display pages in Able Commerce. When the user makes there selections outside of AbleCommerce, they are added to the shopping basket when they push add to cart.

Once in the shopping basket, we want to make sure that they can't change the quantities. These items are all located in one product category in AbleCommerce.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Remove Qty from Basket Gridview

Post by mazhar » Mon May 11, 2009 10:32 am

In this case you can update the page and put some if else logic. For example when prodcuts in cart are going to repeat you can get the category id for each product and check it against your category id for which you want to hide box. For example

Code: Select all

int categoryId = product.Categories[0];
                if (categoryId == 2)
                { 
                    //Hide Quantity Box
                }
Where 2 is the id of category for which I want to hide quantity box.

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Remove Qty from Basket Gridview

Post by CASE » Mon Jul 06, 2009 8:55 am

Am I still working with the BasketHelper file when I add this code?

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: Remove Qty from Basket Gridview

Post by ZLA » Mon Jul 06, 2009 9:01 am

I removed the quantity checkbox as well via this post: viewtopic.php?f=42&t=11334&hilit=+quantity -- see the last entry where I just changed the markup using css as follows:

Code: Select all

<ItemTemplate>
    <asp:PlaceHolder ID="ProductQuantityPanel" runat="server" 
            Visible='<%#((OrderItemType)Eval("OrderItemType") == OrderItemType.Product)%>'>
        <cb:updowncontrol CssClass="HiddenPanel" MinValue="0"  id="Quantity" runat="server" MaxValue="32767"
            DownImageUrl="~/images/down.gif" UpImageUrl="~/images/up.gif" Columns="2" MaxLength="5" 
           Text='<%# Eval("Quantity") %>' onFocus="this.select()"></cb:updowncontrol>
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="OtherQuantityPanel" runat="server" Visible='True' EnableViewState="false">
        <%#Eval("Quantity")%>
    </asp:PlaceHolder>                     
</ItemTemplate>
Not rendering the control in the html can cause it's values not to be posted back. That will set the quantity to zero and can empty your basket. That's why I went with css.

Post Reply