This article describes the example of zen_cart implementing the method of generating orders before payment. Share it with everyone for your reference, the details are as follows:
In addition to paypal, customers can place orders by entering the page index.php?main_page=checkout_confirmation through other payment methods.
But!! Paypal is a little different. It can only place orders after returning from its official website [paypal.com] and entering the checkout_process page
Accidents often happen: For example, the network is not smooth. Or a customer accidentally closes the page before returning.
Then, our website backend cannot see what product the customer bought (although we can see who bought it in the paypal backend, but we really can’t know what he bought). This is very depressing. Things
The principle of paypal’s anti-leaking order is------place an order on the page checkout_confirmation.php!!!
The method is: in the last part of this file
Copy code The code is as follows: echo TITLE_CONTINUE_CHECKOUT_PROCEDURE . '
' . TEXT_CONTINUE_CHECKOUT_PROCEDURE;
:
// create the order record 防漏单 if ($_SESSION['payment'] == 'paypal') { $insert_id = $order->create($order_totals, 2); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE'); $payment_modules->after_order_create($insert_id); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE'); // store the product info to the order $order->create_add_products($insert_id); $_SESSION['order_number_created'] = $insert_id;
In order to avoid affecting other payment methods, the code has made a judgment that only paypal payment will run the code that generates orders. After adding this section, you don’t have to worry about missing orders.
If you need a more perfect approach, in order to prevent customers from repeatedly generating orders when accessing the checkout process, you need to add a judgment
if($_SESSION['payment']!='paypal'){ /*// create the order record $insert_id = $order->create($order_totals, 2); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE'); $payment_modules->after_order_create($insert_id); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE'); // store the product info to the order $order->create_add_products($insert_id); $_SESSION['order_number_created'] = $insert_id; $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS'); //send email notifications $order->send_order_email($insert_id, 2); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL');*/ }
And on the confirmation page, if the customer keeps refreshing the page, orders will continue to be generated. You can add a limit.
// create the order record 防漏单 if ($_SESSION['payment'] == 'paypal' and !isset($_SESSION['order_number_created'])) { $insert_id = $order->create($order_totals, 2); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE'); $payment_modules->after_order_create($insert_id); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE'); // store the product info to the order $order->create_add_products($insert_id); $_SESSION['order_number_created'] = $insert_id; }
Add
anywhere in pages/checkout_payment/header_php.phpunset($_SESSION['order_number_created']);
In this way, even if the customer keeps refreshing the confirmation page, because it has been set
$_SESSION['order_number_created']
Orders are no longer generated,
If the customer returns to modify the shopping cart, $_SESSION['order_number_created'] will be cleared when checkout_payment is reached again,
In fact, the code to generate an order can be written in function confirmation() of modules/payment/paypal.php.
The code is as follows:
function confirmation() { if(!isset($_SESSION['order_number_created'])) { global $order,$order_total_modules,$order_totals,$zco_notifier,$insert_id; $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_BEGIN'); // if the customer is not logged on, redirect them to the time out page if (!$_SESSION['customer_id']) { zen_redirect(zen_href_link(FILENAME_TIME_OUT)); } else { // validate customer if (zen_get_customer_validate_session($_SESSION['customer_id']) == false) { $_SESSION['navigation']->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_SHIPPING)); zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL')); } } if(isset($mycartID)&&$mycartID == $_SESSION['cart']->cartID) { return array('title' => MODULE_PAYMENT_PAYPAL_TEXT_DESCRIPTION); } $mycartID = $_SESSION['cart']->cartID; $order = new order; // prevent 0-entry orders from being generated/spoofed if (sizeof($order->products) < 1) { zen_redirect(zen_href_link(FILENAME_SHOPPING_CART)); } $order_total_modules = new order_total; $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_BEFORE_ORDER_TOTALS_PRE_CONFIRMATION_CHECK'); //$order_totals = $order_total_modules->pre_confirmation_check(); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_BEFORE_ORDER_TOTALS_PROCESS'); $order_totals = $order_total_modules->process(); $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_TOTALS_PROCESS'); if (!isset($_SESSION['payment']) && !$credit_covers) { zen_redirect(zen_href_link(FILENAME_DEFAULT)); } // load the before_process // load the before_process function from the payment modules //$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_BEFOREPROCESS'); // create the order record $insert_id = $order->create($order_totals, 2); require(DIR_WS_LANGUAGES.'english/email_extras.php'); require(DIR_WS_LANGUAGES.'english/checkout_process.php'); // store the product info to the order $order->create_add_products($insert_id); $_SESSION['order_number_created'] = $insert_id; $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS'); $order->send_order_email($insert_id, 2); if (is_array($order_total_modules->modules)) { reset($order_total_modules->modules); while (list(, $value) = each($order_total_modules->modules)) { $class = substr($value, 0, strrpos($value, '.')); if (!isset($GLOBALS[$class])) continue; $GLOBALS[$class]->output=null; } } } else return false; }
Readers who are interested in more content related to zend framework can check out the special topics on this site: "Introduction Tutorial on Zend FrameWork Framework", "Summary of PHP Operation Zip File and Compression Techniques", "Summary of PHP File Operation", "Introduction Tutorial on ThinkPHP" ", "Summary of Common Methods of ThinkPHP", "Basic Tutorial for Getting Started with Smarty Templates" and "Summary of PHP Template Technology".
I hope this article will be helpful to everyone’s PHP program design based on the zend framework.