๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Online Store Main Settings Controller Documentation

File: /controllers/onlinestoremainsetting.php

Purpose: Manages core online store configuration including shipping, contact info, and branding

Last Updated: December 20, 2024

Total Functions: 2

Lines of Code: ~76

---

๐Ÿ“‹ Overview

The Online Store Main Settings Controller manages the fundamental configuration settings for the online store. It handles the core business and operational settings that define how the online store operates, including:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**onlinestoremainsetting**Main online store configurationlogo, logo_dark, send_type, shipping settings, contact info, social media, email/SMS config
**store**Available stores for selectionstoreId, storeName, conditions
---

๐Ÿ”‘ Key Functions

1. Default Action / Settings Display

Location: Line 9

Purpose: Display the online store main settings form

Process Flow:

1. Load current settings from onlinestoremainsetting table (ID=1)

2. Load available stores for selection

3. Assign data to template variables

4. Display edit form

Template Variables:

$showData = R::load('onlinestoremainsetting', 1);
$stores = R::getAll('select storeId,storeName from store where conditions=0');
$smarty->assign('showData', $showData);
$smarty->assign('stores', $stores);

Features:

---

2. update() - Update Settings

Location: Line 20

Purpose: Update online store main settings with file upload support

Process Flow:

1. Handle File Uploads:

- Process logo upload (light theme)

- Process dark logo upload (dark theme)

- Use uploadupdate() function for file handling

2. Update Configuration Fields:

- Shipping configuration

- Contact information

- Social media links

- Email/SMS service settings

- Store selection

3. Save and Respond:

- Store updated record

- Return JSON response for AJAX calls

- Redirect for standard form submission

Key Settings Updated:

Shipping Configuration:

$updateData->send_type = $_POST['send_type'];
$updateData->shippingfree_numberitems = $_POST['shippingfree_numberitems'];
$updateData->numberitems = $_POST['numberitems'];
$updateData->shippingfree_totleitems = $_POST['shippingfree_totleitems'];
$updateData->totleitems = $_POST['totleitems'];
$updateData->fixedshipping_value = $_POST['fixedshipping_value'];
$updateData->shipping_value = $_POST['shipping_value'];

Contact Information:

$updateData->address_ar = $_POST['address_ar'];
$updateData->address_en = $_POST['address_en'];
$updateData->mobile = $_POST['mobile'];
$updateData->another_mobile = $_POST['another_mobile'];
$updateData->email = $_POST['email'];
$updateData->another_email = $_POST['another_email'];

Social Media:

$updateData->facebook = $_POST['facebook'];
$updateData->twitter = $_POST['twitter'];
$updateData->instagram = $_POST['instagram'];
$updateData->telegram = $_POST['telegram'];

Email/SMS Services:

// Twilio SMS Configuration
$updateData->account_sid = $_POST['account_sid'];
$updateData->auth_token = $_POST['auth_token'];
$updateData->twilio_number = $_POST['twilio_number'];

// SMTP Email Configuration  
$updateData->mail_host = $_POST['mail_host'];
$updateData->mail_port = $_POST['mail_port'];
$updateData->mail_username = $_POST['mail_username'];
$updateData->mail_password = $_POST['mail_password'];
$updateData->mail_encryption = $_POST['mail_encryption'];
$updateData->mail_fromaddress = $_POST['mail_fromaddress'];

File Upload Handling:

$logo = uploadupdate('logo', 'logourl', False, 0, 0, 'onlinestoremainsetting');
$logo_dark = uploadupdate('logodark', 'logodarkurl', False, 0, 0, 'onlinestoremainsetting');
$updateData->logo = $logo;
$updateData->logo_dark = $logo_dark;

---

๐Ÿ”„ Workflows

