abderrahimghazali/sylius-social-proof-plugin

Social proof and FOMO widgets for Sylius 2.x — live viewers, recent purchases, sales counter, low stock alerts

Maintainers

Package info

github.com/abderrahimghazali/sylius-social-proof-plugin

Type:sylius-plugin

pkg:composer/abderrahimghazali/sylius-social-proof-plugin

Statistics

Installs: 21

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-04-10 20:10 UTC

This package is auto-updated.

Last update: 2026-04-10 20:46:02 UTC


README

Sylius Logo

Sylius Social Proof Plugin

Social proof and FOMO widgets for Sylius 2.x — live viewer counts, recent purchase notifications, sales counters, low stock alerts, and custom messages.

CI Latest Version PHP Version License Sylius 2.x Symfony 7.x PHPStan Level 5

Features

Live Viewers

Displays "X people are viewing this right now" on product pages. Uses a seeded pseudo-random count within a configurable range, refreshed via lightweight polling.

Recent Purchases

Shows "Jean from Paris just bought this" notifications with clickable product links. Queries real Sylius order data with buyer first name and city from billing address. Shows once per session to avoid spam.

Sales Counter

Displays "47 sold in the last 24h" on product pages with an animated count-up effect. Configurable lookback period and minimum threshold.

Low Stock Alert

Shows "Only 3 left in stock!" when product variant stock falls below a configurable threshold. Includes a subtle pulse animation for urgency.

Custom Message

Display any custom message with an emoji icon, optional link, and dismissible close button. Perfect for announcements, promotions, or seasonal campaigns. Limited to 120 characters.

Independent Positioning

Each widget has its own position setting — place them in any of the 4 screen corners independently:

  • Top left
  • Top right
  • Bottom left
  • Bottom right

Requirements

Dependency Version
PHP ^8.2
Sylius ^2.1
Symfony ^7.0

Installation

1. Install via Composer

composer require abderrahimghazali/sylius-social-proof-plugin

2. Register the bundle

// config/bundles.php
return [
    // ...
    Abderrahim\SyliusSocialProofPlugin\SyliusSocialProofPlugin::class => ['all' => true],
];

3. Import routes

# config/routes/sylius_social_proof.yaml
sylius_social_proof:
    resource: '@SyliusSocialProofPlugin/config/routes.yaml'

4. Run database migration

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

5. Seed default widget configurations

bin/console social-proof:install

This creates the default widgets (all disabled). Enable them from the admin panel.

6. Register Stimulus controllers

// assets/controllers.json
{
    "@abderrahimghazali/sylius-social-proof-plugin": {
        "live-viewers": { "enabled": true, "fetch": "eager" },
        "purchase-toast": { "enabled": true, "fetch": "eager" },
        "sales-counter": { "enabled": true, "fetch": "lazy" },
        "low-stock": { "enabled": true, "fetch": "lazy" }
    }
}

7. Rebuild assets

npm run build

Admin Usage

Navigate to Marketing > Social Proof in the Sylius admin panel.

Each widget can be independently:

  • Enabled/disabled via toggle
  • Configured with type-specific settings
  • Positioned in any screen corner

Widget Settings

Widget Settings
Live Viewers Min count, max count, refresh interval, position
Recent Purchases Max notifications, display interval, show city, lookback period, position
Sales Counter Lookback period (hours), minimum threshold, position
Low Stock Stock threshold, show exact count, position
Custom Message Message (120 chars max), icon (emoji), link URL, link text, dismissible, position

Architecture

SyliusSocialProofPlugin/
├── src/
│   ├── Command/InstallCommand.php          # Seeds default widgets
│   ├── Controller/
│   │   ├── Admin/SocialProofWidgetController.php
│   │   └── Shop/
│   │       ├── LiveViewerController.php    # Polling endpoint
│   │       └── RecentPurchaseController.php # Recent purchases API
│   ├── Entity/SocialProofWidget.php        # Single entity with JSON settings
│   ├── Enum/
│   │   ├── WidgetType.php                  # 5 widget types
│   │   └── DisplayPosition.php             # 4 corner positions
│   ├── Service/
│   │   ├── LiveViewerCounter.php           # Seeded pseudo-random count
│   │   ├── RecentPurchaseProvider.php      # Queries Sylius orders, cached 5min
│   │   ├── SalesCounterProvider.php        # SUM(quantity) query, cached 10min
│   │   └── LowStockChecker.php            # Reads variant onHand - onHold
│   └── Twig/
│       ├── SocialProofExtension.php        # Registers functions
│       └── SocialProofRuntime.php          # Lazy-loaded runtime
├── assets/controllers/                     # Stimulus controllers
├── templates/
│   ├── admin/                              # CRUD forms
│   └── shop/                               # Product page + footer widgets
└── translations/                           # EN + FR

API Endpoints

Endpoint Method Description
/api/v2/shop/social-proof/{productId}/live-viewers GET Returns {"count": 17}
/api/v2/shop/social-proof/recent-purchases GET Returns array of recent purchases
/api/v2/shop/social-proof/recent-purchases?productId=X GET Filtered by product

Testing

vendor/bin/phpunit
vendor/bin/phpstan analyse

License

MIT