Contributions
Automatic remove button in shopping cart
This contribution will make the remove checkbox in the shopping cart automatically update and remove the item when customer clicks the checkbox (no need for them to click "update")
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
Expand All / Collapse All
'text' => 'Remove?<br>' . tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'],'', 'onclick="var answer= confirm('Remove Product?'); if(answer){document.cart_quantity.submit();}else{ return false;};"',false));//auto update cart
change in shopping cart est (line 189)
just to make it a little clearer, helps users understand that the checkbox will remove the product
in shopping_cart.php
find
'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));
change to
//'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));
'text' => 'Remove?<br>' . tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'],'', 'onclick="document.cart_quantity.submit();"',false));//auto update cart
If your going the javascript route, as suggested by deep-silver, you could also include this to update quatities.
// In shopping_cart.php
// Find and replace this:
'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
// On or around line 144 default install
// With this:
//'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4" onblur="document.cart_quantity.submit();"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
When the user changes the quantity and focus' the input elsewhere the form will be submitted. You should be careful however as not all users will have javascript enabled or a DOM compatible browser. I might look into a way to degrade this gracefully when I have the time.
open catalog/shopping_cart.php
find and replace this line (aprox. line no.113)
//--------------------------------
'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));
.....with this...
//'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));
'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'],'', 'onclick="document.cart_quantity.submit();"',false));//auto update cart
Done!
see it in action at...
http://www.deep-silver.com/shop/
P.S Java must be enabled to use this mod.
This mod is a different (and in my mind, better) way to do this.
And you can actually have a 'remove' image button, rather than a checkbox.
There was a bracket missing in update instructions in tep_draw_selection_field_auto_remove. It should work now.
Typo in instructions file fixed. Full package attached.
The original version of this contribution broke the tep_draw_checkbox_field function and caused account_notifications.php and account_newsletters.php not to function correctly.
The attached update fixes this problem. Instructions are provided for both New Installation and Update in the attached file.
Should take less than 10 minutes to install.
If you change the quantity and press Checkout, the new quantity should also be updated in the shopping cart.
this little change in combination with this remove-contribution will do exactly that.
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" onChange="DoSubmission();"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
There seemed to be an missing 0 (zero) between some ' in the shopping_cart.php Code - so i added this one and now it all works fine!
thanks for that simple hint on how to realize this function ;)
This contribution will make the remove checkbox in the shopping cart automatically update and remove the item when customer clicks the checkbox (no need for them to click "update")
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
Note: Contributions are used at own risk.