Reputation: 1
Context:
I want to extend the LineItem
entity in Sylius Refund Plugin to add a code
field.
I created a custom entity:
namespace App\Entity\SyliusRefundPlugin;
use Doctrine\ORM\Mapping as ORM;
use Sylius\RefundPlugin\Entity\LineItem as BaseLineItem;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_refund_line_item")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_refund_line_item')]
class LineItem extends BaseLineItem implements LineItemInterface
{
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $code = null;
public function setCode(?string $code): void
{
$this->code = $code;
}
public function getCode(): ?string
{
return $this->code;
}
}
I also created this interface:
<?php
declare(strict_types=1);
namespace App\Entity\SyliusRefundPlugin;
use Sylius\RefundPlugin\Entity\LineItemInterface as BaseLineItemInterface;
interface LineItemInterface extends BaseLineItemInterface
{
public function getCode(): ?string;
public function setCode(?string $code): void;
}
Configuration:
I used resolve_target_entities
in doctrine.yaml
:
doctrine:
orm:
resolve_target_entities:
Sylius\RefundPlugin\Entity\LineItem: App\Entity\SyliusRefundPlugin\LineItem
I also added this in services.yaml
:
Sylius\RefundPlugin\Entity\LineItem:
class: 'App\Entity\SyliusRefundPlugin\LineItem'
Symptoms:
Doctrine recognizes the custom entity:
bin/console doctrine:mapping:info
shows App\Entity\SyliusRefundPlugin\LineItem
bin/console doctrine:schema:validate
shows correct mapping and schema sync.When running a migration with:
bin/console doctrine:migrations:diff
I get the error:
The table with name "chkv3.sylius_refund_line_item" already exists.
To bypass this, I manually wrote the migration to add the code
field.
Call to undefined method Sylius\RefundPlugin\Entity\LineItem::setCode()
This indicates that Sylius is still using the base LineItem
instance instead of my custom version.
Investigations:
bin/console cache:clear
bin/console doctrine:mapping:info
shows App\Entity\SyliusRefundPlugin\LineItem
bin/console doctrine:schema:validate
shows correct mapping and schema sync.var/cache/dev/doctrine/proxy/
LineItem
is defined as a MappedSuperclass
in Sylius Refund Plugin
resolve_target_entities
in doctrine.yaml
Thanks for your help!
Upvotes: 0
Views: 21