PHP Modify zen-cart ordering and payment process to prevent missed orders_PHP tutorial
WBOY
Release: 2016-07-21 15:40:38
Original
1060 people have browsed it
Anyone who has used zen-cart knows that the steps for placing an order in zen-cart are as follows (the expressions in [] are not necessary):
1. Shopping cart
2. [delivery method]
3. Payment method
4. Order confirmation (confirmation)
5. [Third-party website payment]
6. Order processing (checkout process) - This step is more important because the information in the shopping cart will be written into the order here
7. Order successful (checkout success)
There is no problem with this process under normal circumstances. However, in the process from step 5 to step 6, the user may think that the payment is successful and close the web page directly, or the user may not be able to jump to the checkout_process page normally due to network reasons. The consequences of this are very serious, because the order Cannot be created normally.
Based on the above analysis, we hope to change the process slightly, that is, the order has been created before payment, so that even if the payment cannot be redirected from the third-party payment website, we will not have the user fail to pay successfully. There are no orders in the background. The modified blueprint basically looks like this:
1. After confirming the order on the checkour_confirmation page, you will directly proccess and enter the checkour_success page, where you can enter the payment page. As shown in the picture below:
2. If the customer fails to pay at that time, they can also enter their own backend to pay for historical orders. As shown below:
Let’s take a look at how to implement the above functions step by step.
1. First we need to transform the existing payment module. It is necessary to add a field paynow_action_url to the payment method class to represent the page URL for payment. In addition, a function, paynow_button($order_id), needs to be added to obtain the parameter hidden field code of the payment form. To add the paynow_action_url field, please add the following code at the end of the constructor of class payment:
To add the paynow_button($order_id) function, please add it to the payment class Add the following code after the last function:
Copy code The code is as follows:
function paynow_button($order_id){ if (is_array($this->modules)) { if (is_object($GLOBALS[$this->selected_module])) { return $GLOBALS[$this->selected_module]- >paynow_button($order_id); } } }
2. Take the paypal payment method as an example to explain how to implement it. In order not to destroy the original code of paypal, we will make a copy of the paypal.php file, name it paypalsimple.php, and make appropriate modifications to the code inside. The code is as shown below. You can see that the specification of form_action_url is removed here and paynow_action_url is given. Because we hope that the user will directly enter the checkout_process after clicking "Confirm Order", so if form_action_url is not specified, then the form to confirm the order will be It is submitted directly to the checkout_process page, and paynow_action_url is the value of the previous form_action_url. The implementation of the paynow_button function is also very simple. Here we just cut the content of the original process_button() function, but we do not use the global $order variable, but use $order = new order($order_id) to re- An object constructed in preparation for displaying the pay now button in historical orders. paypalsimple.php
Copy code The code is as follows:
/** * @package paypalsimple payment module * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: paypalsimple.php 4960 2009-12-29 11:46:46Z gary $ */ // ensure dependencies are loaded include_once((IS_ADMIN_FLAG === true ? DIR_FS_CATALOG_MODULES : DIR_WS_MODULES) . 'payment/paypal/paypal_functions.php'); class paypalsimple { var $code, $title, $description, $enabled; // class constructor function paypalsimple() { global $order; $this->code = 'paypalsimple'; $this->title = MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_TITLE; if(IS_ADMIN_FLAG === true){ $this->title = MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_ADMIN_TITLE; } $this->description = MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_DESCRIPTION; $this->sort_order = MODULE_PAYMENT_PAYPAL_SIMPLE_SORT_ORDER; $this->enabled = ((MODULE_PAYMENT_PAYPAL_SIMPLE_STATUS == 'True') ? true : false); if ((int)MODULE_PAYMENT_PAYPAL_SIMPLE_ORDER_STATUS_ID > 0) { $this->order_status = MODULE_PAYMENT_PAYPAL_SIMPLE_ORDER_STATUS_ID; } $this->paynow_action_url = 'https://' . MODULE_PAYMENT_PAYPAL_SIMPLE_HANDLER; if (is_object($order)) $this->update_status(); } // class methods function update_status() { global $order, $db; if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_SIMPLE_ZONE > 0) ) { $check_flag = false; $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_SIMPLE_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); while (!$check->EOF) { if ($check->fields['zone_id'] < 1) { $check_flag = true; break; } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) { $check_flag = true; break; } $check->MoveNext(); } if ($check_flag == false) { $this->enabled = false; } } } function javascript_validation() { return false; } function selection() { $text = MODULE_PAYMENT_SIMPLE_PAYPAL_TEXT_CATALOG_LOGO.' '.MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_TITLE . '
4. Display pay now button in historical orders. There are three pages that need to display the pay now button: account, account_history, and account_history_info. The implementation here is similar to the implementation of the checkout_success page, except that the parameters of the function paynow_button passed to $payment_modules are different, so I will not go into details here. Summary: After the above modifications, our process is as follows: 1. Shopping cart (shopping cart) 2. [delivery method] 3. Payment method ( payment method) 4. Order confirmation (confirmation) 5. Order processing (checkout process) 6. Order successful (checkout success) 7. [Third-party website payment] Because everything from order confirmation to order processing is completed on our own website, and the order already exists before entering the payment website, this way there will be no dropped orders.
http://www.bkjia.com/PHPjc/321347.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321347.htmlTechArticleEveryone who has used zen-cart knows that the ordering steps in zen-cart are as follows (where [ The expressions in ] are not necessary): 1. Shopping cart 2. [delivery method] 3. Support...
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