Zen_cart is used to generate an order before payment. zen_cart is used to generate an order.
This example describes how zen_cart generates an order before payment. We will share this with you for your reference. The details are as follows:
In addition to paypal, the customer enters index. php through other payment methods? Main_page = checkout_confirmation.
But !! Paypal is a little different. It can only be returned from its official website [paypal.com] And Go To The checkout_process page to generate an order.
Accidents often occur: for example, the network is not smooth, and for example, the page is closed before the customer accidentally returns.
Then, our website's back-end will not be able to see what products the customer purchased (although we can see who bought them on the paypal back-end, we really cannot know what they actually bought ,) this is a depressing thing.
The principle of paypal leak-proof ticket is to place an order on the checkout_confirmation.php page !!!
Method: In the last part of this file
Copy codeThe Code is as follows: echo TITLE_CONTINUE_CHECKOUT_PROCEDURE. '<br/>'. TEXT_CONTINUE_CHECKOUT_PROCEDURE;
Add code later:
// Create the order record Leakage Prevention ticket if ($ _ SESSION ['payment'] = 'paypal ') {$ insert_id = $ order-> create ($ order_totals, 2 ); $ zco_notifier-> notify ('your Y _ Region'); $ payment_modules-> after_order_create ($ insert_id); $ zco_notifier-> NOTIFY ('your Y _ Region '); // store the product info to the order $ order-> create_add_products ($ insert_id); $ _ SESSION ['order _ number_created '] = $ insert_id;
In order to avoid the impact on other payment methods, the Code makes a judgment that only paypal payment will run the code for generating the order. After this section is added, you don't have to worry about missing orders.
If you need a more perfect practice 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');*/}
In addition, on the confirmation page, if the customer keeps refreshing the page, the order will be generated continuously. You can add a limit.
// Create the order record Leakage Prevention ticket if ($ _ SESSION ['payment'] = 'paypal 'and! Isset ($ _ SESSION ['order _ number_created ']) {$ insert_id = $ order-> create ($ order_totals, 2 ); $ zco_notifier-> notify ('your Y _ Region'); $ payment_modules-> after_order_create ($ insert_id); $ zco_notifier-> NOTIFY ('your Y _ Region '); // store the product info to the order $ order-> create_add_products ($ insert_id); $ _ SESSION ['order _ number_created '] = $ insert_id ;}
Add any location in pages/checkout_payment/header_php.php
unset($_SESSION['order_number_created']);
In this way, even if the customer keeps refreshing the confirmation page, because
$_SESSION['order_number_created']
Order no longer generated,
If the customer returns and modifies the shopping cart, $ _ SESSION ['order _ number_created '] will be cleared when it reaches checkout_payment again,
In fact, the code for generating 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 pageif (!$_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;}