VOOZH about

URL: https://deepwiki.com/gp247net/shop/4.3-order-processing-and-email-notifications

⇱ Order Processing and Email Notifications | gp247net/shop | DeepWiki


Loading...
Menu

Order Processing and Email Notifications

This page documents the order creation process, post-order processing, email notification system, and dynamic validation logic that occurs after a customer completes checkout. For the checkout flow leading up to order creation, see page 4.2 (Checkout Process).

Overview

After checkout confirmation, the system executes three primary operations:

  1. Order Creation: Converts cart session data into persistent order records in shop_order, shop_order_detail, and shop_order_total tables
  2. Email Notifications: Sends order confirmation emails to customers and administrators based on configuration
  3. Payment Processing: Delegates to payment plugins for transaction processing

The entry point is ShopCartController::addOrder(), which orchestrates these operations.


Sources:

Order Creation Process

The ShopCartController::addOrder() method handles order creation in Step 06 of the checkout flow. It retrieves data from session storage and constructs database records.

Order Creation Workflow

Diagram: Order Creation Sequence


Sources:

Session Data Requirements

The addOrder method expects the following session keys to be populated during checkout:

Session KeyDescriptionSet During Step
dataCheckoutCart items for the current storeStep 03 (checkout screen)
dataTotalTotal calculations from pluginsStep 05 (checkout confirm)
shippingAddressCustomer shipping informationStep 04 (process checkout)
paymentMethodSelected payment method keyStep 04 (process checkout)
shippingMethodSelected shipping method keyStep 04 (process checkout)
storeCheckoutStore ID being checked outStep 02 (prepare checkout)

Sources:

Order Data Structure

Diagram: Order Database Schema


Sources:

Initial Order Status Values

Orders are created with default status constants defined in ShopCartController:

ORDER_STATUS_NEW = 1 // New order, awaiting processing
PAYMENT_UNPAID = 1 // Payment not received
SHIPPING_NOTSEND = 1 // Products not shipped

These constants are used in lines src/Controllers/ShopCartController.php567-569 when constructing the $dataOrder array.

Sources:

Product Detail Processing

For each cart item, the system retrieves current product data and builds order detail records:


This loop constructs the $arrCartDetail array that is passed to ShopOrder::createOrder().

Sources:

Post-Order Processing

After order creation, the system executes post-processing operations through gp247_order_process_after_success() and delegates to payment plugins if configured.

Post-Order Success Hook

The helper function gp247_order_process_after_success() is called immediately after ShopOrder::createOrder() returns successfully. It handles:

  1. Email notification dispatch
  2. Configuration-based conditional execution
  3. Downloadable product link generation

Diagram: Post-Order Processing Flow


Sources:

Payment Plugin Integration

After email processing, the system checks for a configured payment plugin. If a payment method requires additional processing, control transfers to the plugin's processOrder() method:


Sources:

Complete Order Method

The completeOrder() method is the final step when no payment plugin processing is required (e.g., cash on delivery). It:

  1. Retrieves the order ID from session
  2. Clears cart for the checked-out store
  3. Clears session checkout data
  4. Redirects to order success page

Diagram: Complete Order Flow


Sources:

Email Notifications

The gp247_order_process_after_success() function sends order confirmation emails based on two configuration flags: order_success_to_admin and order_success_to_customer.

Email Configuration Gates

Both email types require email_action_mode to be enabled. If disabled, no emails are sent.

if ((gp247_config('order_success_to_admin') || gp247_config('order_success_to_customer')) 
 && gp247_config('email_action_mode')) {
 // Email processing
}

Sources:

Email Data Preparation

The function loads the complete order with relationships and constructs an $orderDetail array:

Diagram: Email Data Construction


For each order item, the system:

  1. Retrieves the product using ShopProduct::getDetail($detail['product_id'])
  2. Checks if the product has tag == GP247_TAG_DOWNLOAD
  3. If downloadable, adds $product->downloadPath->path to the email data
  4. Formats price using gp247_currency_render()

