VOOZH about

URL: https://deepwiki.com/gp247net/shop/2.1-data-seeders-and-initialization

⇱ Data Seeders and Initialization | gp247net/shop | DeepWiki


Loading...
Menu

Data Seeders and Initialization

Purpose and Scope

This document explains the database seeding system used to initialize the GP247/Shop package with essential data. Two seeder classes populate the system with admin interface structures, reference data, configurations, and multilingual translations. This page covers DataShopInitializeSeeder (global initialization) and DataShopDefaultSeeder (store-specific setup). For information about how configurations control runtime behavior, see Configuration-Driven System Behavior. For multi-store data isolation patterns, see Multi-Store and Multi-Vendor Architecture.


Seeder Architecture Overview

The initialization system uses two complementary seeders that populate different scopes of data:

Seeder Execution Flow and Data Population


Sources: src/DB/seeders/DataShopInitializeSeeder.php1-1277 src/DB/seeders/DataShopDefaultSeeder.php1-126


DataShopInitializeSeeder: Global System Initialization

The DataShopInitializeSeeder class populates global, system-wide data that applies across all stores. This seeder runs once during initial package installation.

Database Tables Populated by DataShopInitializeSeeder


Sources: src/DB/seeders/DataShopInitializeSeeder.php24-198

Admin Menu Structure

The seeder creates a hierarchical admin menu structure with six top-level blocks:

Block KeyTitleIconSortChildren
ADMIN_SHOP_BLOCKadmin.menu_titles.ADMIN_SHOP_BLOCKfab fa-shopify100All shop menus
ADMIN_SHOP_CATALOGadmin.menu_titles.ADMIN_SHOP_CATALOGfas fa-folder-open70Product, Category, Supplier, Brand
ADMIN_SHOP_ORDERadmin.menu_titles.ADMIN_SHOP_ORDERfas fa-shopping-basket60Order
ADMIN_SHOP_CUSTOMERadmin.menu_titles.ADMIN_SHOP_CUSTOMERfas fa-user50Customer, Subscribe
ADMIN_SHOP_SHIPPINGadmin.menu_titles.ADMIN_SHOP_SHIPPINGfas fa-truck40(Shipping plugins)
ADMIN_SHOP_PAYMENTadmin.menu_titles.ADMIN_SHOP_PAYMENTfas fa-recycle30(Payment plugins)
ADMIN_SHOP_REPORTadmin.menu_titles.ADMIN_SHOP_REPORTfas fa-chart-line20Report Product
ADMIN_SHOP_SETTINGadmin.menu_titles.ADMIN_SHOP_SETTINGfas fa-cogs10Currency, Statuses, Attributes, Tax, Config

The seeder first deletes any existing menu entries src/DB/seeders/DataShopInitializeSeeder.php30-48 to ensure a clean slate, then inserts the new structure src/DB/seeders/DataShopInitializeSeeder.php54-126

Sources: src/DB/seeders/DataShopInitializeSeeder.php30-163

Reference Data: Currencies

Two default currencies are inserted:


Sources: src/DB/seeders/DataShopInitializeSeeder.php130-135

Reference Data: Status Definitions

The seeder populates three status tables with predefined workflow states:

ShopPaymentStatus - Payment workflow states:

  • ID 1: Unpaid
  • ID 2: Partial payment
  • ID 3: Processing
  • ID 4: Paid
  • ID 5: Refund
  • ID 6: Cancelled

ShopShippingStatus - Shipping workflow states:

  • ID 1: New
  • ID 2: Packing
  • ID 3: Shipping
  • ID 4: Shipped
  • ID 5: Cancelled
  • ID 6: Returned

ShopOrderStatus - Order workflow states:

  • ID 1: New
  • ID 2: Processing
  • ID 3: Hold
  • ID 4: Cancelled
  • ID 5: Done
  • ID 6: Failed

Sources: src/DB/seeders/DataShopInitializeSeeder.php167-174

Admin Dashboard Components

The seeder registers four dashboard components in the AdminHome table:

View PathSize (cols)SortDescription
gp247-shop-admin::component.top_info12100Top-level statistics
gp247-shop-admin::component.order_month1290Monthly order chart
gp247-shop-admin::component.new_order670Recent orders list
gp247-shop-admin::component.new_customer660Recent customers list

These components are rendered on the admin home page using the view paths specified.

Sources: src/DB/seeders/DataShopInitializeSeeder.php178-193

Multilingual Translations

The seeder inserts extensive translations into the Languages table, covering:

  • Admin menu titles (~30 entries): Menu labels for Vietnamese and English
  • Category management (~30 entries): Form labels, validation messages
  • Currency management (~20 entries): Currency form fields
  • Email templates (~70 entries): Email subject lines, content templates
  • Order status (~10 entries): Status display names
  • Payment/Shipping status (~12 entries each): Status display names
  • Tax management (~10 entries): Tax configuration labels
  • Supplier/Brand (~30 entries each): Management interface labels
  • Subscribe (~12 entries): Email subscription labels
  • Cart/Checkout (~80 entries): All cart and checkout interface text
  • Customer forms (~40 entries): Registration, login, profile labels
  • Product display (~60 entries): Product listing and detail labels
  • Admin notifications (~30 entries): Success/error messages
  • Order emails (~30 entries): Order confirmation email templates

Each translation entry has the structure:

  • code: Translation key (e.g., 'admin.menu_titles.order')
  • text: Translated text
  • position: Translation group
  • location: Language code ('vi' or 'en')

