Skip to content

Vendor promotions

The vendors can create their own promotions and configure the rules. This feature is disabled by default, however, it can be enabled.

  1. Add the enabled configuration parameter
yml
# config/packages/odiseo_sylius_marketplace.yaml
odiseo_sylius_marketplace:
    vendor_promotion_enabled: true
  1. Include traits and override the resources

Use Odiseo\SyliusMarketplacePlugin\Entity\VendorAwareTrait, not the vendor plugin's VendorTraitVendorTrait is Product-specific (a required, bidirectional association back to Vendor::$products via inversedBy: 'products'), which doesn't apply to Promotion.

php
<?php
// src/Entity/Promotion.php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Odiseo\SyliusMarketplacePlugin\Entity\VendorAwareTrait;
use Odiseo\SyliusVendorPlugin\Entity\VendorAwareInterface;
use Sylius\Component\Core\Model\Promotion as BasePromotion;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_promotion')]
class Promotion extends BasePromotion implements VendorAwareInterface
{
    use VendorAwareTrait;
}
php
<?php
// src/Repository/PromotionRepository.php

declare(strict_types=1);

namespace App\Repository;

use Odiseo\SyliusMarketplacePlugin\Repository\PromotionRepositoryInterface;
use Odiseo\SyliusMarketplacePlugin\Repository\PromotionRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\PromotionRepository as BasePromotionRepository;

class PromotionRepository extends BasePromotionRepository implements PromotionRepositoryInterface
{
    use PromotionRepositoryTrait;
}

The seller panel also scopes promotion coupons to the owning vendor, so the coupon repository needs the same treatment:

php
<?php
// src/Repository/PromotionCouponRepository.php

declare(strict_types=1);

namespace App\Repository;

use Odiseo\SyliusMarketplacePlugin\Repository\PromotionCouponRepositoryInterface;
use Odiseo\SyliusMarketplacePlugin\Repository\PromotionCouponRepositoryTrait;
use Sylius\Bundle\PromotionBundle\Doctrine\ORM\PromotionCouponRepository as BasePromotionCouponRepository;

class PromotionCouponRepository extends BasePromotionCouponRepository implements PromotionCouponRepositoryInterface
{
    use PromotionCouponRepositoryTrait;
}
yml
# config/packages/_sylius.yaml
sylius_promotion:
    resources:
        promotion:
            classes:
                repository: App\Repository\PromotionRepository
        promotion_coupon:
            classes:
                repository: App\Repository\PromotionCouponRepository
  1. Create the database migration and apply it to your database

The vendor_id column on sylius_promotion is not part of the plugin's shipped migrations — this feature is opt-in, so the column only exists once you enable it. Generate the migration yourself, review it, then apply it:

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

by Odiseo