VOOZH about

URL: https://deepwiki.com/gp247net/shop/7-admin-interface-patterns

⇱ Admin Interface Patterns | gp247net/shop | DeepWiki


Loading...
Menu

Admin Interface Patterns

This document describes the common patterns used across admin controllers and views in the GP247/Shop system. These patterns provide consistency and maintainability for administrative CRUD operations, multi-language support, and custom field integration.

Overview

Admin controllers in GP247/Shop follow consistent patterns for:

  • CRUD operations (Create, Read, Update, Delete)
  • Multi-language content management
  • Configuration-driven field visibility
  • Custom field integration
  • Multi-store data isolation
  • Validation and error handling

All admin controllers extend RootAdminController from the GP247/Core package, which provides common functionality for authentication, layout rendering, and administrative operations.


Sources: src/Admin/Controllers/AdminCategoryController.php1-18 src/Views/admin/screen/category.blade.php1-10 src/Views/admin/screen/customer_edit.blade.php1-18

Controller Structure Pattern

Admin controllers follow a consistent structure with standard methods for CRUD operations. Each controller handles a specific entity type.

Standard Controller Methods:

MethodPurposeHTTP Method
index()List all entities with filtering/paginationGET
create()Display create formGET
postCreate()Process create form submissionPOST
edit($id)Display edit form for specific entityGET
postEdit($id)Process edit form submissionPOST
deleteList()Handle bulk deletion via AJAXPOST
checkPermisisonItem($id)Verify access permissions-

Sources: src/Admin/Controllers/AdminCategoryController.php20-153 src/Admin/Controllers/AdminCategoryController.php159-257 src/Admin/Controllers/AdminCategoryController.php262-283

List View Pattern

The list view pattern handles entity listing with sorting, filtering, pagination, and bulk actions.

Key Components:

  1. Data Preparation - Build query with filters and sorting
  2. Column Configuration - Define table headers ($listTh)
  3. Row Data Mapping - Transform model data to display format ($dataTr)
  4. Action Buttons - Define available actions per row
  5. Menu Configuration - Top/right/left menu items

Example from AdminCategoryController:

$listTh = [
 'image' => gp247_language_render('admin.category.image'),
 'title' => gp247_language_render('admin.category.title'),
 'parent' => gp247_language_render('admin.category.parent'),
 'top' => gp247_language_render('admin.category.top'),
 'status' => gp247_language_render('admin.category.status'),
 'sort' => gp247_language_render('admin.category.sort'),
 'action' => gp247_language_render('action.title')
];

The controller transforms each model row into a display array with HTML formatting:

$dataMap = [
 'image' => gp247_image_render($row->getThumb(), '50px', '50px', $row['title']),
 'title' => $row['title'],
 'parent' => $row['parent'] ? ($categoriesTitle[$row['parent']] ?? '') : 'ROOT',
 'top' => $row['top'] ? '<span class="badge badge-success">ON</span>' : ...,
 'status' => $row['status'] ? '<span class="badge badge-success">ON</span>' : ...,
 'sort' => $row['sort'],
 'action' => $this->procesListAction($arrAction)
];

Sources: src/Admin/Controllers/AdminCategoryController.php40-120

Multi-Language Content Pattern

Entities that require multi-language support use a separate description table and follow a consistent pattern for handling translations.

Pattern Structure:

  1. Main entity table stores non-translatable fields
  2. Description table stores translatable content with lang column
  3. Forms loop through active languages to collect translations
  4. Controllers save all language versions in separate table

Form Pattern in Blade:

Each language gets a collapsible card with translation fields:


Controller Pattern for Saving:


Sources: src/Views/admin/screen/category.blade.php28-113 src/Admin/Controllers/AdminCategoryController.php228-240 src/Admin/Controllers/AdminCategoryController.php342-353

Configuration-Driven Field Visibility Pattern

Admin forms use the gp247_config_admin() helper to conditionally display fields based on system configuration. This allows different stores to have different field requirements without code changes.

Pattern Usage:


Common Configuration Checks:

Configuration KeyPurpose
customer_lastnameSplit name into first/last vs single field
customer_name_kanaShow Japanese phonetic name fields
customer_phoneDisplay phone number field
customer_postcodeDisplay postal code field
customer_address2Display secondary address field
customer_address3Display tertiary address field
customer_countryDisplay country selection
customer_sexDisplay gender selection
customer_birthdayDisplay birthday field
customer_groupDisplay customer group field

Sources: src/Views/admin/screen/customer_edit.blade.php24-80 src/Views/admin/screen/customer_edit.blade.php82-119 src/Views/admin/screen/customer_edit.blade.php121-333

Custom Fields Integration Pattern

Both models and views support custom fields through a standardized pattern that allows extending entities with additional fields without modifying core tables.

Pattern Structure:

  1. Custom fields are defined in admin_custom_field table
  2. Values stored in admin_custom_field_detail table
  3. Forms include custom field rendering component
  4. Controllers use gp247_custom_field_update() helper

Model Pattern - Auto-delete on entity removal:


View Pattern - Render custom fields:


Controller Pattern - Save custom fields:



Sources: src/Models/ShopCategory.php63-88 src/Views/admin/screen/category.blade.php266-268 src/Admin/Controllers/AdminCategoryController.php196-204 src/Admin/Controllers/AdminCategoryController.php250-252 src/Admin/Controllers/AdminCategoryController.php308-316 src/Admin/Controllers/AdminCategoryController.php363-365

Multi-Store Pattern

Admin controllers handle multi-store scenarios by conditionally including store selection fields and filtering data based on the admin's store context.

Pattern in Controllers:


Pattern in Views:



Sources: src/Admin/Controllers/AdminCategoryController.php49-78 src/Admin/Controllers/AdminCategoryController.php242-249 src/Admin/Controllers/AdminCategoryController.php355-362 src/Views/admin/screen/category.blade.php137-177

Validation Pattern

Controllers use Laravel's Validator with dynamic validation rules that adapt to custom fields and configuration.

Standard Validation Structure:


Validation for Updates:

For edit operations, the unique rule excludes the current record:


Sources: src/Admin/Controllers/AdminCategoryController.php189-217 src/Admin/Controllers/AdminCategoryController.php301-329

Form Structure Pattern

Admin forms follow a consistent structure with standardized HTML and CSS classes.

Form Layout:


Key Form Patterns:

PatternImplementation
Error highlighting{{ $errors->has('field') ? ' text-red' : '' }} class
Old input restoration{{ old('field', $entity['field']??'') }}
Icon prefixesInput groups with prepended icons
Validation feedbackError span below input with form-text class
CSRF protection@csrf token in footer
Multi-selectSelect2 plugin with select2 class and multiple attribute

Sources: src/Views/admin/screen/category.blade.php19-297

Deletion and Permission Pattern

Deletion operations follow a consistent pattern with permission checking and cascade handling.

Controller Deletion Handler:


Model Cascade Pattern:



Sources: src/Admin/Controllers/AdminCategoryController.php377-406 src/Models/ShopCategory.php63-88

Data Display Helpers Pattern

Admin views use consistent helper functions for rendering data.

Common Helper Functions:

HelperPurposeExample Usage
gp247_image_render()Render image with dimensionsgp247_image_render($row->getThumb(), '50px', '50px', $title)
gp247_language_render()Translate textgp247_language_render('admin.category.title')
gp247_route_admin()Generate admin routegp247_route_admin('admin_category.edit', ['id' => $id])
gp247_route_front()Generate frontend routegp247_route_front('category.detail', ['alias' => $alias])
gp247_config_admin()Get admin configurationgp247_config_admin('customer_phone')
gp247_file()Generate file URLgp247_file(old('image', $entity['image']??''))
gp247_clean()Sanitize input datagp247_clean($dataCreate, [], true)

Badge Rendering Pattern:


Action Button Pattern:


Sources: src/Admin/Controllers/AdminCategoryController.php82-114 src/Views/admin/component/new_customer.blade.php1-52

Summary

The admin interface patterns provide a consistent, maintainable approach to building administrative functionality in GP247/Shop:

  • CRUD Operations: Standardized methods for create, read, update, delete
  • Multi-Language Support: Separate description tables with language-specific forms
  • Configuration-Driven Fields: Dynamic field visibility based on gp247_config_admin()
  • Custom Fields: Extensible field system without schema modifications
  • Multi-Store Integration: Conditional store filtering and selection
  • Validation: Dynamic rule building with custom field support
  • Form Structure: Consistent HTML patterns with error handling
  • Deletion Cascades: Automatic cleanup of related data via model events
  • Helper Functions: Standardized rendering and data manipulation

These patterns ensure that adding new admin functionality follows established conventions, making the codebase easier to understand and extend.

Controller Architecture

The Admin Interface is primarily implemented through a set of specialized controllers that extend the RootAdminController class. Each controller handles specific aspects of the admin functionality.


Sources: src/Admin/Controllers/AdminOrderController.php src/Admin/Controllers/AdminProductController.php src/Admin/Controllers/AdminOrderStatusController.php src/Admin/Controllers/AdminShipingStatusController.php

Order Management

The order management system is one of the core components of the Admin Interface, allowing administrators to view, create, edit, and process customer orders.

Order Listing

The order listing page provides a comprehensive view of all orders with filtering options:

  • Filter by date range
  • Filter by order status
  • Search by customer email
  • Sort by various criteria (ID, date, email)

