π Hekmat Online Store β Comprehensive PHP MVC E-Commerce Platform
A fully-featured, production-ready e-commerce platform built with a custom PHP MVC framework. Includes user authentication, product catalog with categories/subcategories, shopping cart, order management, comments system, address selection via interactive map, and responsive Persian UI.
Overview
Features
Technology Stack
Project Structure
Architecture
Core Modules
Database Schema
Security Features
Frontend Features
Installation Guide
Environment Configuration
Routing
Controllers Reference
Models Reference
Helper Functions
Views Structure
API Integrations
Browser Support
Troubleshooting
Hekmat Online Store is a complete e-commerce solution developed for a Persian-speaking market. It allows users to browse products by categories and subcategories, add items to cart, place orders with address selection on an interactive map, leave comments on products, and manage their profile. The platform features a responsive design, smooth animations, and a professional user interface.
Category
Features
User Management
π Register, Login, Logout, Profile editing, Password change
Product Catalog
π¦ Products with categories/subcategories, Images gallery, Stock management
Shopping Cart
π Add/remove items, Calculate total price, Checkout process
Order System
π¦ Place orders, View order history, Order status tracking (Pending/Completed/Rejected)
Comments
π¬ Add comments on products, Admin approval system, Phone number masking
Address Selection
πΊοΈ Interactive map (Neshan) for location picking, Save address details
Search
π Product search with real-time results
Bestsellers
β Dynamic display of most sold products
News/New Products
π Latest products showcase
Carousel Sliders
πΌοΈ Category carousels, Product sliders
Security
π‘οΈ CSRF protection, Password hashing (Argon2id), SQL injection prevention, Session management
Responsive Design
π± Mobile-friendly layout, Persian (RTL) support
Animations
β¨ Smooth transitions, Preloader, Swiper.js carousels
Technology
Purpose
PHP 8.0+
Core programming language
Custom MVC Framework
Application architecture
MySQL
Database management
PDO
Database abstraction with prepared statements
Argon2id
Password hashing
Technology
Purpose
HTML5/CSS3
Structure & styling
JavaScript (Vanilla)
Interactive elements
Swiper.js
Touch-enabled carousels
Material Design Icons
Icon system
Vazirmatn Font
Persian typography
Neshan Maps API
Interactive location picker
Service
Purpose
Neshan Maps API
Reverse geocoding & map display
SweetAlert2
Beautiful alert dialogs
project-root/
βββ app/
β βββ auto/ # Auto-loaders
β β βββ PHP_ENV.php # .env file loader
β β βββ PHP_ERROR.php # Error handler
β βββ bootstrap/ # Bootstrap files
β β βββ bootstrap.php # Session start, headers, autoload
β βββ configs/ # Configuration classes
β β βββ Config.php # App configuration
β β βββ DB.php # Database credentials
β βββ controllers/ # Application controllers
β β βββ HomeController.php # Home page
β β βββ LoginController.php # Login logic
β β βββ RegisterController.php# Registration logic
β β βββ ProductsController.php# Product listing
β β βββ ProductsSingleController.php # Single product
β β βββ SearchController.php # Search functionality
β β βββ ProfileController.php # User profile
β β βββ ProfileCartController.php # Cart management
β β βββ ProfileAddressController.php # Address submission
β β βββ ProfileOrdersController.php # Order history
β β βββ ProfileEditProfileController.php # Profile editing
β β βββ ProfileEditPasswordController.php # Password change
β βββ core/ # Core framework
β β βββ Core.php # Router dispatcher
β βββ database/ # Database connection
β β βββ Database.php # PDO connection class
β βββ errors/ # Error handlers
β β βββ Errors.php # HTTP error responses
β βββ helpers/ # Helper functions
β β βββ helpers.php # Global helpers
β βββ libraries/ # Base classes
β β βββ Controller.php # Base controller
β βββ models/ # Database models
β β βββ Categories.php # Category operations
β β βββ Subcategories.php # Subcategory operations
β β βββ Products.php # Product operations
β β βββ Cart.php # Cart operations
β β βββ Orders.php # Order operations
β β βββ Comments.php # Comment operations
β β βββ Users.php # User operations
β β βββ Login.php # Login validation
β β βββ Register.php # Registration operations
β β βββ Search.php # Search operations
β βββ resources/views/ # View templates
β β βββ home/ # Home page views
β β βββ login/ # Login views
β β βββ register/ # Registration views
β β βββ products/ # Product views
β β βββ profile/ # Profile views
β β βββ search/ # Search views
β β βββ partials/ # Reusable components
β β β βββ inc.start.php # HTML opener
β β β βββ inc.end.php # HTML closer
β β β βββ menu.php # Main navigation
β β β βββ navbar.php # Top bar
β β β βββ footer.php # Main footer
β β β βββ footer_2.php # Simple footer
β β βββ errors/ # Error pages
β β βββ _403_.php
β β βββ _404_.php
β β βββ _500_.php
β βββ routes/ # Routing definitions
β βββ Route.php # Route class
β βββ Web.php # Route declarations
βββ public/ # Public assets
β βββ assets/ # CSS, JS, images
β β βββ css/
β β βββ js/
β β βββ images/
β β βββ packages/ # Vendor assets
β β βββ main-*.js # Compiled bundle
β βββ index.php # Front controller
βββ vendor/ # Composer dependencies
βββ .env # Environment variables
βββ composer.json # Composer configuration
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Browser β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Front Controller β
β (public/index.php) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Core.php β
β (Router Dispatcher) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Controllers β β Models β β Views β
β (Business Logic)β β (Data Access) β β (Presentation)β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Database β
β (MySQL) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
User request β public/index.php
Bootstrap loads: session, error handling, helpers, autoloader
Core.php parses URL and determines controller/method
Controller processes request, calls models
Models interact with database via PDO
Controller passes data to View
View renders HTML response
Component
Description
Registration
Phone, username, password with validation (phone format: 09XXXXXXXXX, password: 6-30 chars)
Login
Username/password verification with Argon2id hash check
Session Management
User data stored in $_SESSION["public"]
Logout
Destroys session and redirects to home
Profile Editing
Update phone number or complete address (based on address status)
Password Change
Verify old password, hash new password (Argon2id)
Component
Description
Categories
Product categories with parity-based display (odd/even)
Subcategories
Nested under categories with hierarchical menu
Product Listing
Paginated display (5 per page) with images
Single Product
Detailed view with image gallery, specifications, stock status
Stock Management
Shows "Out of stock", "Limited stock" (β€10), or normal stock
Bestsellers
Products sorted by order count (JOIN with orders table)
New Products
Latest 12 products displayed on homepage
Component
Description
Add to Cart
AJAX-less form submission, stores product title, price, image, user_id
View Cart
List all cart items with total price calculation
Remove Item
Delete individual items from cart
Checkout
Proceeds to address selection page
Cart Clear
After successful order, cart is emptied
Component
Description
Order Creation
When user submits address, all cart items become orders
Unique Order ID
Generated using uniqid() . "__" . time()
Order Status
1 = Completed, 2 = Pending, 3 = Rejected
Order History
Users can view all their orders with status
Total Spend
Sum of completed orders displayed
Comments System
Component
Description
Add Comment
Authenticated users can leave comments
Phone Masking
Phone numbers are partially hidden (e.g., *******1234)
Admin Approval
Comments have status field (0 = pending, 1 = approved)
Comment Count
Shows number of approved comments per product
Address Selection (Map Integration)
Component
Description
Interactive Map
Neshan map integration for location picking
Reverse Geocoding
Click on map β fetch formatted address
Address Details
Collects pelak (plaque), zang (intercom), name, phone, national code, postal code
Validation
Phone, national code, postal code format validation
Duplicate Check
Prevents duplicate phone/national code/postal code
Component
Description
Search Input
Real-time search by product title
Search Results
Displays matching products with images
No Results
Shows friendly "No results found" message
Column
Type
Description
id
INT (PK)
Auto-increment
username
VARCHAR(30)
Unique login username
password
VARCHAR(255)
Argon2id hash
phone
VARCHAR(11)
Unique, format: 09XXXXXXXXX
name
VARCHAR(50)
Full name (optional)
national_code
VARCHAR(10)
National ID (optional)
post_code
VARCHAR(10)
Postal code (optional)
address
TEXT
Formatted address
address_desc
TEXT
Address details
width
VARCHAR(20)
Latitude coordinate
height
VARCHAR(20)
Longitude coordinate
zoom
INT
Map zoom level
zang
VARCHAR(10)
Intercom number
pelak
VARCHAR(10)
Plaque number
address_status
TINYINT
0 = no address, 1 = has address
ip
VARCHAR(45)
Registration IP address
Column
Type
Description
id
INT (PK)
Auto-increment
title
VARCHAR(100)
Category name
image
VARCHAR(255)
Carousel image path
Column
Type
Description
id
INT (PK)
Auto-increment
cat_id
INT (FK)
Reference to categories.id
title
VARCHAR(100)
Subcategory name
Column
Type
Description
id
INT (PK)
Auto-increment
cat_id
INT (FK)
Reference to categories.id
subcat_id
INT (FK)
Reference to subcategories.id
title
VARCHAR(200)
Product name
price
DECIMAL(15,2)
Product price
total
INT
Stock quantity
description
TEXT
Product description
Column
Type
Description
id
INT (PK)
Auto-increment
product_id
INT (FK)
Reference to products.id
image
VARCHAR(255)
Image filename
Column
Type
Description
id
INT (PK)
Auto-increment
product_id
INT (FK)
Reference to products.id
search
TEXT
Searchable product title
Column
Type
Description
id
INT (PK)
Auto-increment
title
VARCHAR(200)
Product title (denormalized)
price
DECIMAL(15,2)
Product price (denormalized)
user_id
INT (FK)
Reference to users.id
product_id
INT
Product ID reference
image
VARCHAR(255)
Product image path
Column
Type
Description
id
INT (PK)
Auto-increment
title
VARCHAR(200)
Product title (denormalized)
price
DECIMAL(15,2)
Product price (denormalized)
user_id
INT (FK)
Reference to users.id
product_id
INT
Product ID reference
unique_id
VARCHAR(100)
Unique order identifier
status
TINYINT
1=Completed, 2=Pending, 3=Rejected
products_comments
Column
Type
Description
id
INT (PK)
Auto-increment
product_id
INT (FK)
Reference to products.id
comment
TEXT
Comment content
name
VARCHAR(50)
Commenter name (phone masked)
status
TINYINT
0=Pending, 1=Approved
Feature
Implementation
SQL Injection
Prepared statements (PDO) with bound parameters
XSS Prevention
safeEcho() uses htmlspecialchars()
CSRF Protection
Token generation and validation on all forms
Password Security
Argon2id hashing (MakeSecureHash/CheckSecureHashed)
Session Security
Session start with custom headers
Input Validation
Server-side validation for all inputs
Phone Validation
Regex check (starts with 09, length 11)
National Code Validation
Length 10, starts with 0
Postal Code Validation
Length 10
Output Encoding
All dynamic output escaped
Security Headers
X-Frame-Options, X-XSS-Protection, etc.
// In view
<input type="hidden" name="csrf_token" value="<?= generateToken () ?> ">
// In controller
validateToken(); // Throws error if invalid
Feature
Description
Preloader
Shows loading animation while assets load
Swiper Sliders
Touch-enabled carousels for categories, bestsellers, news
Responsive Menu
Hamburger menu for mobile devices
Interactive Map
Neshan map for address selection
Form Validation
Real-time browser validation + server validation
Success/Error Messages
SweetAlert2 for results, styled lists for form errors
Responsive Layout
Mobile-first design with breakpoints
Persian Typography
Vazirmatn font with proper RTL support
Smooth Animations
CSS transitions and keyframe animations
PHP >= 8.0
MySQL >= 5.7
Composer
Apache/Nginx with mod_rewrite
Step-by-Step Installation
# 1. Clone or download the project
cd /var/www/html/
git clone [repository-url] hekmat-store
cd hekmat-store
# 2. Install Composer dependencies
composer install
# 3. Create .env file
cp .env.example .env
# 4. Edit .env with your database credentials
# DB_HOST, DB_NAME, DB_USER, DB_PASS
# 5. Import database schema
mysql -u root -p database_name < database.sql
# 6. Set document root to /public folder
# Configure Apache VirtualHost or Nginx server block
# 7. Set proper permissions
chmod -R 755 storage/
chmod -R 755 public/assets/
# 8. Access the application
# http://localhost/hekmat-store
Apache Configuration (.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php?url=$1 [QSA,L]
π Environment Configuration
Create .env file in project root:
# Application
WEB =off # "off" for development, "on" for production
PROJECTNAME =hekmat-store
URL =http://localhost/hekmat-store
# Database
DB_HOST =localhost
DB_NAME =hekmat_db
DB_USER =root
DB_PASS =your_password
Routes are defined in app/routes/Web.php:
Route::Get ("/ " , "HomeController " , "index " );
Route::Get ("/login " , "LoginController " , "index " );
Route::Post ("/login " , "LoginController " , "login " );
Route::Get ("/register " , "RegisterController " , "index " );
Route::Post ("/register " , "RegisterController " , "register " );
Route::Post ("/logout " , "LoginController " , "logout " );
Route::Get ("/products " , "ProductsController " , "categories " );
Route::Get ("/sub/products " , "ProductsController " , "subcategories " );
Route::Get ("/product/:number " , "ProductsSingleController " , "index " );
Route::Post ("/comments " , "ProductsSingleController " , "comment " );
Route::Get ("/search " , "SearchController " , "index " );
Route::Get ("/profile " , "ProfileController " , "index " );
Route::Get ("/profile/cart " , "ProfileCartController " , "index " );
Route::Post ("/profile/cart " , "ProfileCartController " , "cart " );
Route::Post ("/profile/cart/delete/:number " , "ProfileCartController " , "delete " );
Route::Get ("/profile/address " , "ProfileAddressController " , "index " );
Route::Post ("/profile/address " , "ProfileAddressController " , "address " );
Route::Get ("/profile/orders " , "ProfileOrdersController " , "index " );
Route::Get ("/profile/edit " , "ProfileEditProfileController " , "index " );
Route::Post ("/profile/edit " , "ProfileEditProfileController " , "change " );
Route::Get ("/profile/edit/password " , "ProfileEditPasswordController " , "index " );
Route::Post ("/profile/edit/password " , "ProfileEditPasswordController " , "change " );
π Controllers Reference
Controller
Methods
Description
HomeController
index()
Homepage with categories, bestsellers, news
LoginController
index(), login(), logout()
User authentication
RegisterController
index(), register()
User registration
ProductsController
categories(), subcategories()
Product listing by category/subcategory
ProductsSingleController
index(), comment()
Single product view, comment submission
SearchController
index()
Product search
ProfileController
index()
User profile display
ProfileCartController
index(), cart(), delete()
Cart management
ProfileAddressController
index(), address()
Address submission & order finalization
ProfileOrdersController
index()
Order history
ProfileEditProfileController
index(), change()
Profile editing
ProfileEditPasswordController
index(), change()
Password change
Model
Methods
Description
Categories
getAll(), getOne(), getByParity(), countProducts()
Category operations
Subcategories
getAll(), getOne(), countProducts()
Subcategory operations
Products
getAll(), getOne(), getProductsByCategory(), getProductsBySubcategory(), getProductBySubcategory(), getProductImages(), getProductByHighOrder()
Product operations
Cart
addCart(), getCartByUser(), SumPriceCart(), getOne(), deleteCart()
Cart operations
Orders
getOrdersByUser(), add(), SumPriceOrders()
Order operations
Comments
CommentsOfProducts(), CommentCount(), addComment()
Comment operations
Users
getOne(), getExistsPhone(), getExistsPhoneAndPostCodeAndNationalCode(), editPhone(), updatePassword(), editInformation(), createCartAddress()
User operations
Login
CheckUsername()
Login validation
Register
register(), getExistUsernameAndPhone()
Registration operations
Search
SearchProducts(), SearchProductsImages()
Search operations
Located in app/helpers/helpers.php:
Function
Description
MakeSecureHash($password)
Argon2id password hashing
CheckSecureHashed($hash, $plain)
Password verification
periodPath($path)
Convert dot notation to path
redirect($path)
Redirect to URL
dd($content)
Dump and die (debugging)
require_view($path)
Include view file
safeEcho($value)
XSS-safe output
urlPath($path)
Generate full URL
publicPath($path)
Generate public asset path
getDbConnection()
Return PDO instance
generateToken()
Generate CSRF token
validateToken()
Validate CSRF token
excel($tableName)
Export table to Excel
word($tableName)
Export table to Word
csv($tableName)
Export table to CSV
tableExport($tableName)
Export table as SQL
resources/views/
βββ partials/
β βββ inc.start.php # DOCTYPE, head, preloader
β βββ inc.end.php # Closing tags
β βββ menu.php # Side menu
β βββ navbar.php # Top navigation bar
β βββ footer.php # Main footer (4 columns)
β βββ footer_2.php # Simple footer
βββ home/
β βββ index.php # Homepage
βββ login/
β βββ index.php # Login form
β βββ welcome.php # Post-login redirect
βββ register/
β βββ index.php # Registration form
βββ products/
β βββ categories.php # Products by category
β βββ subcategories.php # Products by subcategory
β βββ single.php # Single product page
βββ profile/
β βββ index.php # Profile display
β βββ cart.php # Shopping cart
β βββ address.php # Address form
β βββ orders.php # Order history
β βββ edit-profile.php # Edit profile form
β βββ edit-password.php # Change password form
β βββ inc.menu.php # Profile sub-menu
βββ search/
β βββ index.php # Search results
βββ errors/
βββ _403_.php
βββ _404_.php
βββ _500_.php
Endpoint
Purpose
https://api.neshan.org/v5/reverse
Reverse geocoding (lat/lng β address)
Leaflet map tiles
Interactive map display
Configuration:
const CONFIG = {
mapApiKey : "web.a681e265827c4815adc2bb291fd4b2ae" ,
serviceApiKey : "service.d490722192844f6c8aac5f0d3dc6481b" ,
defaultCenter : [ 35.6997 , 51.338 ] , // Tehran
defaultZoom : 13 ,
} ;
Browser
Version
Support
Chrome
60+
β
Full
Firefox
55+
β
Full
Safari
12+
β
Full
Edge
79+
β
Full
Opera
47+
β
Full
iOS Safari
12+
β
Full
Android Chrome
80+
β
Full
Issue
Solution
White screen
Check PHP error log, ensure .env exists
Database connection error
Verify credentials in .env, check MySQL is running
404 errors
Ensure .htaccess is enabled, mod_rewrite active
CSRF token invalid
Clear browser cookies and session, refresh page
Map not loading
Check API keys, ensure internet connection
Images not showing
Verify paths in /public/assets/images/
Login redirect loop
Check session configuration, cookie settings
MIT β Free for personal and commercial projects.
Danial Jamshidi
Swiper.js for carousel functionality
Neshan for mapping services
SweetAlert2 for beautiful alerts
Material Design Icons
Vazirmatn font
A complete e-commerce solution built with PHP MVC β Secure, Scalable, and Feature-Rich π