VOOZH about

URL: https://deepwiki.com/gp247net/shop/2.2-configuration-driven-system-behavior

⇱ Configuration-Driven System Behavior | gp247net/shop | DeepWiki


Loading...
Menu

Configuration-Driven System Behavior

This document explains how the GP247/Shop package uses runtime configuration values stored in the database to control system behavior without requiring code changes. Configuration determines field visibility, validation rules, feature enablement, email triggers, and business logic across the entire application.

For information about how configurations are initially populated, see Data Seeders and Initialization. For multi-store configuration isolation, see Multi-Store and Multi-Vendor Architecture.


Configuration Storage Architecture

The system stores all configuration values in the admin_config table, accessed through the AdminConfig model. Each configuration entry uses a hierarchical structure with three identifying fields:

FieldPurposeExample
groupLogical categorygp247_cart
codeSub-categorycustomer_config, display_config
keySpecific settingcustomer_phone, product_top
valueStored value1, 12, json_array
store_idStore isolationStore-specific values

Sources: src/DB/seeders/DataShopInitializeSeeder.php196-197 src/DB/seeders/DataShopDefaultSeeder.php94-123


Configuration Groups and Purpose

The system organizes configurations into logical groups that control different aspects of behavior:

Core Configuration Groups

Group CodePurposeKey Examples
admin_configAdmin panel settingsADMIN_NAME, ADMIN_TITLE, hidden_copyright_footer
display_configDisplay limitsproduct_top, product_list, product_relation, product_viewed
customer_configCustomer field controlcustomer_phone, customer_lastname, customer_address1_required
sendmail_configEmail triggerswelcome_customer, order_success_to_admin, order_success_to_customer
captcha_configCaptcha settingscaptcha_mode, captcha_page, captcha_method
config_layoutUI element visibilitylink_account, link_language, link_currency, link_cart

Customer Configuration Pattern

The system uses a two-level pattern for customer fields:

  1. Visibility control: customer_phone (0 or 1) - Show/hide field
  2. Requirement control: customer_phone_required (0 or 1) - Make field mandatory

This pattern applies to: lastname, phone, address1, address2, address3, country, postcode, company, sex, birthday, group, name_kana

Sources: src/DB/seeders/DataShopDefaultSeeder.php94-123 src/DB/seeders/DataShopInitializeSeeder.php196-197


Configuration Access Layer

Primary Access Function: gp247_config()

The gp247_config() helper function retrieves configuration values within the current store context. It automatically resolves the active store from session or application configuration.


Usage Examples

Throughout the codebase, gp247_config() is called to make runtime decisions:


Sources: src/Library/Helpers/customer.php257-266 src/Library/Helpers/order.php136-142


Dynamic Validation Rules

The most significant impact of configuration-driven behavior is on validation. The system constructs validation rules at runtime based on configuration values.


Order Validation Mapping

The gp247_order_mapping_validate() function constructs validation rules for checkout:

Base Requirements:

  • first_name: Always required
  • email: Always required
  • shippingMethod: Required if gp247_config('use_shipping') is enabled
  • paymentMethod: Required if gp247_config('use_payment') is enabled

Conditional Fields: Each customer field follows this pattern:


The function returns an array with validate and messages keys, ready for Laravel validator usage.

Sources: src/Library/Helpers/order.php89-211

Customer Data Insert Mapping

The gp247_customer_data_insert_mapping() function builds validation for new customer registration:

Base Requirements:

  • first_name: Always required
  • email: Always required, unique in shop_customer table
  • password: Always required, with configurable strength requirements

Configurable Password Validation: Password requirements are themselves configuration-driven via gp247_customer_validate_password():

  • Minimum length: gp247_config('customer_password_min', null, 6)
  • Maximum length: gp247_config('customer_password_max', null, 16)
  • Require letters: gp247_config('customer_password_letter')
  • Require mixed case: gp247_config('customer_password_mixedcase')
  • Require numbers: gp247_config('customer_password_number')
  • Require symbols: gp247_config('customer_password_symbol')

Sources: src/Library/Helpers/customer.php183-396 src/Library/Helpers/customer.php644-670


Customer Field Visibility and Requirements

The system uses configuration to control which customer fields appear in forms and whether they are mandatory.

Supported Customer Fields

Field NameVisibility ConfigRequired Config
Last Namecustomer_lastnamecustomer_lastname_required
Phonecustomer_phonecustomer_phone_required
Address 1customer_address1customer_address1_required
Address 2customer_address2customer_address2_required
Address 3customer_address3customer_address3_required
Countrycustomer_countrycustomer_country_required
Postcodecustomer_postcodecustomer_postcode_required
Companycustomer_companycustomer_company_required
Sexcustomer_sexcustomer_sex_required
Birthdaycustomer_birthdaycustomer_birthday_required
Groupcustomer_groupcustomer_group_required
Name Kanacustomer_name_kanacustomer_name_kana_required

