Skip to content

Order processors

The plugin replaces two of Sylius' order processors to make orders marketplace-aware: one splits an order into a shipment per vendor, the other charges for those shipments. Both are ordinary services, so you can decorate either one to substitute your own logic. See Shipping in a marketplace for what they do by default.

Custom shipment processor

INFO

Only applies when shipping.method_owner is vendor (the default).

This plugin has an own shipment processor that overrides the default Sylius one. This processor creates one shipment for each vendor that appears in the provided order.

You should start with the implementation of your custom shipment processor service. Remember that OrderProcessorInterface must be implemented the from Order Component

php
<?php
// src/OrderProcessing/OrderShipmentProcessor.php

declare(strict_types=1);

namespace App\OrderProcessing;

use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;

final class OrderShipmentProcessor implements OrderProcessorInterface
{
    public function process(OrderInterface $order): void
    {
        // your own logic
    }
}

One more thing is needed to make it work. A proper service registration in the services.yaml file.

yml
# config/services.yaml
app.order_processing.order_shipment_processor:
    class: App\OrderProcessing\OrderShipmentProcessor
    decorates: odiseo_marketplace.order_processing.order_shipment_processor

Custom shipping charges processor

INFO

Only applies when shipping.method_owner is vendor (the default). In operator mode a different processor is registered, which charges the buyer once for the whole order.

This plugin has an own shipping charges processor that overrides the default Sylius one. This processor creates one charge for each vendor shipment that appear in the provided order.

You should start with the implementation of your custom shipping charges processor service. Remember, that it must implement the OrderProcessorInterface from Order Component.

php
<?php
// src/OrderProcessing/ShippingChargesProcessor.php

declare(strict_types=1);

namespace App\OrderProcessing;

use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;

final class ShippingChargesProcessor implements OrderProcessorInterface
{
    public function process(OrderInterface $order): void
    {
        // your own logic
    }
}

One more thing is needed to make it work. A proper service registration in the services.yaml file.

yml
# config/services.yaml
app.order_processing.shipping_charges_processor:
    class: App\OrderProcessing\ShippingChargesProcessor
    decorates: odiseo_marketplace.order_processing.shipping_charges_processor

That's it! Now your shipment process will be executed during the checkout.

by Odiseo