Workflow 1: Settings Configuration

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Configure Store Settings
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Current Settings
- Query onlinestoremainsetting table (ID=1)
- Load available stores list
- Display settings form
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2User Configures Settings
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ Branding:
โ”‚ - Upload store logo (light theme)
โ”‚ - Upload store logo (dark theme)
โ”‚
โ”‚ Shipping:
โ”‚ - Shipping method type
โ”‚ - Free shipping thresholds
โ”‚ - Shipping costs and rules
โ”‚
โ”‚ Contact Information:
โ”‚ - Business addresses (AR/EN)
โ”‚ - Phone numbers
โ”‚ - Email addresses
โ”‚ - Social media links
โ”‚
โ”‚ Services:
โ”‚ - Twilio SMS configuration
โ”‚ - SMTP email settings
โ”‚ - Store selection for inventory
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process Form Submission
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ File Uploads:
โ”‚ - Process logo uploads
โ”‚ - Validate file types and sizes
โ”‚ - Save to appropriate directories
โ”‚
โ”‚ Data Validation:
โ”‚ - Validate email addresses
โ”‚ - Validate phone numbers
โ”‚ - Validate shipping values
โ”‚ - Validate store selection
โ”‚
โ”‚ Database Update:
โ”‚ - Update onlinestoremainsetting record
โ”‚ - Save all configuration fields
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Success/Error Response
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ AJAX Request?
โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚
โ”‚ NO
โ–ผ
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ Redirect to Settings Page
โ”‚ - Show success message
โ”‚ - Reload with updated values
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay settings form
`do=update``update()`Save settings changes
### Required Parameters for Update

Shipping Configuration:

Contact Information:

Social Media:

Service Configuration:

File Uploads:

---

๐Ÿงฎ Configuration Logic

Shipping Rules Configuration

The system supports various shipping methods and thresholds:

1. Free Shipping by Item Count:

- shippingfree_numberitems: Minimum items for free shipping

- numberitems: Regular shipping item threshold

2. Free Shipping by Total Amount:

- shippingfree_totleitems: Minimum total for free shipping

- totleitems: Regular shipping total threshold

3. Shipping Cost Structure:

- fixedshipping_value: Fixed shipping cost

- shipping_value: Variable shipping calculation

File Upload Handling

// Logo upload with validation
$logo = uploadupdate('logo', 'logourl', False, 0, 0, 'onlinestoremainsetting');
$logo_dark = uploadupdate('logodark', 'logodarkurl', False, 0, 0, 'onlinestoremainsetting');

// Parameters:
// - Field name from form
// - URL field name (for fallback)
// - Resize flag (False = no resize)
// - Width (0 = original)
// - Height (0 = original)  
// - Directory prefix

---

๐Ÿ”’ Security & Permissions

File Upload Security

Input Validation

Access Control

---

๐Ÿ“Š Performance Considerations

Database Optimization

1. Single Record Pattern:

- Always uses ID=1 for settings

- No indexing needed beyond primary key

- Fast single-record lookups

2. Store Selection:

- Efficient store query with conditions filter

- Small result set for dropdown

File Upload Performance

---

๐Ÿ› Common Issues & Troubleshooting

1. Logo Upload Failures

Issue: Logos not uploading or displaying

Cause: File permissions, invalid file types, or size limits

Debug Steps:

// Check upload directory permissions
// Verify file types allowed in uploadupdate() function
// Check PHP upload_max_filesize and post_max_size settings

2. Settings Not Saving

Issue: Form submission successful but settings unchanged

Cause: Database connection issues or field name mismatches

Debug:

-- Check if record exists
SELECT * FROM onlinestoremainsetting WHERE id = 1;

-- Verify field names match POST data
DESCRIBE onlinestoremainsetting;

3. SMTP Configuration Issues

Issue: Email configuration not working

Cause: Incorrect SMTP settings or firewall blocks

Test Configuration:

// Test SMTP connection manually
// Verify host, port, encryption settings
// Check authentication credentials

4. Store Selection Not Working

Issue: Store dropdown empty or not saving

Cause: Inactive stores or conditions filter

Debug Query:

SELECT storeId, storeName, conditions FROM store WHERE conditions = 0;

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Configuration

1. Load settings form
2. Verify current values displayed
3. Update basic contact information
4. Save and verify changes
5. Check form reload shows new values

Test Case 2: Logo Upload

1. Prepare test image files (light/dark themes)
2. Upload logos through form
3. Verify files saved to correct directories
4. Check database contains file references
5. Verify logos display on frontend

Test Case 3: Shipping Configuration

1. Set various shipping rules
2. Test free shipping thresholds
3. Configure multiple shipping options
4. Verify frontend shipping calculations
5. Test edge cases (zero values, very high thresholds)

Test Case 4: Service Integration

1. Configure Twilio SMS settings
2. Test SMS functionality
3. Configure SMTP email settings  
4. Test email sending
5. Verify error handling for invalid credentials

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