a1boroujerdi/php-recommender

AI-powered product recommendation system for e-commerce platforms

v1.0.0 2025-06-28 07:24 UTC

This package is auto-updated.

Last update: 2025-06-28 07:32:33 UTC


README

A Laravel package for AI-powered product recommendations in e-commerce platforms.

Features

  • Track user behavior on e-commerce websites
  • Analyze user interactions (views, purchases, etc.)
  • Generate product recommendations based on AI analysis
  • Provide personalized recommendations to users
  • Connect to external AI services for advanced recommendations

Installation

You can install the package via composer:

composer require ecomai/recommender

Publishing the config file

php artisan vendor:publish --provider="EcomAI\Recommender\RecommenderServiceProvider" --tag="recommender-config"

Setting up the database

Run the migrations to create the necessary tables:

php artisan migrate

Configuration

Configure your AI service connection in your .env file:

ECOMAI_SERVICE_URL=https://api.youraiservice.com
ECOMAI_API_KEY=your-api-key
ECOMAI_TIMEOUT=5
ECOMAI_TRACK_GUESTS=true

Usage

Tracking user behavior

You can track user behavior through the facade:

use EcomAI\Recommender\Facades\Recommender;

// Track when a user views a product
Recommender::trackBehavior(
    $userId,
    $productId,
    'view',
    ['duration' => 30] // Optional metadata
);

// Track when a user adds a product to cart
Recommender::trackBehavior(
    $userId,
    $productId,
    'cart'
);

// Track when a user purchases a product
Recommender::trackBehavior(
    $userId,
    $productId,
    'purchase',
    ['quantity' => 2, 'price' => 99.99]
);

Getting recommendations

// Get recommendations for a specific product
$recommendations = Recommender::getProductRecommendations($productId, 5);

// Get personalized recommendations for a user
$recommendations = Recommender::getUserRecommendations($userId, 5);

In Blade templates

<div class="product-recommendations">
    <h3>You might also like</h3>
    <div class="products">
        @foreach(Recommender::getProductRecommendations($product->id) as $recommendedProduct)
            <div class="product-card">
                <h4>{{ $recommendedProduct->name }}</h4>
                <img src="{{ $recommendedProduct->image }}" alt="{{ $recommendedProduct->name }}">
                <p>{{ $recommendedProduct->price }}</p>
            </div>
        @endforeach
    </div>
</div>

API Endpoints

The package provides the following API endpoints:

  • POST /api/ecomai/track - Track user behavior
  • GET /api/ecomai/recommend/product/{productId} - Get product recommendations
  • GET /api/ecomai/recommend/user/{userId?} - Get user recommendations

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.