Schema failure when extending Sylius entity from plugin

My plugin (Sylius 1.7) uses a trait to add an attribute to a Sylius entity. For example:

# sylius-example-plugin/src/Model/OrderItemTrait.php

namespace Acme\SyliusExamplePlugin\Model;

trait OrderItemTrait

    private $foo;

    public function getFoo()
        return $this->foo;

    public function setFoo($foo)
        $this->foo = $foo;


In a sylius-standard shop, I can add this trait to App\Entity\Order\OrderItem and everything works great:

# my-sylius-standard-shop/src/Entity/Order/OrderItem.php

namespace App\Entity\Order;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\OrderItem as BaseOrderItem;

class OrderItem extends BaseOrderItem
	use \Acme\SyliusExamplePlugin\Model\OrderItemTrait;

But I also need to add that trait to tests/Application so I can run tests. And that does NOT work great. Since tests/Application doesn’t have any App\Entity classes, I created one just like sylius-standard, and I copied the doctrine.orm.mappings config from sylius-standard.

Here is a demo

The result is that doctrine:mapping:info successfully reports the new class, but doctrine:schema:create fails:

The table with name 'acme_sylius_example_plugin_dev.sylius_order_item' already exists.

I can find plenty of discussions about similar issues but not that pertain to this specific case. I’m guessing there’s some other magic trick in sylius-standard to support these App entities that isn’t in PluginSkeleton/tests/Application, but I have no idea what. Any ideas appreciated!

Hi Rob, I figured it out for you:

Add a Sylius resource config for each App entity:

# tests/Application/config/packages/_sylius.yaml
                model: App\Entity\Order\OrderItem

and the autoload mapping for App classes in general:

# composer.json
    "autoload": {
        "psr-4": {
            "App\\": "tests/Application/src/"

and you may need to run composer dump-autoload after that.

  • Rob