The following code allows to update item quantity straight to a desired number, by adding a textbox to the last column of the cart. LinkButton lnkAdd is used to confirm quantity.
So far this functionality is not apllied to mini-cart .
In CartDeatail.ascx in the last itemtemplate tag add:
<asp:textbox id="txtQuantity" runat="server" width="30" MaxLength="4" cssclass="NormalTextBox"></asp:textbox>
In CartDeatail.ascx.cs:
Change "if(lnkAdd != null){...}" to:
if (lnkAdd != null)
{
TextBox txtQuantity = (TextBox)e.Item.FindControl("txtQuantity");
if (txtQuantity != null)
{
txtQuantity.TextChanged += new EventHandler(OnQtyChanged);
txtQuantity.Attributes.Add("OnKeyDown", " if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + lnkAdd.ClientID + "').Click;" + Page.GetPostBackEventReference(lnkAdd, string.Empty) + ";return false;}} else {return true}; ");
}
// Traduction effectuйe
lnkAdd.Attributes.Add("title", Localization.GetString("AddAnother", this.LocalResourceFile) + " " + itemInfo.ProductTitle + " " + Localization.GetString("ToTheCart", this.LocalResourceFile));
lnkAdd.CommandName = itemInfo.ItemID.ToString();
lnkAdd.CommandArgument = itemInfo.Quantity.ToString();
lnkAdd.Command += new CommandEventHandler(btnAdd_Click);
lnkAdd.CausesValidation = false;
}
Add event handler:
private void OnQtyChanged(object sender, EventArgs e)
{
((TextBox)(grdItems.Items[0].FindControl("txtQuantity"))).Text = ((TextBox)sender).Text;
}
Change btnAdd_Click() to:
private void btnAdd_Click(object sender, CommandEventArgs e)
{
int itemID = int.Parse(e.CommandName);
int quantity;
try
{
quantity = int.Parse(((TextBox)(grdItems.Items[0].FindControl("txtQuantity"))).Text);
if (quantity == 0)
{
CurrentCart.RemoveItem(itemID);
}
else if (quantity < 0)
{
CurrentCart.UpdateItem(PortalId, itemID, -(quantity));
}
else
{
CurrentCart.UpdateItem(PortalId, itemID, quantity);
}
updateCartGrid();
this.invokeEditComplete();
}
catch(Exception ex) //does nothing, if quantity is not a positive integer
{
updateCartGrid();
this.invokeEditComplete();
}
}