search
HomeBackend DevelopmentPHP Tutorialzen_cart implements the method of generating orders before payment

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;

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;

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;);*/
}

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;
}

In pages/checkout_payment/header_php. Add

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

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

$_SESSION[&#39;order_number_created&#39;]
## 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;
}

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
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
How do you modify data stored in a PHP session?How do you modify data stored in a PHP session?Apr 27, 2025 am 12:23 AM

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Give an example of storing an array in a PHP session.Give an example of storing an array in a PHP session.Apr 27, 2025 am 12:20 AM

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

How does garbage collection work for PHP sessions?How does garbage collection work for PHP sessions?Apr 27, 2025 am 12:19 AM

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

How can you trace session activity in PHP?How can you trace session activity in PHP?Apr 27, 2025 am 12:10 AM

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

How can you use a database to store PHP session data?How can you use a database to store PHP session data?Apr 27, 2025 am 12:02 AM

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

Explain the concept of a PHP session in simple terms.Explain the concept of a PHP session in simple terms.Apr 26, 2025 am 12:09 AM

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

How do you loop through all the values stored in a PHP session?How do you loop through all the values stored in a PHP session?Apr 26, 2025 am 12:06 AM

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

Explain how to use sessions for user authentication.Explain how to use sessions for user authentication.Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

See all articles

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.