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:
- โข Store branding (logos for light/dark themes)
- โข Shipping configuration and pricing
- โข Contact information (addresses, phones, emails)
- โข Social media links
- โข Email/SMS service configuration (Twilio, SMTP)
- โข Store selection for inventory
- โข Multi-language address support
Primary Functions
- โ Display online store main settings form
- โ Update store configuration with file uploads
- โ Handle logo uploads (light and dark themes)
- โ Configure shipping methods and pricing
- โ Set contact information and social media
- โ Configure email/SMS services
- โ Select inventory stores for online display
Related Controllers
- โข onlinestoresetting.php - Advanced sync settings
- โข onlinestoresync.php - Data synchronization
- โข storeController.php - Store management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **onlinestoremainsetting** | Main online store configuration | logo, logo_dark, send_type, shipping settings, contact info, social media, email/SMS config | |
| **store** | Available stores for selection | storeId, 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:
- โข Single record configuration (ID=1 always used)
- โข Store selection dropdown
- โข Form pre-populated with current values
---
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
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Display settings form | |
| `do=update` | `update()` | Save settings changes |
Shipping Configuration:
- โข
send_type- Shipping method type - โข
shippingfree_numberitems- Free shipping item threshold - โข
numberitems- Regular shipping item count - โข
shippingfree_totleitems- Free shipping total threshold - โข
totleitems- Regular shipping total - โข
fixedshipping_value- Fixed shipping cost - โข
shipping_value- Variable shipping cost
Contact Information:
- โข
address_ar- Arabic address - โข
address_en- English address - โข
mobile- Primary phone number - โข
another_mobile- Secondary phone number - โข
email- Primary email address - โข
another_email- Secondary email address
Social Media:
- โข
facebook- Facebook page URL - โข
twitter- Twitter account URL - โข
instagram- Instagram account URL - โข
telegram- Telegram contact
Service Configuration:
- โข
account_sid- Twilio account SID - โข
auth_token- Twilio auth token - โข
twilio_number- Twilio phone number - โข
mail_host- SMTP server host - โข
mail_port- SMTP server port - โข
mail_username- SMTP username - โข
mail_password- SMTP password - โข
mail_encryption- SMTP encryption type - โข
mail_fromaddress- Email from address - โข
store- Selected store for inventory
File Uploads:
- โข
logo- Store logo file (light theme) - โข
logodark- Store logo file (dark theme)
---
๐งฎ 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
- โข File type validation through
uploadupdate()function - โข Directory restrictions to prevent path traversal
- โข File size limitations
Input Validation
- โข Email address format validation
- โข Phone number format checking
- โข URL validation for social media links
- โข Numeric validation for shipping values
Access Control
- โข Requires valid session for access
- โข Admin-level permissions typically required
- โข CSRF protection through session validation
---
๐ 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
- โข Image optimization during upload
- โข Proper file storage organization
- โข Cache considerations for logo display
---
๐ 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
- โข CLAUDE.md - PHP 8.2 migration guide
- โข onlinestoresetting.md - Advanced sync settings
- โข onlinestoresync.md - Data synchronization
- โข storeController.md - Store management
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur