Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Issue with Overriding LineItem in Sylius Refund Plugin #470

Open
yass-chullanka opened this issue Feb 27, 2025 · 0 comments
Open

[Bug] Issue with Overriding LineItem in Sylius Refund Plugin #470

yass-chullanka opened this issue Feb 27, 2025 · 0 comments
Labels
Bug Confirmed bugs or bugfixes.

Comments

@yass-chullanka
Copy link

SyliusRefundPlugin version affected: 1.6

Description

I want to extend the LineItem entity in Sylius Refund Plugin to add a code field. But it's not detected by doctrine

Steps to reproduce
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:

  1. 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.
  2. 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.

  1. However, I still get this error when running:
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.

  1. Am I approaching this the wrong way?
  2. Has anyone successfully overridden LineItem in this plugin?

Thanks for your help!

@yass-chullanka yass-chullanka added the Bug Confirmed bugs or bugfixes. label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bugs or bugfixes.
Projects
None yet
Development

No branches or pull requests

1 participant