Zen_cart the method of generating order before payment _php instance

Source: Internet
Author: User
Tags php template smarty template zend zend framework

The example in this article describes the method for generating orders before payment is realized by Zen_cart. Share to everyone for your reference, specific as follows:

Other than PayPal. The customer enters the index.php?main_page=checkout_confirmation through the other payment method to be able to produce the order.
But!! PayPal is a little different, it can only be from its official website [paypal.com] back and into the checkout_process this page, to produce orders

And accidents often happen: for example, the network is not smooth. Another example is the client accidentally closes the page before returning.

Then, our site will not see the background of what customers buy products (although in the background can see the PayPal who bought, but really can not know what he bought,) it is a good depressing thing

PayPal is the principle of the leak-proof list------in checkout_confirmation.php this page Mister Order!!!

The method is: In the last part of this file

Copy Code code as follows:
Echo Title_continue_checkout_procedure. ' <br/> '. Text_continue_checkout_procedure;

Add code later:

Create the order record Leakproof single 
if ($_session[' payment '] = = ' PayPal ') { 
$insert _id = $order->create ($order _tota LS, 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 the impact on other payment methods, the code made a judgment, only PayPal payment will run the code to generate the order, add this paragraph will not worry about the leakage of a single.

If a more perfect approach is needed to prevent customers from repeatedly generating orders while accessing the checkout process, a judgment is needed

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 in the confirmation page, if the customer has been refreshing the page, will always generate orders, you can add a limit.

Create the order record leak-proof single
if ($_session[' payment '] = = ' PayPal ' and!isset ($_session[' order_number_created ')) c2/> $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 at any point in the pages/checkout_payment/header_php.php

unset ($_session[' order_number_created '));

This way, even if the customer has been refreshing on the confirmation page because the

$_session[' order_number_created ']

Orders are no longer generated,

If the customer returns and modifies the cart, the $_session[' order_number_created ' will be cleared when it reaches checkout_payment again,

In fact, the code that generates the order can be written in the modules/payment/paypal.php function confirmation ().

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 isn't logged on, redirect them to the time out page if (!$_session[' customer_id ']) {zen_redirect (ze 
N_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)); }//Load the before_process//load the Before_process function from the payment modules//$zco _notifier->notify (' not
Ify_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;

 }

More interested readers of the Zend framework are available to view this site: "Introduction to the Zend Framework frame", "PHP operation zip file and compression skills summary", "PHP file Operation Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Smarty Template Primer Tutorial" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on Zend Framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.