Zen_cart implements the method for generating orders before payment. zen_cart generates orders _ PHP Tutorial

Source: Internet
Author: User
Zen_cart is used to generate an order before payment. zen_cart is used to generate an order. Zen_cart is used to generate an order before payment. This document describes how zen_cart generates an order before payment. For your reference, the details are as follows: how to generate an order before payment is implemented by zen_cart, and how to generate an order by zen_cart

This example describes how zen_cart generates an order before payment. We will share this with you for your reference. The details are as follows:

In addition to paypal, the customer enters index. php through other payment methods? Main_page = checkout_confirmation.
But !! Paypal is a little different. it can only be returned from its official website [paypal.com] and go to the checkout_process page to generate an order.

Accidents often occur: for example, the network is not smooth, and for example, the page is closed before the customer accidentally returns.

Then, our website's back-end will not be able to see what products the customer purchased (although we can see who bought them on the paypal back-end, we really cannot know what they actually bought ,) this is a depressing thing.

The principle of paypal leak-proof ticket is to place an order on the checkout_confirmation.php page !!!

Method: In the last part of this file
The code is as follows: echo TITLE_CONTINUE_CHECKOUT_PROCEDURE .'
'. TEXT_CONTINUE_CHECKOUT_PROCEDURE;

Add Code later:

// Create the order record leakage prevention ticket if ($ _ SESSION ['payment'] = 'PayPal ') {$ insert_id = $ order-> create ($ order_totals, 2 ); $ zco_notifier-> notify ('your y _ region'); $ payment_modules-> after_order_create ($ insert_id); $ zco_notifier-> NOTIFY ('your y _ region '); // 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 makes a judgment that only paypal payment will run the code for generating the order. after this section is added, you don't have to worry about missing orders.

If you need a more perfect practice to prevent customers from repeatedly generating orders when accessing the checkout process, you need to add a judgment.

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

In addition, on the confirmation page, if the customer keeps refreshing the page, the order will be generated continuously. you can add a limit.

// Create the order record leakage prevention ticket if ($ _ SESSION ['payment'] = 'PayPal 'and! Isset ($ _ SESSION ['Order _ number_created ']) {$ insert_id = $ order-> create ($ order_totals, 2 ); $ zco_notifier-> notify ('your y _ region'); $ payment_modules-> after_order_create ($ insert_id); $ zco_notifier-> NOTIFY ('your y _ region '); // store the product info to the order $ order-> create_add_products ($ insert_id); $ _ SESSION ['Order _ number_created '] = $ insert_id ;}

Add any location in pages/checkout_payment/header_php.php

unset($_SESSION['order_number_created']);

In this way, even if the customer keeps refreshing the confirmation page, because

$_SESSION['order_number_created']

Order no longer generated,

If the customer returns and modifies the shopping cart, $ _ SESSION ['Order _ number_created '] will be cleared when it reaches checkout_payment again,

In fact, the code for generating an order can be written in function confirmation () of modules/payment/paypal. php.

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 not logged on, redirect them to the time out pageif (!$_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['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;}

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.