Zen Cart Logo
Forums / General Questions / Add delete button in shopping cart

Add delete button in shopping cart

Locked

Views: 4,780

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
29 Jan 2010, 4:29 PM
#1
pablo1719 avatar

pablo1719

New Zenner

Join Date:
Nov 2008
Posts:
33
Plugin Contributions:
0

Add delete button in shopping cart

I have installed the shopping cart with rewards side box and merged it with the images and checkout button in cart sidebox. Now, I am trying to add a remove from cart button after each product. I have the button showing but it doesn't work correctly. It returns teh user to the shopping cart page and at that time you can remove items from the sidebox but it only removes the last item added. I have changed the file name for the icon so that I could have a smaller icon.

$content .= '<a href="'.zen_href_link(FILENAME_SHOPPING_CART, 'action=remove_product&product_id=' . $product['id']). '">'. zen_image($template->get_template_dir(ICON_IMAGE_TINYTRASH, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/'.ICON_IMAGE_TINYTRASH, ICON_TRASH_ALT).'</a></li>';
3 Feb 2010, 3:45 PM
#2
bigstar avatar

bigstar

New Zenner

Join Date:
Jun 2006
Posts:
6
Plugin Contributions:
0

Re: Add delete button in shopping cart

I've managed to add a delete button beside each product in the shopping cart sidebox, using part of a script from an osCommerce mod.

In templates/sideboxes/tpl_shopping_cart.php I added this script at the start before $content ="";

?>
<script type="text/javascript">
<!--
function mark(pid) {
   document.forms["remove_product"].elements["cart_delete[]"][0].value=pid;
   document.forms["remove_product"].elements["products_id[]"][0].value=pid;
   document.remove_product.submit();
}
var sURL = document.URL.toString();
if (sURL.indexOf("?") > 0){
 urlsplitter = '';
} else {
 urlsplitter = '?';
}
document.write('<form ');
document.write(' name="remove_product" ');
document.write(' action="' + document.URL + urlsplitter + '&action=update_product"');
document.write(' method="post">');
//one element is not an array so add 2 of each!
document.write('<input type="hidden" name="products_id[]">');
document.write('<input type="hidden" name="cart_delete[]">');
document.write('<input type="hidden" name="products_id[]">');
document.write('<input type="hidden" name="cart_delete[]">');
document.write('</form>');

document.write('<form ');
document.write(' name="cart_box" ');
document.write(' action="' + document.URL + urlsplitter + '&action=update_product"');
document.write(' method="post">');
   //-->
</script>
<?php

I dropped a delete icon into my images folder and added the following line before <span class="cartNewItem"> and <span class="cartOldItem">:

<div class="removeProduct"><a href="javascript:void(mark(\'' . $products[$i]['id'] . '\'));">' . '<img src="images/small_delete.gif" border="0" height="16" width="16"></a></div>

To make the delete icon display to the right of each product, I added this line to stylesheet.css:

.removeProduct {float:right;margin:0px 0px 0px 2px;}

Seems to be working OK... I'd like to get the delete icons to line up on the right, but I'm not sure how to do this ...

3 Feb 2010, 5:06 PM
#3
bigstar avatar

bigstar

New Zenner

Join Date:
Jun 2006
Posts:
6
Plugin Contributions:
0

Re: Add delete button in shopping cart

Maybe my last suggestion isn't necessary. While the script works for me, I wonder is there an easier way to use the

'action=remove_product&product_id='

in the shopping cart sidebox without having the action revert to the shopping cart page?

3 Feb 2010, 9:02 PM
#4
pablo1719 avatar

pablo1719

New Zenner

Join Date:
Nov 2008
Posts:
33
Plugin Contributions:
0

Re: Add delete button in shopping cart

Awesome! works great.

as far as getting the icon to align to the right I just put align="right" in the <div> tag. as far as going back to the shopping cart page I have mine set up differently so that after items are added it just goes to the product added page. You can adjust this in the Admin>Configuration>My Store>Display Cart After Adding Product="false".

once again thank you