The implementation uses the AdminOrder model's getOrderListAdmin method to retrieve and filter orders based on the admin's search criteria.

Order Detail and Editing

The order detail page allows administrators to:

  • View complete order information
  • Edit order status, payment status, and shipping status
  • Add or remove products from the order
  • Update product quantities and prices
  • Process payments and shipping
  • Generate invoices

Sources: src/Admin/Controllers/AdminOrderController.php402-437 src/Admin/Controllers/AdminOrderController.php474-550

Order Creation

Administrators can manually create new orders through the admin interface:

  1. Access the order creation form
  2. Enter customer information
  3. Select products to add to the order
  4. Set payment and shipping methods
  5. Submit the order

The implementation is handled by the create and postCreate methods in the AdminOrderController.

Invoice Generation

The admin interface provides functionality to generate and print invoices for orders. This is implemented in the invoice method of AdminOrderController, which formats order data into a printable invoice view.

Sources: src/Admin/Controllers/AdminOrderController.php760-820

Product Management

The product management system allows administrators to create, edit, clone, and delete products of various types.

Product Types

The system supports three types of products:

  1. Single Products: Standard individual products with their own attributes and pricing
  2. Product Builds (Bundles): Collections of single products sold together as a package
  3. Product Groups: Sets of related products displayed together but purchased individually

Sources: src/Admin/Controllers/AdminProductController.php43-50 src/Admin/Controllers/AdminProductController.php257-292 src/Admin/Controllers/AdminProductController.php298-350 src/Admin/Controllers/AdminProductController.php357-399

Product Listing

The product listing page displays all products with filtering options:

  • Filter by category
  • Search by product name or SKU
  • Sort by various criteria

This is implemented in the index method of AdminProductController.

Product Creation and Editing

The product creation and editing pages provide forms for adding and modifying product information:

  • Basic information (name, SKU, alias)
  • Descriptions in multiple languages
  • Price, cost, and promotional prices
  • Images and additional media
  • Attributes and variations
  • Stock and inventory settings
  • Categorization and tagging

Different forms are provided for each product type, with specific fields and options based on the type.

Product Cloning

The system provides functionality to clone existing single products, creating a copy with a new SKU and name but retaining all other attributes. This is implemented in the cloneProduct method of AdminProductController.

Sources: src/Admin/Controllers/AdminProductController.php1150-1207

Status Management

The Admin Interface includes dedicated controllers for managing order statuses and shipping statuses.

Order Status Management

The AdminOrderStatusController handles the creation, editing, and deletion of order statuses. The system includes several protected default statuses that cannot be deleted:

  1. New
  2. Processing
  3. Hold
  4. Canceled
  5. Done
  6. Failed
  7. Refunded

Administrators can create additional custom statuses as needed.

Sources: src/Admin/Controllers/AdminOrderStatusController.php207-217

Shipping Status Management

Similarly, the AdminShipingStatusController manages shipping statuses, with protected default values:

  1. Not sent
  2. Sending
  3. Shipping done
  4. Refunded

Sources: src/Admin/Controllers/AdminShipingStatusController.php205-212

Subscription Management

The Admin Interface includes functionality for managing customer subscriptions through the AdminSubscribe model. This includes:

  • Listing all subscriptions
  • Filtering subscriptions by various criteria
  • Creating new subscriptions
  • Viewing subscription details

Sources: src/Admin/Models/AdminSubscribe.php30-47 src/Admin/Models/AdminSubscribe.php56-60

Sample Data Management

The Admin Interface includes functionality to populate the store with sample data for testing and demonstration purposes through the ShopSample command.

This command:

  • Creates sample categories (Food, Travel, Fruits)
  • Creates sample brands (Nike, Adidas, Puma)
  • Creates sample suppliers (ABC Corp, XYZ Inc, DEF Ltd)
  • Creates sample products for each category

This feature is particularly useful for setting up a demonstration environment or testing the shop functionality.

Sources: src/Commands/ShopSample.php39-354

Integration with Core System

The Admin Interface integrates with the core GP247 system through the GP247 Service Provider mechanism. All admin controllers extend the RootAdminController class, which provides common functionality for admin operations including:

  • Access control and authentication
  • Layout rendering
  • Error handling
  • Flash messaging

Data Workflow

The typical data workflow in the Admin Interface follows this pattern:


This workflow applies to all major operations in the Admin Interface, including order management, product management, and status configuration.

Summary

The Admin Interface of the GP247/Shop system provides a comprehensive set of tools for managing all aspects of the e-commerce platform. Its modular architecture, organized around specific controllers for different administrative functions, makes it flexible and maintainable, while its integration with the core GP247 system ensures consistency and reliability across the platform.