Skip to content

Linking vendors to shop users ​

If you want to link the vendor with the shop user within the vendor registration form, follow this steps.

  1. Make the ShopUser implement VendorAwareInterface and use Odiseo\SyliusMarketplacePlugin\Entity\VendorAwareTrait — not the vendor plugin's VendorTrait, which is Product-specific (it maps a required, bidirectional association back to Vendor::$products, via inversedBy: 'products')
php
<?php
// src/Entity/ShopUser.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\ShopUser as BaseShopUser;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_shop_user')]
class ShopUser extends BaseShopUser implements VendorAwareInterface
{
    use VendorAwareTrait;
}
  1. Add the access control for the vendor registration route
yml
# config/packages/security.yaml
security:
    access_control:
        # ...
        - { path: "%sylius.security.shop_regex%/vendors/register", role: ROLE_USER }
  1. Create the database migration and apply it to your database

The vendor_id column on sylius_shop_user 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