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

Jun 07, 2018 pm 05:12 PM
pay

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to pay for a taxi ride on Baidu Maps. Introduction to the payment steps for a taxi ride. How to pay for a taxi ride on Baidu Maps. Introduction to the payment steps for a taxi ride. Mar 13, 2024 am 10:04 AM

Baidu Map APP has now become the preferred travel navigation software for many users, so some of the functions here are comprehensive and can be selected and operated for free to solve some of the problems that you may encounter in daily travel. You can all check some of your own travel routes and plan some of your own travel plans. After checking the corresponding routes, you can choose appropriate travel methods according to your own needs. So whether you choose some public transportation, Cycling, walking or taking a taxi can all satisfy your needs. There are corresponding navigation routes that can successfully lead you to a certain place. Then everyone will feel more convenient if they choose to take a taxi. There are many drivers They are all able to take orders online, and taxi-hailing has become super

How uniapp application implements payment and order management How uniapp application implements payment and order management Oct 19, 2023 am 10:37 AM

uniapp is a cross-platform application development framework that can develop small programs, Apps and H5 at the same time. In uniapp applications, payment and order management are very common needs. This article will introduce how to implement payment functions and order management in the uniapp application, and give specific code examples. 1. Implementing the payment function The payment function is the key to realizing online transactions, and it usually requires integrating the SDK of a third-party payment platform. The following are the specific steps to implement the payment function in uniapp: Register and obtain a third-party payment platform

Pay using PHP and PayPal API Pay using PHP and PayPal API Jun 19, 2023 pm 04:13 PM

With the increasing popularity of online transactions, payment methods are gradually diversifying, among which PayPal is very popular as a widely used payment method. If you want to use PayPal to process transactions on your website or application, then you can use PHP and PayPal API to complete the payment process easily. PayPalAPI is a set of programming interfaces for interacting with PayPal. Through the API, you can receive notifications from PayPal, query the latest transaction information, and initiate payments.

How to pay for taking the bus in Wuhan How to pay for taking the bus in Wuhan Oct 13, 2022 pm 02:17 PM

Payment methods for taking buses in Wuhan: 1. For cash payment, you need to prepare sufficient change in advance and put the money directly into the coin slot; 2. Swipe the Wuhan Tong card. The full name of Wuhan Tong is Wuhan City Card, which is an integrated circuit Card, also known as chip card; 3. Alipay electronic bus card, first get a Wuhan electronic bus card in Alipay, and then directly scan the QR code to deduct the money when getting on the bus; 4. WeChat bus code payment , open the WeChat "Ride Code" applet, activate the Wuhan "Ride Code", and you can directly scan the QR code to deduct payment and get on the bus.

Establish an order payment table for the grocery shopping system in MySQL Establish an order payment table for the grocery shopping system in MySQL Nov 01, 2023 pm 03:48 PM

To establish the order payment table of the grocery shopping system in MySQL, specific code examples are required. With the development of the Internet, shopping has become more and more convenient. In the shopping process, order payment is an important part of the shopping process. The grocery shopping system not only needs to have an order generation function, but also must have a complete payment process, because only successful payment can be regarded as completing a transaction. This article will describe how to create an order payment table for the grocery shopping system in MySQL and provide specific code examples. 1. Design of order payment table. The order payment table in the grocery shopping system stores orders.

How to close Meituan Takeout Express Payment How to close Meituan Takeout Express Payment Mar 27, 2024 am 10:41 AM

In the fast-paced modern life, Meituan Takeaway is deeply loved by consumers for its convenient services and rich choices. Among them, the ultra-fast payment function brings great convenience to users. Payment can be completed with one click, eliminating tedious input steps. However, many users don't like paying directly without confirmation, so they want to turn off this feature. So how to turn off the fast payment of Meituan Waimai? In the following, the editor of this website will bring you a detailed step-by-step setup tutorial, I hope it can help you! 1. Click the &quot;Meituan Takeout&quot; shortcut icon on the mobile phone desktop. 2. Log in to the Meituan takeout app on your mobile phone and click &quot;My&quot; in the lower right corner. 3. In the My interface, click &quot;Enter Wallet&quot;. 4. On the Meituan Wallet interface, click the &quot;Settings&quot; icon in the upper right corner

What does paynow payment mean? What does paynow payment mean? Sep 30, 2022 am 11:01 AM

PayNow payment is an electronic transfer service. Users can directly initiate real-time SGD transfers to the payee through the mobile phone number, ID card/FIN number, UEN number or PayNow QR code specified by the payee without the need for the other party. Bank account information.

Where can Meituan instant discount be deducted by default when payment is enabled_ Tutorial on Meituan instant discount being deducted by default when payment is enabled Where can Meituan instant discount be deducted by default when payment is enabled_ Tutorial on Meituan instant discount being deducted by default when payment is enabled Mar 28, 2024 am 11:00 AM

1. First open the [Meituan] APP, click the [My] button in the bottom navigation bar. 2. Then click the [My Wallet] function button and click the [Cash Voucher] button. 3. Then in the top function bar, click the [Instant Deduction] button, and click the switch button to turn on [Default Deduction during Payment] to successfully turn it on.

See all articles