Sylius Plugin to display items sold on every Product/ProductVariant details admin page.

This package is auto-updated.

Last update: 2023-05-26 11:23:37 UTC


Latest Version on Packagist Software License Build Status Quality Score

Sylius Plugin to display items sold on every Product/ProductVariant details admin page

alt text


Add plugin to composer.json

composer require setono/sylius-items-sold-plugin

Register plugin at AppKernel.php

# app/AppKernel.php

final class AppKernel extends Kernel
    public function registerBundles(): array
        return array_merge(parent::registerBundles(), [
            // ...
            new \Setono\SyliusItemsSoldPlugin\SetonoSyliusItemsSoldPlugin(),

Add routing

# app/config/routing.yml
    resource: "@SetonoSyliusItemsSoldPlugin/Resources/config/admin_routing.yml"
    prefix: /admin

Configure plugin (optional)

You can omit this step as far as plugin works even without configuration. In that case result will count carts/orders in any (checkout/payment/shipment) states without any interval limitation and will not be cached.

But lets suppose we need to:

  • See how much times every item was sold last 14 days
  • Cache that values for 30 mins (1800 seconds) to decrease server load a bit
  • We don't want to count orders in states other than in payed and shipped
# app/config/config.yml
        class: Symfony\Component\Cache\Simple\FilesystemCache
            - ''
            - 0
            - "%kernel.cache_dir%/items-sold"

        service: 'app.setono_sylius_items_sold.cache'
        ttl: 1800
    interval: 14
        - paid
        - shipped


  • Don't forget to clean cache after changing interval parameter.
  • Don't specify interval if you wish to count even items added to carts (as far as cart doesn't have order date at checkoutCompletedAt field)
  • Discover Setono\SyliusItemsSoldPlugin\DependencyInjection\Configuration for more info about config options

(Manually) Test plugin

  • Run application: (by default application have default config at dev environment and example config from Configure plugin step at prod environment)

    cd tests/Application && \
        yarn install && \
        yarn run gulp && \
        bin/console assets:install web -e $SYMFONY_ENV && \
        bin/console doctrine:database:create -e $SYMFONY_ENV && \
        bin/console doctrine:schema:create -e $SYMFONY_ENV && \
        bin/console sylius:fixtures:load -e $SYMFONY_ENV && \
        bin/console server:run -d web -e $SYMFONY_ENV
  • Log in at http://localhost:8000/admin with Sylius demo credentials:

    Password: sylius 
  • Go to any product edit page like http://localhost:8000/admin/products/1

  • Or to product variant page like http://localhost:8000/admin/products/1/variants/1/edit

  • See how much that item was ordered (or even added to cart depending on config)