Modifying Cart Item Remove Functionality

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
New York wrote:
Would I be beaten with the "anti-MVC" stick to suggest this?

(OrderSummary.cshtml   -  on the checkbox, just add jquery onclick to click the updatecart button)

<input id="removefromcart" type="checkbox" name="removefromcart" value="@(item.Id)"  onclick="$('#updatecart').click();"/>

(EDIT:  I haven't tried your method - what would happen if the customer changed a qty on another line, and then clicked the remove button on a different line?  I'd think he'd lose his qty change.)


You're correct "New York" just rendering an anchor tag would cause the loss of data when clicked. Ciwan could make the method I provided an ajax call without trouble. The method you've provided above would fall victim to a similar problem to my original suggestion. Instead of updating one row you're actually updating the entire cart, and from a user perspective that would feel pretty awkward if a "remove icon" updated seemingly unrelated rows.

There are many ways to approach the issue described above and each have their drawbacks. Thanks for the alternate solution!
12 years ago
I'm not sure what you mean NY. If a user changes quantity and clicks update cart button, the cart would obviously update to show the quantity change.

If the user, clicks the remove button, it doesn't matter what he/she has done to the quantity, that cart item will be removed.
12 years ago
Ciwan wrote:
I'm not sure what you mean NY. If a user changes quantity and clicks update cart button, the cart would obviously update to show the quantity change.

If the user, clicks the remove button, it doesn't matter what he/she has done to the quantity, that cart item will be removed.


If the user changes the quantity on any OTHER item(s) in the cart and does not click the update, but then clicks the remove button, then he will either lose the quantity information entered on those other items (sky's solution), or he will get all the new quantities applied by just clicking the remove button (my solution).
12 years ago
ahh I see what you mean now.

I don't think many people would do that though.

Not many people would update the cart quantity, and go hit the remove (unless that's what they intended on doing). :)
12 years ago
Another way to do this, using POST, with not need to create a new route :

In ShoppingCartController.cs
[ValidateInput(false)]
[HttpPost, ActionName("Cart")]
[FormValueRequired(FormValueRequirement.StartsWith, "removefromcart")]
public ActionResult RemoveFromCart(FormCollection form)
{

        int shoppingCartItemId = 0;
    foreach (var formValue in form.AllKeys)
        if (formValue.StartsWith("removefromcart", StringComparison.InvariantCultureIgnoreCase))
        {
            shoppingCartItemId = Convert.ToInt32(formValue.Substring("removefromcart".Length));
            break;
        }

    _shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer, shoppingCartItemId, 0, true);

    return RedirectToAction("Cart");
}


In OrderSummary.cshtml
<input type="submit" name="removefromcart@(item.Id)" value="@T("ShoppingCart.Remove")" id="removefromcart@(item.Id)" class="removefromcartbutton" />
11 years ago
Don't you think this system should be the default behavior in Nop?
Personally I think the system with checkbox + refresh button is not very handy.
11 years ago
zar wrote:
Don't you think this system should be the default behavior in Nop?
Personally I think the system with checkbox + refresh button is not very handy.


I agree with you, personnaly I have removed the checkboxes.
8 years ago
zar wrote:
Don't you think this system should be the default behavior in Nop?
Personally I think the system with checkbox + refresh button is not very handy.


So am I working on removing checkboxes. Would be really handy if the feature is by default :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.