Page 1 of 1
Remove Qty from Basket Gridview
Posted: Wed Jan 14, 2009 6:27 pm
by BryanWarmoth
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!
Re: Remove Qty from Basket Gridview
Posted: Thu Jan 15, 2009 11:18 am
by mazhar
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++;
}
}
}
Re: Remove Qty from Basket Gridview
Posted: Fri Jan 16, 2009 10:16 am
by BryanWarmoth
Works perfectly! Thanks Mazhar!
Re: Remove Qty from Basket Gridview
Posted: Mon May 11, 2009 9:22 am
by CASE
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?
Re: Remove Qty from Basket Gridview
Posted: Mon May 11, 2009 10:00 am
by mazhar
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.
Re: Remove Qty from Basket Gridview
Posted: Mon May 11, 2009 10:26 am
by CASE
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.
Re: Remove Qty from Basket Gridview
Posted: Mon May 11, 2009 10:32 am
by mazhar
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.
Re: Remove Qty from Basket Gridview
Posted: Mon Jul 06, 2009 8:55 am
by CASE
Am I still working with the BasketHelper file when I add this code?
Re: Remove Qty from Basket Gridview
Posted: Mon Jul 06, 2009 9:01 am
by ZLA
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.