0

easyadmin3 について質問があります。私の管理パネルには productCrudController があり、新しい製品を作成するときに設定できる値の 1 つは価格です。価格については、日付付きのすべての価格を含む別のテーブルがあります。製品バンの価格は時間の経過とともに変化し、クライアントは各製品の価格履歴の概要を把握できるようにしたいと考えています。

したがって、私の productCrudController では、associationField を使用して価格エンティティにリンクしています。しかし、私は次の実際的な問題に本当に行き詰まっています: priceCrudController に価格を追加する必要はありません。

私が欲しいのは、製品を作成して価格を入力し、価格表に挿入できるようにすることです。

私のコード:

productCrudController ->

現在、ドロップダウン メニューで価格を選択できる価格のフィールドがありますが、最初に priceCrudController で価格を追加する必要がありますが、これは実際には実用的ではありません。

class ProductsCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Products::class;
    }


    public function configureFields(string $pageName): iterable
    {
        $image = ImageField::new('image')->setBasePath('resources/images');
        $imageFile = TextField::new('imageFile')->setFormType(VichImageType::class);
        $fields = [
            IdField::new('id', 'ID')->hideOnForm(),
            TextField::new('name'),
            TextEditorField::new('description'),
            AssociationField::new('category'),
            AssociationField::new('plants')->setTemplatePath('list.html.twig'),
            NumberField::new('stock'),
            AssociationField::new('prices', 'bruto price')->onlyOnIndex()->setTemplatePath('price.html.twig'),

        ];

        if($pageName == Crud::PAGE_INDEX || $pageName == Crud::PAGE_DETAIL){
            $fields[] = $image;
        } else {
            $fields[] = $imageFile;
        }

        return $fields;
    }

「価格」の数値フィールドを作成して、データベースに永続化される値を入力できるかどうかを確認しようとしましたが、次のエラーが発生します。

クラス Doctrine\ORM\PersistentCollection のオブジェクトを文字列に変換できませんでした

これは、「製品」エンティティとメソッドの「価格」プロパティです。

   /**
     * @ORM\OneToMany(targetEntity=Prices::class, mappedBy="product")
     * @Groups({"products:read"})
     */
    private $prices;

   /**
     * @return Collection|Prices[]
     */
    public function getPrices(): Collection
    {
        return $this->prices;
    }

    public function addPrice(Prices $price): self
    {
        if (!$this->prices->contains($price)) {
            $this->prices[] = $price;
            $price->setProduct($this);
        }

        return $this;
    }

    public function removePrice(Prices $price): self
    {
        if ($this->prices->removeElement($price)) {
            // set the owning side to null (unless already changed)
            if ($price->getProduct() === $this) {
                $price->setProduct(null);
            }
        }

        return $this;
    }

イベントリスナーで何かをする必要があるかもしれないと感じていますが、これまで実際に作業したことがないため、どうすればよいかわかりません。

どんな助けにもとても感謝しています

4

1 に答える 1