Overview
The Affiliate Program allows users to earn commissions by promoting your products. The system supports multiple commission types, payment processing, withdraw requests, and detailed analytics.The affiliate system is an addon feature that must be activated. Check
addon_is_activated('affiliate_system') before using affiliate features.Database Structure
AffiliateLog Model
Location:app/Models/AffiliateLog.php:1
Relationships:
user()- BelongsTo relationship with User (app/Models/AffiliateLog.php:9)order_detail()- BelongsTo relationship with OrderDetail (app/Models/AffiliateLog.php:14)order()- BelongsTo relationship with Order (app/Models/AffiliateLog.php:19)
user_id- Customer who made the purchaseguest_id- Guest customer identifierreferred_by_user- Affiliate user who referred the customeramount- Commission amount earnedorder_id- Related orderorder_detail_id- Specific order item (for product-based commissions)affiliate_type- Type of commission (user_registration_first_purchase, product_sharing, category_wise_affiliate)
Commission Types
User Registration First Purchase
Affiliate earns commission when their referred user makes their first purchase. Configuration:- Set percentage of order total (app/Http/Controllers/AffiliateController.php:349)
- Applied only to first order (app/Http/Controllers/AffiliateController.php:345)
- Processes when order is placed
Product Sharing
Affiliate earns commission when products they share are purchased. Configuration:- Fixed amount or percentage per product
- Tracked via product referral code (app/Http/Controllers/AffiliateController.php:371)
- Applied to each order item
Category-Wise Affiliate
Commission rates vary by product category. Configuration:- Set commission per category (app/Http/Controllers/AffiliateController.php:60-65)
- Amount or percentage based
- Applied when product’s category matches
Affiliate User Management
Registration Process
User Applies
Customers apply to become affiliates via the application form
Location:
app/Http/Controllers/AffiliateController.php:134-139Submit Verification Form
Applicants fill out a customizable verification form with:
- Text fields
- Select/Multi-select dropdowns
- Radio buttons
- File uploads
AffiliateConfig (app/Http/Controllers/AffiliateController.php:185-209)Admin Review
Administrators review applications and either:
- Approve the user (app/Http/Controllers/AffiliateController.php:230-240)
- Reject the application (app/Http/Controllers/AffiliateController.php:242-253)
Verification Form Configuration
Location:app/Http/Controllers/AffiliateController.php:94-132
Admins can customize the affiliate application form:
Payment Management
Direct Payments
Location:app/Http/Controllers/AffiliateController.php:271-284
Admins can pay affiliates directly:
Withdraw Requests
Affiliate Requests Withdrawal
Users submit withdrawal requests (app/Http/Controllers/AffiliateController.php:495-515)
Admin Reviews Request
Administrators view pending requests (app/Http/Controllers/AffiliateController.php:517-521)
Payment Settings
Location:app/Http/Controllers/AffiliateController.php:333-340
Affiliates configure their payment preferences:
Analytics and Stats
Location:app/Http/Controllers/AffiliateController.php:449-486
Tracked Metrics
- Clicks: Product link clicks
- Order Items: Number of items sold
- Delivered: Successfully delivered orders
- Cancelled: Cancelled orders
Processing Stats
User Dashboard
Location:app/Http/Controllers/AffiliateController.php:292-310
Affiliates can view their stats filtered by:
- Today
- Last 7 days
- Last 30 days
Configuration Options
Validation Time
Location:app/Http/Controllers/AffiliateController.php:99-109
Set how long it takes for commissions to be validated:
Commission Rate Configuration
Location:app/Http/Controllers/AffiliateController.php:43-92
Admins can configure commission rates for each type:
Permissions
Location:app/Http/Controllers/AffiliateController.php:24-36
affiliate_registration_form_config- Configure verification formaffiliate_configurations- Manage commission settingsview_affiliate_users- View affiliate users listpay_to_affiliate_user- Process paymentsaffiliate_users_payment_history- View payment recordsview_all_referral_users- See referral networkview_affiliate_withdraw_requests- View withdrawal requestsaccept_affiliate_withdraw_requests- Approve withdrawalsreject_affiliate_withdraw_request- Deny withdrawal requestsview_affiliate_logs- Access affiliate activity logs
Commission Processing
Location:app/Http/Controllers/AffiliateController.php:342-447
The processAffiliatePoints method automatically processes commissions when orders are placed:
Processing Flow
- Check addon status - Verify affiliate system is enabled
- Determine commission type - User registration, product sharing, or category-wise
- Calculate commission amount - Based on configuration
- Update affiliate balance - Add commission to user’s balance
- Create affiliate log - Record transaction for tracking
Referral Tracking
Location:app/Http/Controllers/AffiliateController.php:488-492
View all users referred by affiliates:
Best Practices
Commission Structure:
- Start with conservative rates (5-10%) and adjust based on performance
- Consider category-wise rates for different profit margins
- Set validation periods to prevent fraud (e.g., 30 days after delivery)