Sources: src/DB/seeders/DataShopInitializeSeeder.php200-1277


DataShopDefaultSeeder: Store-Specific Initialization

The DataShopDefaultSeeder class populates store-specific data when a new store is created. It runs for each store and uses the store ID to scope all inserted data.

Store-Specific Data Flow


Sources: src/DB/seeders/DataShopDefaultSeeder.php20-91

Store Configuration Data

The seeder inserts 20 configuration entries grouped by code within the gp247_cart group:

Admin Configuration (admin_config code)

KeyDefault ValueDetail Translation Key
ADMIN_NAMEGP247 Systemadmin.env.ADMIN_NAME
ADMIN_TITLEGP247 Adminadmin.env.ADMIN_TITLE
hidden_copyright_footer0admin.env.hidden_copyright_footer
hidden_copyright_footer_admin0admin.env.hidden_copyright_footer_admin

Display Configuration (display_config code)

KeyDefault ValueDetail Translation Key
product_top12store.display.product_top
product_list12store.display.list_product
product_relation4store.display.relation_product
product_viewed4store.display.viewed_product
item_list12store.display.item_list
item_top12store.display.item_top

Captcha Configuration (captcha_config code)

KeyDefault ValueDetail Translation Key
captcha_mode0admin.captcha.captcha_mode
captcha_page[]admin.captcha.captcha_page
captcha_method(empty)admin.captcha.captcha_method

Layout Configuration (config_layout code)

KeyDefault ValueDetail Translation Key
link_account1admin.config_layout.link_account
link_language1admin.config_layout.link_language
link_currency1admin.config_layout.link_currency
link_cart1admin.config_layout.link_cart

Send Mail Configuration (sendmail_config code)

KeyDefault ValueDetail Translation Key
welcome_customer0sendmail_config.welcome_customer
order_success_to_admin0sendmail_config.order_success_to_admin
order_success_to_customer0sendmail_config.order_success_to_cutomer
contact_to_customer0sendmail_config.contact_to_customer
contact_to_admin1sendmail_config.contact_to_admin

All configurations include the store_id field to ensure proper multi-store isolation.

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

Frontend Links

The seeder creates navigation links in the FrontLink table:


Each link is created with a UUID and attached to the store via the stores() relationship using attach($storeId). This enables the multi-store architecture where links can be scoped to specific stores.

Sources: src/DB/seeders/DataShopDefaultSeeder.php35-60

Frontend Layout Blocks

Two layout blocks are inserted into FrontLayoutBlock:

Product Home Block

  • name: "Product Home (Shop Package)"
  • position: bottom
  • page: front_home
  • text: shop_product_home
  • type: view
  • sort: 10
  • template: Inherited from store
  • store_id: Current store

Product Last View Block

  • name: "Product Last View (Shop Package)"
  • position: left
  • page: shop_product_detail,shop_product_list,shop_search
  • text: shop_product_last_view
  • type: view
  • sort: 20
  • template: Inherited from store
  • store_id: Current store

These blocks enable the frontend template system to render product-related widgets on specific pages.

Sources: src/DB/seeders/DataShopDefaultSeeder.php63-88


Configuration Data Structure

Both seeders insert data into the AdminConfig table, which uses a three-level hierarchy:

AdminConfig Table Structure


Configuration Access Pattern

The configurations are accessed at runtime using helper functions:

  • gp247_config($key): Retrieves configuration for current store context
  • gp247_config_admin($key): Retrieves configuration, potentially switching store context

Example usage from admin view:


The sendmail_config entries control email sending behavior, which can be toggled via the admin interface at the "Shop Configuration" page.

Sources: src/DB/seeders/DataShopDefaultSeeder.php94-123 src/Views/admin/screen/config_shop/config_sendmail.blade.php1-27


Execution Context

When Seeders Run

DataShopInitializeSeeder runs:

  • During initial package installation via php artisan migrate --seed
  • When explicitly invoked: php artisan db:seed --class=GP247\Shop\DB\seeders\DataShopInitializeSeeder
  • Typically runs once per application installation

DataShopDefaultSeeder runs:

  • When a new store is created (triggered by store creation logic)
  • Uses session('lastStoreId') to determine which store to initialize
  • Falls back to GP247_STORE_ID_ROOT if session is empty
  • Can be run multiple times for different stores

Method Structure

Both seeders follow the standard Laravel seeder pattern:


DataShopInitializeSeeder contains helper methods:

  • updateDataVersion(): Updates package version metadata
  • dataPaymentStatus(): Returns payment status array
  • dataShippingStatus(): Returns shipping status array
  • dataOrderStatus(): Returns order status array
  • dataConfigShop(): Returns configuration array

DataShopDefaultSeeder contains:

  • dataConfigShop($storeId): Returns store-specific configuration array

Sources: src/DB/seeders/DataShopInitializeSeeder.php16-1277 src/DB/seeders/DataShopDefaultSeeder.php12-126


Insert Strategies

Both seeders use insertOrIgnore() to prevent duplicate entries during re-execution:


This ensures idempotent seeding - running the seeder multiple times won't create duplicate records. The database's unique constraints (typically on primary keys or unique indexes) determine what constitutes a duplicate.

For admin menus, the seeder explicitly deletes old entries before inserting new ones src/DB/seeders/DataShopInitializeSeeder.php30-48 to handle schema changes across package versions.

Sources: src/DB/seeders/DataShopInitializeSeeder.php130-198 src/DB/seeders/DataShopDefaultSeeder.php33-88