Sources:

Email Template Variables

Both email templates receive identical data structures:

VariableTypeDescription
$orderIDstringOrder identifier
$tonamestringCustomer full name (first_name + last_name)
$addressstringConcatenated address fields
$phonestringCustomer phone number
$commentstringOrder comment/notes
$currencystringCurrency code (e.g., "USD")
$orderDetailarrayArray of product items with sku, name, price, qty, total, linkDownload
$subtotalstringRendered subtotal amount
$shippingstringRendered shipping cost
$discountstringRendered discount amount
$otherFeestringRendered other fees
$totalstringRendered total amount

Sources:

Admin Notification Email

Sent to gp247_store_info('email') with subject from language file key email.order.email_subject_to_admin.

The template renders order information and a product table. The gp247_mail_send() function is called with:


Sources:

Customer Notification Email

Sent to the customer's email address ($data['email']) with subject from email.order.email_subject_customer.

Configuration includes a replyTo field set to the store email:


Sources:

Email Template Structure

Both templates extend a base layout and render in a responsive HTML structure:


Sources:

Dynamic Validation

The gp247_order_mapping_validate() helper function generates Laravel validation rules dynamically based on configuration settings. This allows stores to require different customer fields without code changes.

Validation Rule Generation

Diagram: Dynamic Validation Logic


Sources:

Configuration-Based Field Validation

The function checks pairs of configuration keys for each optional field:

  1. Field visibility: gp247_config('customer_fieldname') - Controls if field is shown
  2. Field requirement: gp247_config('customer_fieldname_required') - Controls if field is required

Example for last name field:


This pattern repeats for: address1, address2, address3, phone, country, postcode, company, first_name_kana, last_name_kana.

Sources:

Validation Rules Table

FieldConditional ConfigValidation Rule (if required)Validation Rule (if optional)
first_nameAlways requiredrequired|string|max:100N/A
emailAlways requiredrequired|string|email|max:255N/A
shippingMethoduse_shippingrequiredNot added
paymentMethoduse_paymentrequiredNot added
last_namecustomer_lastnamerequired|string|max:100nullable|string|max:100
address1customer_address1required|string|max:100nullable|string|max:100
address2customer_address2required|string|max:100nullable|string|max:100
address3customer_address3required|string|max:100nullable|string|max:100
phonecustomer_phonerequired|regex:/^0[^0][0-9\-]{6,12}$/nullable|regex:/^0[^0][0-9\-]{6,12}$/
countrycustomer_countryrequired|string|min:2|in:{codes}nullable|string|min:2|in:{codes}
postcodecustomer_postcoderequired|min:5nullable|min:5
companycustomer_companyrequired|string|max:100nullable|string|max:100
first_name_kanacustomer_name_kanarequired|string|max:100nullable|string|max:100
last_name_kanacustomer_name_kanarequired|string|max:100nullable|string|max:100

Sources:

Usage in Checkout Process

The validation rules are applied during Step 04 (Process Checkout) in ShopCartController::processCheckout():


Sources:

Custom Validation Messages

The function generates localized validation messages for all fields:


Sources:

Payment Integration

The order processing system integrates with payment methods through a plugin architecture. After order creation, if a payment method is configured, the system hands off to the payment plugin's processing method.


Sources:

Integration Points

The Order Processing system integrates with several other components:

  1. Cart System: Orders are created from cart data
  2. Product System: Order items reference products
  3. Customer System: Orders are associated with customer accounts
  4. Email System: Notifications are sent via the email system
  5. Payment Plugins: Payment processing is delegated to payment method plugins
  6. Shipping Plugins: Shipping methods are used from shipping plugins

Sources:

Conclusion

The Order Processing system forms a critical part of the GP247/Shop e-commerce platform, handling the conversion of shopping carts to orders and managing the entire order lifecycle. Its modular design allows for flexible integration with payment and shipping methods while providing robust administrative tools for order management.