๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Online Store Settings Controller Documentation

File: /controllers/onlinestoresetting.php

Purpose: Advanced online store synchronization configuration and data transfer management

Last Updated: December 20, 2024

Total Functions: 10+

Lines of Code: ~584

---

๐Ÿ“‹ Overview

The Online Store Settings Controller manages advanced configuration for synchronizing data between the ERP system and external online stores. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**onlinestoresetting**Sync configurationonlinesettingid, url, availableStores, onlinestoreid, updatetype, timing settings
**onlinetemporder**Temporary order storageid, onlineorderid, customerid, ordertotal, createdatetime, orderstatus
**onlinetemporderproduct**Order line itemsid, orderid, productid, quantity, price, total
### Source Tables (Read for Sync)

Table NamePurposeKey Columns
**productcat**Categories to syncproductCatId, productCatName, productCatParent, logo, conditions
**product**Products to syncproductId, productName, productCatId, logo, logo1-7, conditions
**client**Customers to syncclientid, clientname, clientcode, clientmobile, clientdebt, conditions
**storedetail**Inventory quantitiesstoredetailid, productid, storeid, productquantity
### Configuration Tables

Table NamePurposeKey Columns
**store**Available storesstoreId, storeName, conditions
**clientarea**Customer areasid, name, description
**government**Geographic datagovernmentid, name
**goverarea**Area-government mappingid, governmentid, clientareaid
**youtubelink**Help videosyoutubelinkid, title, url
---

๐Ÿ”‘ Key Functions

1. Default Action / Settings Display

Location: Line 145

Purpose: Display online store synchronization configuration form

Process Flow:

1. Load current online store settings

2. Parse available stores from comma-separated string

3. Load client area and government data

4. Display configuration form with current values

Template Variables:

$onlineStoreSetting = getOrHandleOnlineStoreSetting();
$onlineStoreSetting->availableStores = explode(',', $onlineStoreSetting->availableStores);
$allStores = $storeDAO->queryAll();
$clientareaData = $ClientareaDAO->load($onlineStoreSetting->onlineclientareaid);

---

2. update() - Save Configuration

Location: Line 502

Purpose: Update synchronization settings and store selections

Function Signature:

function update()

Process Flow:

1. Extract configuration parameters

2. Process store selection array

3. Update timing and synchronization settings

4. Save to database

5. Handle store quantity updates if stores changed

Key Settings:

$onlineStoreSetting->url = $url;
$onlineStoreSetting->availableStores = $choosenStores_str;
$onlineStoreSetting->onlinestoreid = $onlinestoreid;
$onlineStoreSetting->updatetype = $updatetype;
$onlineStoreSetting->catprohour = $catprohour;
$onlineStoreSetting->catprominute = $catprominute;
$onlineStoreSetting->proquantityhour = $proquantityhour;
$onlineStoreSetting->proquantityminute = $proquantityminute;
$onlineStoreSetting->clientshour = $clientshour;
$onlineStoreSetting->clientsminute = $clientsminute;
$onlineStoreSetting->ordershour = $ordershour;
$onlineStoreSetting->ordersminute = $ordersminute;
$onlineStoreSetting->clientdebtchangeStartId = $clientdebtchangeStartId;

---

3. updateonlinecatsandproducts - Full Data Sync

Location: Line 174

Purpose: Complete synchronization of categories and products with images

Process Flow:

Phase 1: Category Synchronization

// Process categories in batches of 100
$limit = 100;
$all_items_count = $productCatExt->getCategoriesCount();

for ($i = $start; $i <= $all_items_count->productCatId; $i+=$limit) {
    $all_items = $productCatExt->queryAllOrderedLimitedForCURL($start, $limit);
    
    // Encode category images
    foreach ($all_items as $value) {
        $path = getcwd() . '/../views/default/images/cat_image/' . $value->logo;
        $value->logo_base64 = base64_encode(file_get_contents($path));
    }
    
    // Send to online store
    CURL_IT($all_items, $onlineStoreSetting->url . '/api_erp/copyCatsFromERPCURL');
}

