Home > Backend Development > PHP Tutorial > zen_cart implements the method of generating orders before payment

zen_cart implements the method of generating orders before payment

不言
Release: 2023-03-30 15:08:02
Original
2124 people have browsed it

This article mainly introduces the method of zen_cart to generate orders before payment. It analyzes in detail the specific steps and related implementation techniques of zen_cart to generate orders before payment in the form of examples. Friends in need can refer to this article

The example describes how zen_cart implements 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 index.php?main_page=checkout_confirmation page through other payment methods.
But!! Paypal It is a bit different. It can only place an order after returning from its official website [paypal.com] and entering the checkout_process page.

But accidents often happen: for example, the network is not smooth. Another example is the customer's failure. Be careful to close the page before returning.

Then, our website backend will not be able to see what product the customer bought (although you can see who bought it in the paypal backend, but there is really no way to know who bought it. What did you buy?) This is a very depressing thing.

The principle of paypal’s anti-leakage order is to place an order on the checkout_confirmation.php page!!!

The method is: copy the code
at the last part of this file

##The code is as follows:

echo TITLE_CONTINUE_CHECKOUT_PROCEDURE . &#39;<br />&#39; . TEXT_CONTINUE_CHECKOUT_PROCEDURE;
Copy after login

Add the code after:

// create the order record 防漏单 
if ($_SESSION[&#39;payment&#39;] == &#39;paypal&#39;) { 
$insert_id = $order->create($order_totals, 2);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE&#39;);
$payment_modules->after_order_create($insert_id);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE&#39;);
// store the product info to the order
$order->create_add_products($insert_id);
$_SESSION[&#39;order_number_created&#39;] = $insert_id;
Copy after login

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[&#39;payment&#39;]!=&#39;paypal&#39;){
/*// create the order record
$insert_id = $order->create($order_totals, 2);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE&#39;);
$payment_modules->after_order_create($insert_id);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE&#39;);
// store the product info to the order
$order->create_add_products($insert_id);
$_SESSION[&#39;order_number_created&#39;] = $insert_id;
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS&#39;);
//send email notifications
$order->send_order_email($insert_id, 2);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL&#39;);*/
}
Copy after login

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[&#39;payment&#39;] == &#39;paypal&#39; and !isset($_SESSION[&#39;order_number_created&#39;])) {
$insert_id = $order->create($order_totals, 2);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE&#39;);
$payment_modules->after_order_create($insert_id);
$zco_notifier->notify(&#39;NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE&#39;);
// store the product info to the order
$order->create_add_products($insert_id);
$_SESSION[&#39;order_number_created&#39;] = $insert_id;
}
Copy after login

In pages/checkout_payment/header_php. Add

unset($_SESSION[&#39;order_number_created&#39;]);
Copy after login

anywhere in php. In this way, even if the customer keeps refreshing the confirmation page, because

$_SESSION[&#39;order_number_created&#39;]
Copy after login
## has been set.

#The order is no longer generated.

If the customer returns to modify the shopping cart, $_SESSION['order_number_created'] will be cleared when the checkout_payment is reached again.

In fact, it is generated The order code can be written in the function confirmation() of modules/payment/paypal.php.

The code is as follows:

function confirmation() {
if(!isset($_SESSION[&#39;order_number_created&#39;]))
{
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[&#39;order_number_created&#39;] = $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;
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone’s study, For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Development of PHP version of UnionPay payment interface


##

The above is the detailed content of zen_cart implements the method of generating orders before payment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
pay
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template