Guest Posted November 8, 2008 Share Posted November 8, 2008 Hi does anyone know if its possible to have a button which is on the last page of the checkout process that if the customer for some reason decides not to go ahead and confirm they can click cancel and then the cart is cleared and they are returned to the main page? or something like that. ANy ideas? Link to comment Share on other sites More sharing options...
♥kymation Posted November 9, 2008 Share Posted November 9, 2008 Not that hard to do. Copy this code to a new file and name it cancel.php. <?php /* $Id: cancel.php 1.0 2008-11-08 kymation $ osCommerce, Open Source E-Commerce Solutions [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url] Copyright © 2008 osCommerce Released under the GNU General Public License */ include('includes/application_top.php'); // if the customer is not logged on, redirect them to the login page if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT)); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } // Empty the cart $cart->reset(true); // unregister session variables used during checkout tep_session_unregister('sendto'); tep_session_unregister('billto'); tep_session_unregister('shipping'); tep_session_unregister('payment'); tep_session_unregister('comments'); // Send them to the front page tep_redirect(tep_href_link(FILENAME_DEFAULT)); require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> Then just link your Cancel button to that page. I haven't actually tested this, so fat-finger typos are possible. Please let me know if it works or not. Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
ozEworks Posted November 9, 2008 Share Posted November 9, 2008 Does that actually clear the cart from the database? Link to comment Share on other sites More sharing options...
Guest Posted November 9, 2008 Share Posted November 9, 2008 Not that hard to do. Copy this code to a new file and name it cancel.php. <?php /* $Id: cancel.php 1.0 2008-11-08 kymation $ osCommerce, Open Source E-Commerce Solutions [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url] Copyright © 2008 osCommerce Released under the GNU General Public License */ include('includes/application_top.php'); // if the customer is not logged on, redirect them to the login page if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT)); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } // Empty the cart $cart->reset(true); // unregister session variables used during checkout tep_session_unregister('sendto'); tep_session_unregister('billto'); tep_session_unregister('shipping'); tep_session_unregister('payment'); tep_session_unregister('comments'); // Send them to the front page tep_redirect(tep_href_link(FILENAME_DEFAULT)); require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> Then just link your Cancel button to that page. I haven't actually tested this, so fat-finger typos are possible. Please let me know if it works or not. Regards Jim Hi Jim, You seem to be my problem fixer at the mo :) Yes this does work but i also notice it does keep the person or guest logged in. Is this correct? I did find another way that works, but dont know if this is correct (but as i say it does work) <td class="main"><a href="<?php echo tep_href_link(basename($PHP_SELF), 'action=clear_cart', 'NONSSL');?>" onclick="var x=confirm(' To Cancel Checkout & Return To Main Page? '); if (x==false) { return false; }"><?php echo tep_image_button('button_cancel_checkout.gif', IMAGE_BUTTON_CANCEL_CHECKOUT)?> Do you think this too should be fine? or will it not clear the database. I checked it in the admin area to see what step the customer (account holder or guest) is up to. It shows the session ID and does update to say they are on the index page and that there is nothing in their cart. Regards, Link to comment Share on other sites More sharing options...
♥kymation Posted November 10, 2008 Share Posted November 10, 2008 The code that I posted will clear the cart, database and all, as well as the checkout session variables. Your method uses an action of "clear_cart" that does not exist in stock osCommerce. Perhaps some contribution added that code. I can't tell what it does without seeing the code that it executes, so I have no idea what it does. My code also keeps the customer logged in. If this is not what you want, add the following to the code I posted above: tep_session_unregister('customer_id'); tep_session_unregister('customer_default_address_id'); tep_session_unregister('customer_first_name'); tep_session_unregister('customer_country_id'); tep_session_unregister('customer_zone_id'); somewhere below the rest of the unregister function calls. Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
zeppos Posted July 19, 2009 Share Posted July 19, 2009 ok this cancel.php suggestion has some flaws. for one thing, if you put the Cancel Button on the checkout_confirmation page, even if you cancel the order you still get the confirmation email and the purchase appears on your account history. all this because the redirect doesnt prevent if (is_array($payment_modules->modules)) { echo $payment_modules->process_button(); } from being executed, so we get the redirect but not the total cancellation of the order. i'm trying to find a solution for this. Link to comment Share on other sites More sharing options...
zeppos Posted July 19, 2009 Share Posted July 19, 2009 furthermore i just noticed that the order appears on the admin tool as well, so the owner of the store cannot even know if the customer actually canceled or confirmed the order. now it's clear that if we put this Cancel button anywhere else but in checkout_confirmation.php, it'll probably work ok. so considering the fact that this Cancel feature was supposed to be in the checkout_confirimation.php from the very beginning, from the first question of this thread, we see that this approach is totally flawed, unless we find a way to reset this $payment_modules thing, which means that the cancel button should probably be an action and not a simple href link. Link to comment Share on other sites More sharing options...
zeppos Posted July 21, 2009 Share Posted July 21, 2009 ok i think i've found a temporary solution, that seems to be working. the only thing i changed was the echo tep_draw_form('checkout_confirmation', $form_action_url, 'post'); instead of putting it at its' original position (practically at the top of the page), i put it right AFTER the cancel button and BEFORE the confirm button. so now only the latter seems to be processed as a "form button" and the Cancel one only works as a simple hyperlink. Link to comment Share on other sites More sharing options...
♥kymation Posted July 21, 2009 Share Posted July 21, 2009 I'm having trouble understanding what you did here. Could you post the code that you used for your Cancel button? Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
zeppos Posted July 27, 2009 Share Posted July 27, 2009 Umm, the code is very simple, I just put this for the Cancel button: <td align="left" class="main bg_input"> <?php echo '<a href="' . tep_href_link(FILENAME_CANCEL_ORDER, '', 'SSL') . '">' . tep_image_submit('button_cancel_order.png', IMAGE_BUTTON_CANCEL_ORDER) . '</a>'; ?> </td> Now somewhere at the top of the original checkout_confirmation.php, there was this line of code: echo tep_draw_form('checkout_confirmation', $form_action_url, 'post'); which means more or less than the entire central column of the page was considered to be a form, so if I pressed the Cancel button (which was placed way before the "/form" statement at the bottom of the file) it was considered to be a "process button" as well, and some code right below it was executed too. That code was: if (is_array($payment_modules->modules)) { echo $payment_modules->process_button(); } So even if I pressed the Cancel button, the page would still redirect to the checkout_process.php page and would send the purchase-complete email to the client, add the purchase to the database, show it on the client's account history, etc etc. After the addition of the Cancel button, the only real difference was that instead of the normal sequence "checkout_confirmation.php -> checkout_process.php -> checkout_success.php" now we had "checkout_confirmation.php -> checkout_process.php -> cancel.php -> index.php (due to the cancel button redirect". So we only missed the checkout_success page but the purchase was processed alright (instead of being canceled). So the only thing I really changed was the place of the tep_draw_form code. Instead of leaving it at the top of the file, I put it BELOW the cancel button, and now only the Confirmation button is considered to be part of the form. So the code now is: <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <?php // adding Cancel Order button (empties the cart but does not logout the customer) ?> <td align="left" class="main bg_input"> <?php echo '<a href="' . tep_href_link(FILENAME_CANCEL_ORDER, '', 'SSL') . '">' . tep_image_submit('button_cancel_order.png', IMAGE_BUTTON_CANCEL_ORDER) . '</a>'; ?> </td> <?php // end_of Cancel Order button addition ?> <td align="right" class="main bg_input"> <?php // tep_draw_form was moved here, instead of top of the file (which was the original position) echo tep_draw_form('checkout_confirmation', $form_action_url, 'post'); if (is_array($payment_modules->modules)) { echo $payment_modules->process_button(); } // confirmation button echo tep_image_submit('button_confirm_order1.png', IMAGE_BUTTON_CONFIRM_ORDER) . "\n"; ?> </td> </tr> </table> etc... Link to comment Share on other sites More sharing options...
♥kymation Posted July 27, 2009 Share Posted July 27, 2009 That first part is the problem. tep_image_submit() is a form submit button. That would submit the form and complete the order before it redirects to the cancel script. What you need is <?php echo '<a href="' . tep_href_link(FILENAME_CANCEL_ORDER, '', 'SSL') . '">' . tep_image_button('button_cancel_order.png', IMAGE_BUTTON_CANCEL_ORDER) . '</a>'; ?> Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
zeppos Posted July 29, 2009 Share Posted July 29, 2009 That first part is the problem. tep_image_submit() is a form submit button. That would submit the form and complete the order before it redirects to the cancel script. What you need is <?php echo '<a href="' . tep_href_link(FILENAME_CANCEL_ORDER, '', 'SSL') . '">' . tep_image_button('button_cancel_order.png', IMAGE_BUTTON_CANCEL_ORDER) . '</a>'; ?> Regards Jim good suggestion, I'll try it asap and hopefully it'll work. Link to comment Share on other sites More sharing options...
zeppos Posted July 29, 2009 Share Posted July 29, 2009 right, it's working perfectly fine. Duh, I should have seen that tep_image_submit() thing, I just copied/pasted from some other piece of code and I didn't even notice it, thanks for the suggestion, it's a much nicer fix. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.