Remove Product as a Button instead of Checkbox

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
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
13 years ago
No one? =/
13 years ago
I have the requirement. I based my implementation on https://www.nopcommerce.com/boards/t/8367/adding-delete-button-to-mini-cart.aspx

1) In OrderSummary.ascx.cs in validateCartItems

….....

               int shoppingCartItemId = 0;

               var btnProductDelete = item.FindControl("btnProductDelete") as LinkButton;

              
               int quantity = 0;
               if (txtQuantity != null && lblShoppingCartItemId != null && cbRemoveFromCart != null)
               {
                   int.TryParse(lblShoppingCartItemId.Text, out shoppingCartItemId);

                   if (!cbRemoveFromCart.Checked)
                   {
                       int.TryParse(txtQuantity.Text, out quantity);
                       var sci = this.ShoppingCartService.GetShoppingCartItemById(shoppingCartItemId);
                       if (btnProductDelete != null)
                       {
                           //btnProductDelete.Command += new CommandEventHandler(lvCart_ItemDeleteCommand);
                           btnProductDelete.CommandArgument = sci.ShoppingCartItemId.ToString();


                       }


                       var warnings = this.ShoppingCartService.GetShoppingCartItemWarnings(
                           sci.ShoppingCartType,

….......

Add the following function


       protected void lvCart_ItemDeleteCommand(object sender, CommandEventArgs e)
       {
           int commandShoppingCartItemId;
           if (int.TryParse(e.CommandArgument.ToString(), out commandShoppingCartItemId))
           {
               this.ShoppingCartService.DeleteShoppingCartItem(commandShoppingCartItemId, true);
           }

        //   this.DisplayAlertMessage(GetLocaleResourceString("Products.ProductHasBeenDeletedToTheCart"));
           Response.Redirect(SEOHelper.GetShoppingCartUrl());
       }

2) In OrderSummary.ascx

…....
                       { %>
                         <td>
                             <asp:LinkButton runat="server" ID="btnProductDelete" OnCommand="lvCart_ItemDeleteCommand"
                               CssClass="buttons btn_style3 left shopping-cart-delete">
                               <div>
                               <span>
                               <asp:Literal ID="Literal1" runat="server"><h1>&nbsp;X&nbsp;</h1></asp:Literal></span>
                               </div>
                               </asp:LinkButton>

          <!--                  <asp:CheckBox runat="server" ID="cbRemoveFromCart" /> -->
                       </td>
                       <%} %>
                       <%if (this.SettingManager.GetSettingValueBoolean("Display.Products.ShowSKU"))
                         {%>

…...
9 years ago
Hi,

does anyone know how to make this work in 3.4?
9 years ago
ssc wrote:
Hi,

does anyone know how to make this work in 3.4?


Try something like that for 3.40


ShoppingCartController.cs


[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);
}


OrderSummary.chtml

Inside cart table


@if (Model.IsEditable)
{
    <td>                              
    <input class="remove-item-cart-btn" type="button" value="Remove" data-itemid="@item.Id"/>
    </td>
}


outside of cart table

 
<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>
9 years ago
Another solution working in nopCommerce 3.40 without modify .cs source code (only in view).
Please take a look
https://www.nopcommerce.com/boards/t/32278/how-to-implement-remove-buttons-to-each-shopping-cart-row-in-v340.aspx
9 years ago
Thank you both very much!

I went with shahdat45ict's solution. To make it work I had to change a little bit:

OrderSummary.chtml

outside of cart table:

        <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>


I underlined the changes I made.
8 years ago
Hi @all can we add remove product for version 3.60, if yes please guide me?
8 years ago
Hopefully: https://www.nopcommerce.com/p/1706/shoppingcart-remove-button-free-ima9inescom.aspx

Updates for 3.6

As for a 3.4 method. I haven't found any 'easy to use' methods that don't involve changing the core of Nop...something I go to great lengths to avoid.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.