Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Delete button in shopping cart


magnusj

Recommended Posts

Hi all,

 

I would like to know if it?s possible to have a delete button beside each product in the shopping cart, instead of the checkbox?

Or even better; one "remove 1 item" button, and one "add 1 item" button (I?m sure I have seen this somewhere?).

 

Also I would like the same in the shopping cart box. Is this possible?

 

 

Best Regards

Magnus J

Link to comment
Share on other sites

Hi all,

 

I would like to know if it?s possible to have a delete button beside each product in the shopping cart, instead of the checkbox?

Or even better; one "remove 1 item" button, and one "add 1 item" button (I?m sure I have seen this somewhere?).

 

Also I would like the same in the shopping cart box. Is this possible?

Best Regards

Magnus J

 

Yes it is possible.

Link to comment
Share on other sites

I just wrote this little script, should get the job done, it doesnt add a "delete" button, but it means when you click the remove checkbox the cart automatically updates.

 

Maybe i should submit as a contribute?

 

Here:

1 ) Add this between the <head></head> tags in shopping_cart.php (around line 25)

 

<script type="text/javascript" language="JavaScript"><!--
function DoSubmission() {
document.cart_quantity.submit();
}
//--></script>

 

2 ) Search for:

 

'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));

 

Change to:

'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'], ' ', 'onClick="DoSubmission();"'));

 

3 ) in file includes/functions/html_output.php search for: (around line 189)

 

 if ( ($checked == true) || ( isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ( ($GLOBALS[$name] == 'on') || (isset($value) && (stripslashes($GLOBALS[$name]) == $value)) ) ) ) {
     $selection .= ' CHECKED';

 

Change to:

if ( ($checked == true) || ( isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ( ($GLOBALS[$name] == 'on') || (isset($value) && (stripslashes($GLOBALS[$name]) == $value)) ) ) ) {
     $selection .= '';

 

and thats it, enjoy :D

Link to comment
Share on other sites

Just so you know, it's not generally good UI practice to have an "action" behind checkboxes. It could be changed to a button easily enough, but in both cases, it won't work if the user's browser has javascript disabled.

Link to comment
Share on other sites

Just so you know, it's not generally good UI practice to have an "action" behind checkboxes. It could be changed to a button easily enough, but in both cases, it won't work if the user's browser has javascript disabled.

 

If you can think of a better way please post, before i submit contribute

 

(If users dont have javascript enabled it will still update when the click the update button)

 

P.S what is "UI"?

Link to comment
Share on other sites

Thanks a lot dave111!

 

Your contribution worked great. However... :-"

I really would like an image button (or a "remove item" hyperlink like FalseDawn suggested).

Do you know how to make such a button or link, since FalseDawn can?t be bothered :-)?

 

 

Magnus J

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

That is EXACTLY the question I have! ie. How could we have a DELETE button behind each item?

 

Also, could we have a button for UPDATE in front of the quantity box of each item? Could someone write a contribution?! Would be greatly appreciated.

 

Many thanx,

David.

 

Just checking in. It?s been a while. I would still like to know if anyone has ANY ideas about the above issue?

 

Thanks!

Link to comment
Share on other sites

  • 1 month later...

Hi friends!

I have succeded in putting a delete button in the shopping cart (instead of the delete checkbox).

 

Here is how:

 

In the head section of Catalog/shopping_cart.php, put:

 

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

 

 

Then, in the same file about row 124, find:

'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));

 

Replace with:

'text' => '<a href="java script:void(mark(\'' . $products[$i]['id'] . '\'));"><img src="images/remove.gif" border="0" height="14" width="14"></a>');

 

Then, upload the file.

 

Then, upload an image called remove.gif to the images folder. For example this one:

 

remove.gif

 

 

All done... good luck!

 

Magnus J

Link to comment
Share on other sites

Ok I made a fix, I don't know why you guys make it so advanced with javascripts and editing thousands of files, it's a matter of changing two lines really..

 

Add delete button instead of checkbox:

Edit shopping_cart.php

Find:
'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));

Replace with:
'text' => '<input type="image" src="PATH_TO_YOUR_DELETE_IMG.jpg" name="cart_delete[]" value="' . $products[$i]['id'] . '">');

 

Add update button near quantity box:

Find:
'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', 

$products[$i]['id']));

Replace with:
'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']) . '  <input type="image" src="PATH_TO_YOUR_UPDATE_IMG.jpg" border="0" alt="Update" title=" Update ">');

Comment out the update button at the bottom cause we don't need this anymore,
at about line 223:

<td class="main"><?php # echo tep_image_submit('button_update_cart.gif', IMAGE_BUTTON_UPDATE_CART); ?></td>

 

Works for me, have fun.

 

You could even do:

 

 'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']) . '  ' . tep_image_submit('button_update_cart.gif', IMAGE_BUTTON_UPDATE_CART));

 

Instead, if you want to use the updatebutton image.

Link to comment
Share on other sites

  • 1 month later...

The last solution does not work for the "delete" button. This is my rendered html code for the delete button :

 

<td align="center" class="productListing-data" valign="top"><input type="image" src="includes/languages/french/images/buttons/button_delete.gif" border="0" alt="Supprimer" title=" Supprimer " name="cart_delete[]" value="589{9}23{1}58{10}32{txt_18}"></td>

 

However, when clicking on the button, the form is executed but the product is not dropped from the shopping cart. I've checked the switch in application_top.php (case update_product) and I did no changes in that code.

 

Somebody got it working ? I like this solution much more than the previous javascript solutions so I would like it to work...

 

Any idea?

:-"

Didier.

Link to comment
Share on other sites

  • 3 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...