Phase 2: Parent Relationship Update

// Update category parent relationships
for ($i = $start; $i <= $all_items_count->productCatId; $i+=$limit) {
    $all_items = $productCatExt->queryAllOrderedLimitedForCURL($start, $limit);
    CURL_IT($all_items, $onlineStoreSetting->url . '/api_erp/updateCatParentOnlyCurl');
}

Phase 3: Product Synchronization

// Process products in batches of 50
$limit = 50;
$all_products_count = $productExt->getProductsCountForCURLNormal('', $joinConditionWithStore);

for ($i = $start; $i <= $all_products_count->productId; $i+=$limit) {
    $allproduct = $productExt->queryAllOrderedLimitedSimpleForCurlNormal($start, $limit, '', $joinConditionWithStore);
    
    // Process each product
    foreach ($allproduct as $value) {
        // Set quantity based on store selection
        if (empty($onlineStoreSetting->availableStores)) {
            $value->quantity = 0;
        } else {
            $value->quantity = $value->sumProductQuantity;
        }
        
        // Encode multiple product images
        $path = getcwd() . '/../views/default/images/product_image/';
        $value->logo_base64 = base64_encode(file_get_contents($path . $value->logo));
        $value->logo1_base64 = base64_encode(file_get_contents($path . $value->logo1));
        $value->logo2_base64 = base64_encode(file_get_contents($path . $value->logo2));
        $value->logo3_base64 = base64_encode(file_get_contents($path . $value->logo3));
        $value->logo4_base64 = base64_encode(file_get_contents($path . $value->logo4));
        $value->logo5_base64 = base64_encode(file_get_contents($path . $value->logo5));
        $value->logo6_base64 = base64_encode(file_get_contents($path . $value->logo6));
        $value->logo7_base64 = base64_encode(file_get_contents($path . $value->logo7));
    }
    
    // Send to online store
    CURL_IT($allproduct, $onlineStoreSetting->url . '/api_erp/copyProductsFromERPCURL');
}

---

4. updateonlinecats - Category Only Sync

Location: Line 285

Purpose: Synchronize only categories (faster operation)

Features:

---

5. updateonlineproducts - Product Only Sync

Location: Line 340

Purpose: Synchronize only products (most common operation)

Features:

---

6. updateonlineclients - Client Sync

Location: Line 416

Purpose: Synchronize customer/client data to online store

Process Flow:

$limit = 100;
$all_clients_count = $clientEX->getClientsCountForCURLNormal(' and clientid != 1 ');

for ($i = $start; $i <= $all_clients_count->clientid; $i+=$limit) {
    $allclients = $clientEX->queryAllOrderedLimitedSimpleForCurlNormal($start, $limit, ' and clientid != 1 ');
    CURL_IT($allclients, $onlineStoreSetting->url . '/api_erp/copyClientsFromERPCURL');
    
    // Update start position
    $lastitem = end($allclients);
    $start = $lastitem->clientid;
}

Features:

---

7. onlineOrders - Order Management

Location: Line 442

Purpose: Display and filter online store orders

Function Signature:

// POST parameters
$clientId = (int) $_POST["clientid"];
$orderid = (int) $_POST["orderid"];  
$from = $_POST["from"];
$to = $_POST["to"];

Query Building:

$sqlQuery = '';
if ($orderid > 0) {
    $sqlQuery .= " and onlinetemporder.onlineorderid = " . $orderid;
} else {
    if ($clientId > 0) {
        $sqlQuery .= " and onlinetemporder.customerid = " . $clientId;
    }
    if (!empty($from)) {
        $sqlQuery .= " and onlinetemporder.createdatetime >= '" . $from . "'";
    }
    if (!empty($to)) {
        $sqlQuery .= " and onlinetemporder.createdatetime <= '" . $to . "'";
    }
}

// Default to today if no filters
if ($sqlQuery == "") {
    $sqlQuery .= " and onlinetemporder.createdatetime >= '" . date('Y-m-d 00:00:00') . "'";
    $sqlQuery .= " and onlinetemporder.createdatetime <= '" . date('Y-m-d 59:59:59') . "'";
}

