Hi friends,
Does anyone have a code to put a button instead of a "checkbox>Update Cart" to delete the products from the Shopping Cart? If not, some idea about it would be very nice too.
Thanks a lot,
Humberto
[HttpPost]
public void RemoveShippingCartItem(int id)
{
var shoppingCartItem = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Id == id)
.LimitPerStore(_storeContext.CurrentStore.Id).FirstOrDefault();
_shoppingCartService.DeleteShoppingCartItem(shoppingCartItem, ensureOnlyActiveCheckoutAttributes: true);
}
@if (Model.IsEditable)
{
<td>
<input class="remove-item-cart-btn" type="button" value="Remove" data-itemid="@item.Id"/>
</td>
}
<script>
$('.remove-item-cart-btn').click(function () {
var $this = $(this);
$.ajax({
url: '/ShoppingCart/RemoveShippingCartItem',
type: 'POST',
data: { id: $this.data('itemid') },
success: function () { $this.parent('.cart-item-row').hide()},
error: function () { },
complete: function () { }
});
});
</script>
<script type="text/javascript">
$(document).ready(function ()
{
$(".cart").find(".remove-item-cart-btn").on("click", function () {
var $this = $(this);
$.ajax({
url: '@Url.Action('RemoveShippingCartItem', 'ShoppingCart')',
type: 'POST',
data: { id: $this.data('itemid') },
success: function () { $this.parent().parent('.cart-item-row').hide(); },
error: function () { },
complete: function () { }
});
});
});
</script>