Sources: src/Library/Helpers/customer.php212-333 src/Library/Helpers/order.php105-175


Email Notification Control

Email sending is entirely configuration-driven. The system checks configuration values before sending any email notification.

Email Configuration Keys

Configuration KeyPurposeChecked In
email_action_modeMaster email on/off switchAll email functions
welcome_customerSend welcome email on registrationgp247_customer_sendmail_welcome()
order_success_to_adminSend order notification to admingp247_order_process_after_success()
order_success_to_customerSend order confirmation to customergp247_order_process_after_success()
contact_to_customerSend contact form copy to customerContact form handler
contact_to_adminSend contact form to adminContact form handler

Order Success Email Implementation

The gp247_order_process_after_success() function demonstrates the pattern:


Sources: src/Library/Helpers/order.php7-84 src/Views/front/email/order_success_to_admin.blade.php1-68 src/Views/front/email/order_success_to_customer.blade.php1-68

Welcome Email Implementation

The gp247_customer_sendmail_welcome() function sends welcome emails to new customers:


Sources: src/Library/Helpers/customer.php84-102


Display Configuration

Display configurations control pagination limits and list sizes throughout the frontend.

Display Configuration Keys

KeyPurposeDefault Value
product_topFeatured products on homepage12
product_listProducts per page in listings12
product_relationRelated products on detail page4
product_viewedRecently viewed products4
item_listGeneric items per page12
item_topFeatured items12

These values are seeded by DataShopDefaultSeeder:


Controllers query these configurations to set pagination:


Sources: src/DB/seeders/DataShopDefaultSeeder.php100-105


Layout Configuration

Layout configurations control the visibility of UI elements in the frontend header/navigation.

Layout Configuration Keys

KeyPurposeControls
link_accountShow/hide account menuCustomer login/register links
link_languageShow/hide language switcherLanguage selection dropdown
link_currencyShow/hide currency switcherCurrency selection dropdown
link_cartShow/hide cart iconShopping cart link

All layout configurations default to 1 (visible):


Template files check these configurations before rendering:


Sources: src/DB/seeders/DataShopDefaultSeeder.php109-112


Configuration Initialization Process

Configuration values are populated during system installation and store creation through two seeders.


DataShopInitializeSeeder

This seeder populates global, non-store-specific data:

  1. Admin Menus: Creates the shop menu hierarchy
  2. Currencies: Inserts USD and VND currency records
  3. Statuses: Populates order, payment, and shipping status tables
  4. Admin Home Modules: Adds dashboard widgets
  5. Global Configurations: Inserts shared configuration entries
  6. Language Translations: Adds all shop-related translation strings

Sources: src/DB/seeders/DataShopInitializeSeeder.php16-573

DataShopDefaultSeeder

This seeder populates store-specific configurations:

  1. Retrieves Store ID: Gets current store from session or uses root store
  2. Inserts Configuration Records: Calls dataConfigShop($storeId) to build array
  3. Creates Frontend Links: Adds "All Products" link to store menu
  4. Adds Layout Blocks: Creates product display blocks for the store

The dataConfigShop() method returns an array of configuration records:


Sources: src/DB/seeders/DataShopDefaultSeeder.php12-125


Admin Configuration Interface

Administrators manage sendmail configurations through a dedicated interface.


The config_sendmail.blade.php view renders the configuration interface:


Each checkbox has:

  • check-data-config class: JavaScript hook for AJAX updates
  • data-store attribute: Identifies which store's configuration to update
  • name attribute: Configuration key to update
  • checked state: Current configuration value

The interface displays the master email_action_mode status at the top, indicating whether email functionality is globally enabled.

Sources: src/Views/admin/screen/config_shop/config_sendmail.blade.php1-27


Runtime Configuration Resolution Flow

When application code requests a configuration value, the system follows this resolution process:


The gp247_config() function signature typically supports default values:


Sources: Based on common implementation patterns observed in src/Library/Helpers/order.php and src/Library/Helpers/customer.php


Configuration Impact Summary

The configuration system enables different stores within a multi-store installation to have dramatically different behaviors without code modification:

Store A Configuration:

  • Customer phone: Required
  • Customer lastname: Optional
  • Welcome email: Enabled
  • Order email to admin: Enabled
  • Products per page: 20

Store B Configuration:

  • Customer phone: Hidden
  • Customer lastname: Required
  • Welcome email: Disabled
  • Order email to admin: Disabled
  • Products per page: 12

Both stores share the same codebase but behave differently based on their admin_config entries. This architecture enables:

  1. Flexible Business Rules: Change validation requirements per store
  2. Feature Toggles: Enable/disable features administratively
  3. Localization Support: Different field requirements for different countries
  4. A/B Testing: Test different configurations without code deployment
  5. White-Label Installations: Customize behavior per client/brand

Sources: src/DB/seeders/DataShopDefaultSeeder.php32-33 src/DB/seeders/DataShopDefaultSeeder.php94-123