---

8. onlineOrderDetails - Order Detail View

Location: Line 477

Purpose: Display detailed view of specific order

Process Flow:

1. Load order header information

2. Load order line items with product details

3. Display comprehensive order view

$onlineTempOrders = $onlineTempOrderEX->queryAllEX(' and onlinetemporder.id = ' . $id);
$onlineTempOrderProducts = $onlineTempOrderProductEX->queryByOrderidEX($onlineTempOrders->onlineorderid);

---

9. CURL_IT() - Data Transfer Function

Location: Line 558

Purpose: Send data to online store via CURL POST

Function Signature:

function CURL_IT($data_arr, $url)

Process:

$post = [
    'data_arr' => json_encode($data_arr), // Encode array as JSON
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// Disable SSL verification for internal transfers
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($ch);
curl_close($ch);

Features:

---

๐Ÿ”„ Workflows

Workflow 1: Complete Data Synchronization

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Full Data Sync to Online Store
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Verify Online Store Configuration
- Check online store URL is set
- Verify connection to online store
- Load synchronization settings
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Phase 1: Category Synchronization
FOR EACH batch of 100 categories:
โ”‚
โ†’ Load category data from productcat table
โ”‚
โ†’ Process category images
โ”‚ โ”œโ”€ Read image files from disk
โ”‚ โ”œโ”€ Convert to Base64 encoding
โ”‚ โ”‚ โ””โ”€ Attach to category data โ”‚
โ”‚
โ†’ Send batch via CURL to online store
โ”‚ โ”‚ โ””โ”€ POST to /api_erp/copyCatsFromERPCURL โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Continue until all categories processed โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Phase 2: Update Category Relationships
FOR EACH batch of 100 categories:
โ”‚
โ†’ Load parent-child relationships
โ”‚
โ”‚ โ””โ”€โ†’ Send relationship updates โ”‚
โ”‚ โ””โ”€ POST to /api_erp/updateCatParentOnlyCurl โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Phase 3: Product Synchronization
FOR EACH batch of 50 products:
โ”‚
โ†’ Load product data with store quantities
โ”‚ โ”‚ โ””โ”€ Filter by selected stores if configured โ”‚
โ”‚
โ†’ Calculate quantities
โ”‚ โ”œโ”€ If no stores selected: quantity = 0
โ”‚ โ”‚ โ””โ”€ Else: sum quantities from selected stores โ”‚
โ”‚
โ†’ Process multiple product images
โ”‚ โ”œโ”€ logo (main image)
โ”‚ โ”œโ”€ logo1 through logo7 (additional images)
โ”‚ โ”œโ”€ Convert each to Base64
โ”‚ โ”‚ โ””โ”€ Attach to product data โ”‚
โ”‚
โ†’ Send batch via CURL to online store
โ”‚ โ”‚ โ””โ”€ POST to /api_erp/copyProductsFromERPCURL โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Continue until all products processed โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Completion and Response
- Log completion time
- Return success response
- Update last sync timestamp
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Online Order Processing

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: View Online Orders
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Apply Order Filters
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ Filter Options:
โ”‚ - Specific order ID
โ”‚ - Customer/client ID
โ”‚ - Date range (from/to)
โ”‚ - Default: today's orders only
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Dynamic SQL Query
- Start with base onlinetemporder query
- Add client filter if specified
- Add date range filters if specified
- Add specific order filter if specified
- Apply default date filter if no filters
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Load Order Data
- Execute query against onlinetemporder table
- Load associated customer information
- Load online store configuration
- Prepare data for display
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Display Orders List
- Show order summary information
- Include customer details
- Show order totals and status
- Provide drill-down links for details
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay synchronization settings
`do=update``update()`Save synchronization configuration
`do=updateonlinecatsandproducts`Bulk syncFull category and product sync
`do=updateonlinecats`Category syncCategories only synchronization
`do=updateonlineproducts`Product syncProducts only synchronization
`do=updateonlineclients`Client syncCustomer data synchronization
`do=onlineOrders`Order listingDisplay/filter online orders
`do=onlineOrderDetails`Order detailsShow specific order details
### Required Parameters by Action

Configuration Update (do=update):

Order Filtering (do=onlineOrders):

Order Details (do=onlineOrderDetails):

---

๐Ÿงฎ Synchronization Logic

Store Selection Processing

$choosenStores = filter_input(INPUT_POST, 'stores', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
$choosenStores_str = '';
foreach ($choosenStores as $value) {
    $choosenStores_str .= $value . ",";
}
$choosenStores_str = rtrim($choosenStores_str, ','); // Remove trailing comma

Image Encoding Process

// Category images
$path = str_replace('\\', '/', getcwd()) . '/../views/default/images/cat_image/' . $value->logo;
$value->logo_base64 = base64_encode(file_get_contents($path));

// Product images (up to 8 per product)
$path = str_replace('\\', '/', getcwd()) . '/../views/default/images/product_image/';
$value->logo_base64 = base64_encode(file_get_contents($path . $value->logo));
$value->logo1_base64 = base64_encode(file_get_contents($path . $value->logo1));
// ... through logo7

Quantity Calculation

if (empty($onlineStoreSetting->availableStores)) {
    $value->quantity = 0; // No stores selected = no inventory
} else {
    $value->quantity = $value->sumProductQuantity; // Sum from selected stores
}

---

๐Ÿ”’ Security & Permissions

Data Transfer Security

Access Control

Input Validation

---

๐Ÿ“Š Performance Considerations

Batch Processing

1. Category Batches: 100 records per batch

2. Product Batches: 50 records per batch

3. Client Batches: 100 records per batch

Reasoning:

Image Processing Optimization

// Potential optimization: Check if image exists before encoding
if (file_exists($path . $value->logo)) {
    $value->logo_base64 = base64_encode(file_get_contents($path . $value->logo));
} else {
    $value->logo_base64 = ''; // Empty for missing images
}

Memory Management

---

๐Ÿ› Common Issues & Troubleshooting

1. Synchronization Timeouts

Issue: Large data sets cause timeout errors

Cause: Too many records processed at once

Solutions:

// Reduce batch sizes
$limit = 25; // Instead of 50 for products

// Add timeout handling
curl_setopt($ch, CURLOPT_TIMEOUT, 120); // 2 minutes

2. Image Upload Failures

Issue: Products sync but images missing

Cause: File path issues or missing images

Debug:

// Check image paths
$path = str_replace('\\', '/', getcwd()) . '/../views/default/images/product_image/';
echo "Image path: " . $path . $value->logo . "\n";

// Verify file exists
if (!file_exists($path . $value->logo)) {
    echo "Missing image: " . $value->logo . "\n";
}

3. Store Selection Issues

Issue: Wrong inventory quantities in online store

Cause: Store filter not applied correctly

Debug Query:

SELECT sd.productid, sd.storeid, sd.productquantity
FROM storedetail sd
WHERE sd.storeid IN (1,2,3) -- Selected stores
AND sd.productid = [PRODUCT_ID];

4. Connection Failures

Issue: CURL requests failing

Cause: Network issues or incorrect URLs

Debug:

$response = curl_exec($ch);
if ($response === false) {
    echo 'CURL Error: ' . curl_error($ch);
}
echo 'HTTP Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE);

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Configuration

1. Set online store URL
2. Select stores for synchronization
3. Configure timing parameters
4. Save settings and verify persistence
5. Test connection to online store

Test Case 2: Category Synchronization

1. Create test categories with images
2. Run category-only sync
3. Verify categories appear in online store
4. Check parent-child relationships
5. Verify image display

Test Case 3: Product Synchronization

1. Create products with multiple images
2. Set quantities in selected stores
3. Run product sync
4. Verify quantities match store selection
5. Check all images transferred correctly

Test Case 4: Order Processing

1. Create test orders in online store
2. Use order filtering interface
3. Test date range filtering
4. Test customer filtering
5. Verify order detail display

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