Skip to content

Vendor resolver

When an order is paid, the marketplace splits it into one vendor order per vendor. To know which vendor an order item belongs to, the split, the commission calculation and the payout all go through a single extension point: the vendor resolver.

By default the resolver reads the vendor from the item's product. You can replace it to resolve the vendor differently — for example, to resolve it from a selected offer in a shared catalogue.

The contract

php
namespace Odiseo\SyliusMarketplacePlugin\Vendor\Resolver;

use Odiseo\SyliusMarketplacePlugin\Entity\VendorInterface;
use Sylius\Component\Core\Model\OrderItemInterface;

interface VendorResolverInterface
{
    public function resolveForItem(OrderItemInterface $item): ?VendorInterface;
}

The default implementation is registered under the service id odiseo_marketplace.resolver.vendor.

Replacing the resolver

  1. Implement the interface
php
<?php
// src/Vendor/Resolver/MyVendorResolver.php

declare(strict_types=1);

namespace App\Vendor\Resolver;

use Odiseo\SyliusMarketplacePlugin\Entity\VendorInterface;
use Odiseo\SyliusMarketplacePlugin\Vendor\Resolver\VendorResolverInterface;
use Sylius\Component\Core\Model\OrderItemInterface;

final class MyVendorResolver implements VendorResolverInterface
{
    public function resolveForItem(OrderItemInterface $item): ?VendorInterface
    {
        // your resolution logic here
    }
}
  1. Redefine the service id
yaml
# config/services.yaml
services:
    odiseo_marketplace.resolver.vendor:
        class: App\Vendor\Resolver\MyVendorResolver

The split, commission and payout pick up the new resolver automatically — no other change is needed.

by Odiseo