This document describes the newly implemented features from Shopify and Magento 2 (Adobe Commerce) that have been added to the Laravel ecommerce platform.
- Customer Segmentation
- AI-Powered Product Recommendations
- Product Taxonomy
- Abandoned Cart Recovery
- Gift Registry
- Customer Analytics & Metrics
- A/B Testing Framework
- Product Performance Analytics
Advanced customer segmentation allows targeting specific groups based on behavior, purchase history, and other criteria.
customer_segments- Segment definitions with conditionscustomer_segment_members- Segment membership tracking
CustomerSegment- Segment management with auto-calculation
- Condition-based segmentation - Create rules based on:
- Total orders count
- Lifetime value
- Last order date
- Purchased specific products
- Customer group membership
- Match types - Match ALL or ANY conditions
- Auto-calculation - Segments update automatically
- Cached counts - Fast segment size retrieval
use App\Models\CustomerSegment;
// Create a VIP segment
$vipSegment = CustomerSegment::create([
'name' => 'VIP Customers',
'description' => 'High-value customers with $1000+ lifetime value',
'conditions' => [
[
'field' => 'lifetime_value',
'operator' => '>=',
'value' => 1000
]
],
'match_type' => 'all',
'is_active' => true,
]);
// Calculate members
$vipSegment->calculateMembers();
// Get segment members
$members = $vipSegment->members;# Calculate all active segments
php artisan segments:calculate
# Calculate specific segments
php artisan segments:calculate --segment=1 --segment=2use App\Services\CustomerSegmentationService;
$service = app(CustomerSegmentationService::class);
// Check if user is in segment
$isVip = $service->isUserInSegment($userId, $segmentId);
// Get all segments for user
$segments = $service->getUserSegments($userId);
// Get segment statistics
$stats = $service->getSegmentStats($segmentId);
// Returns: ['total_members' => 150, 'average_ltv' => 1250.00, ...]Intelligent product recommendations using collaborative filtering and behavioral analysis.
recommendation_rules- Recommendation engine rulesproduct_recommendations- Product-to-product recommendationsproduct_interactions- User interaction tracking
RecommendationRule- Rule definitionsProductRecommendation- Recommendation relationshipsProductInteraction- Interaction tracking
- Collaborative filtering - "Customers also bought"
- Personalized recommendations - Based on user history
- Trending products - Popular items tracking
- Similar products - Category and price-based
- Interaction tracking - Views, cart adds, purchases
use App\Services\ProductRecommendationService;
$service = app(ProductRecommendationService::class);
// Get personalized recommendations
$recommendations = $service->getPersonalizedRecommendations(
userId: $userId,
sessionId: session()->getId(),
limit: 10
);
// Get "also bought" recommendations
$alsoBought = $service->getAlsoBoughtRecommendations($productId, 6);
// Get similar products
$similar = $service->getSimilarProducts($product, 6);
// Track interactions
$service->trackView($userId, $productId, $duration);
$service->trackAddToCart($userId, $productId);
$service->trackPurchase($userId, $productId);# Generate recommendations using collaborative filtering
php artisan recommendations:generate- Personalized - Based on user's browsing/purchase history
- Collaborative - "Customers who bought X also bought Y"
- Similar - Products in same category with similar price
- Trending - Popular products in last 7 days
Hierarchical product categorization for better organization and discoverability.
taxonomy_categories- Hierarchical categoriesproduct_taxonomy- Product assignmentstaxonomy_attributes- Category-specific attributesproduct_taxonomy_values- Product attribute values
TaxonomyCategory- Category managementTaxonomyAttribute- Attribute definitionsProductTaxonomyValue- Product values
- Hierarchical structure - Nested categories with materialized paths
- Custom attributes - Define attributes per category
- Filterable attributes - Enable filtering by attributes
- Multiple categories - Products can belong to multiple taxonomies
- Breadcrumb support - Auto-generated category paths
use App\Models\TaxonomyCategory;
// Create root category
$electronics = TaxonomyCategory::create([
'name' => 'Electronics',
'slug' => 'electronics',
'is_active' => true,
]);
// Create subcategory
$phones = TaxonomyCategory::create([
'name' => 'Smartphones',
'slug' => 'smartphones',
'parent_id' => $electronics->id,
]);
// Add attributes
$phones->attributes()->create([
'name' => 'Screen Size',
'slug' => 'screen-size',
'type' => 'select',
'options' => ['5.5"', '6.1"', '6.7"'],
'is_filterable' => true,
]);
// Assign product to taxonomy
$product->taxonomyCategories()->attach($phones->id, [
'is_primary' => true
]);
// Set attribute values
ProductTaxonomyValue::create([
'product_id' => $product->id,
'taxonomy_attribute_id' => $attribute->id,
'value' => '6.1"',
]);
// Get breadcrumbs
$breadcrumbs = $phones->getBreadcrumbs();Automated campaigns to recover abandoned carts with email/SMS and discounts.
abandoned_carts- Enhanced with recovery fieldscart_recovery_campaigns- Campaign definitionscart_recovery_attempts- Tracking sends and conversions
CartRecoveryCampaign- Campaign managementCartRecoveryAttempt- Attempt tracking
- Multiple channels - Email, SMS, or both
- Delay triggers - Send after X minutes
- Discount incentives - Automatic discount codes
- Condition-based - Target specific cart values
- Conversion tracking - Track clicks and conversions
use App\Models\CartRecoveryCampaign;
// Create recovery campaign
$campaign = CartRecoveryCampaign::create([
'name' => 'First Hour Recovery',
'trigger_type' => 'email',
'delay_minutes' => 60,
'email_subject' => 'Complete your purchase and save 10%!',
'email_body' => 'You left items in your cart...',
'include_discount' => true,
'discount_type' => 'percentage',
'discount_value' => 10,
'conditions' => [
['field' => 'cart_value', 'operator' => '>=', 'value' => 50]
],
]);
// Check if campaign applies
if ($campaign->meetsConditions($abandonedCart)) {
// Send recovery email
}Complete gift registry system for weddings, baby showers, and other events.
gift_registries- Registry definitionsgift_registry_items- Products in registrygift_registry_purchases- Purchase tracking
GiftRegistry- Registry managementGiftRegistryItem- Item trackingGiftRegistryPurchase- Purchase records
- Multiple event types - Wedding, baby, birthday, etc.
- Privacy levels - Public, private, link-only
- Access codes - For private registries
- Completion tracking - Show progress
- Anonymous purchases - Option to hide purchaser
- Shipping address - Store delivery information
use App\Models\GiftRegistry;
// Create registry
$registry = GiftRegistry::create([
'user_id' => $userId,
'name' => 'John & Jane\'s Wedding',
'type' => 'wedding',
'event_date' => '2025-06-15',
'privacy' => 'public',
'is_active' => true,
]);
// Add items
$item = $registry->items()->create([
'product_id' => $productId,
'quantity_requested' => 2,
'priority' => 1, // Must have
]);
// Mark as purchased
$item->markPurchased(
quantity: 1,
orderId: $orderId,
purchaserName: 'Sarah Smith',
purchaserEmail: 'sarah@example.com',
anonymous: false
);
// Get completion percentage
$completion = $registry->getCompletionPercentage(); // 50.00Comprehensive customer lifetime value and behavior tracking.
customer_metrics- Customer LTV and statisticsconversion_funnels- Funnel definitionsconversion_events- Event tracking
CustomerMetric- Metric tracking
- Lifetime Value (LTV) - Total customer spend
- Average Order Value (AOV) - Average per order
- Purchase frequency - Total orders
- Recency tracking - Days since last purchase
- Customer segmentation - Auto-categorization (new, active, at_risk, churned, vip)
- Retention scoring - 0-100 score
- Predictions - Next order value and date
use App\Models\CustomerMetric;
// Get or create metrics
$metric = CustomerMetric::firstOrCreate(['user_id' => $userId]);
// Recalculate all metrics
$metric->recalculate();
// Access metrics
$ltv = $metric->lifetime_value; // 1250.50
$aov = $metric->average_order_value; // 125.05
$segment = $metric->customer_segment; // "vip"
$score = $metric->retention_score; // 85# Update all customer metrics
php artisan metrics:update-customers
# Update specific customers
php artisan metrics:update-customers --user=1 --user=2Built-in A/B testing for optimizing conversions.
ab_tests- Test definitionsab_test_assignments- User/session assignments
ABTest- Test managementABTestAssignment- Assignment tracking
- Multiple test types - Page, feature, price, content, checkout
- Traffic allocation - Control test exposure
- Variant management - Multiple variants per test
- Conversion tracking - Track goals and revenue
- Statistical analysis - Built-in conversion rates
use App\Services\ABTestingService;
$service = app(ABTestingService::class);
// Create test
$test = $service->createTest(
name: 'Checkout Button Color',
type: 'feature',
variants: [
['name' => 'control', 'weight' => 50],
['name' => 'red_button', 'weight' => 50],
],
description: 'Test red vs blue checkout button'
);
// Start test
$service->startTest($test->id);
// Get variant for user
$variant = $service->getVariant('Checkout Button Color', $userId);
// Check variant
if ($service->isVariant('Checkout Button Color', 'red_button')) {
// Show red button
}
// Track conversion
$service->trackConversion('Checkout Button Color', $orderTotal);
// Get results
$results = $service->getTestResults($test->id);
// Returns conversion rates and statistics per variant
// End test with winner
$service->endTest($test->id, 'red_button');Track product views, conversions, and performance.
product_performance- Daily product metrics
ProductPerformance- Performance tracking
- Daily metrics - Views, cart adds, purchases
- Revenue tracking - Per product revenue
- Conversion rates - View-to-purchase conversion
- Return rates - Product return tracking
- Automatic calculation - Auto-update rates
use App\Models\ProductPerformance;
// Record view
ProductPerformance::recordView($productId);
// Record add to cart
ProductPerformance::recordAddToCart($productId);
// Record purchase
ProductPerformance::recordPurchase($productId, $revenue);
// Get performance data
$performance = ProductPerformance::where('product_id', $productId)
->where('date', today())
->first();
$views = $performance->views;
$conversionRate = $performance->conversion_rate; // Auto-calculatedRun migrations to install all features:
php artisan migrateNo additional configuration required. All features work out of the box.
Add to app/Console/Kernel.php:
protected function schedule(Schedule $schedule)
{
// Update customer metrics daily
$schedule->command('metrics:update-customers')->daily();
// Calculate segments daily
$schedule->command('segments:calculate')->daily();
// Generate recommendations weekly
$schedule->command('recommendations:generate')->weekly();
}All models are REST API-ready and can be exposed via Laravel's resource controllers.
Filament admin resources can be created for managing:
- Customer segments
- Recommendation rules
- Gift registries
- A/B tests
- Cart recovery campaigns
For issues or questions, please open an issue in the GitHub repository.
MIT License - see LICENSE file for details.