This project is read-only.

Bug (and fix) in ShoppingCart.aspx


The UpdateTotals() routine does not work if you have 2 or more items with the first item having more than 1 quantity in the shopping cart.
The problem is the cartItems enumerator is in the for loop so it gets reset back to the beginning of the enumeration for each item.
Also the int i = 0; and i += 1; in the routine serves no purpose and can be deleted.
The fix is remove the cartItems enumerator out of the for loop and paste it above the for loop instead. Below is the fixed code:
protected void UpdateTotals()
    IEnumerator cartItems = lShoppingCart.Items.GetEnumerator();
    foreach (ListViewDataItem lvdi in lvOrderItems.Items)
        ShoppingCartItem lCartItem = null; // = (ShoppingCartItem)lShoppingCart.Items.ElementAtOrDefault(i);
        while (cartItems.MoveNext())
            lCartItem = (ShoppingCartItem)cartItems.Current;
        if (lCartItem != null)
            int id = lCartItem.ID;
            int quantity = int.Parse(((TextBox)lvdi.FindControl("txtQuantity")).Text);
            lShoppingCart.UpdateItemQuantity(id, quantity);


vanbach1304 wrote May 14, 2010 at 10:27 AM

You can fix this by adding code to commerce.js file for after delete item the page will reload.
$(".delete-item-button").click(function () {
var productId = $(this).attr("meta:id");
var form = $(this).parent("form");
    { id: productId },
    function (data) {
        $("#item-" +;
        //Reload whole page
return false;

sisnaz wrote Jun 4, 2010 at 12:13 AM

I posted the fix above - The cartItems enumeration should not be in the for loop.... additionally the problem isn't just with deleting items.

wrote Feb 22, 2013 at 12:12 AM