# ProductEntity erweitern mit zusätzlichen Feldern

**URL:** https://forum.shopware.com/t/productentity-erweitern-mit-zusatzlichen-feldern/69014
**Category:** Programmierung
**Created:** [18. August 2020 um 17:44 UTC](https://forum.shopware.com/t/productentity-erweitern-mit-zusatzlichen-feldern/69014 "2020-08-18T17:44:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rammi22](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rammi22](https://forum.shopware.com/u/rammi22)
#### Post date: [18. August 2020 um 17:44 UTC](https://forum.shopware.com/t/productentity-erweitern-mit-zusatzlichen-feldern/69014/1 "2020-08-18T17:44:04Z")

</div>

Hallo,

irgendwie bin ich nicht allein mit meinem [Verständissproblem bezüglich der Erweiterung einer Core-Entity](https://www.google.com/search?q=shopware+6+entity+extension+site:forum.shopware.com&client=firefox-b-d&ei=mQo8X_OeBajnsAemiKjYCw&start=0&sa=N&ved=2ahUKEwizz9nFnqXrAhWoM-wKHSYECrs4ChDy0wN6BAgLEC8&biw=1618&bih=948). Und ich finde keine Lösung. Als Tutorial nutze ich das [How To BundleExample](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/indepth-guide-bundle/entity-association?category=shopware-platform-dev-en/how-to/indepth-guide-bundle)

Also, ich habe eine **Entität MyProduct** , welches das eine **Erweiterung der Product-Entität** ist und zusätzliche Felder/Eigenschaften hat.

Die Migration-Datei für MyProduct:

```
...
class Migration1596974074MyProduct extends MigrationStep
{
    use InheritanceUpdaterTrait;
    ...
    public function update(Connection $connection): void
    {
        $connection->executeUpdate('
            CREATE TABLE IF NOT EXISTS `my_product` (
                `id_campaign` BINARY(16) NOT NULL,
                `product_id` BINARY(16) NOT NULL,
                `product_version_id` BINARY(16) NOT NULL,
                `name` VARCHAR(255) NULL COMMENT "specific product name for this campaign",
                `created_at` DATETIME(3) NOT NULL,
                PRIMARY KEY (`id_campaign`, `product_id`, `product_version_id`),
                CONSTRAINT `fk.my_product.id_campaign` FOREIGN KEY (`id_campaign`)
                REFERENCES `my_campaign` (`id`),
                CONSTRAINT `fk.my_product.product_id` FOREIGN KEY (`product_id`)
                REFERENCES `product` (`id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
        ');

        $this->updateInheritance($connection, 'product', 'my_campaigns');
    }
    ...
}

```

Dazu gibt es die MyProductDefinition.php

```
class LiveshoppingProductDefinition extends MappingEntityDefinition
{

    public function getEntityName(): string
    {
        return 'my_product';
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            // gekürzt: FK-Fields für id_campaign, product_id, product_version_id
            ...  
            (new StringField('name', 'name')),
           // gekürzt: ManyToMnayAssociationFields
           ...
        ]);
    }
}

```

Und die ProductExtension.php

```
...
public function getDefinitionClass(): string
    {
        return ProductDefinition::class;
    }

    public function extendFields(FieldCollection $collection): void
    {
        $collection->add(
            (new ManyToManyAssociationField(
                ...
            ))->addFlags(new Inherited())
        );
    }

```

&nbsp;

In meinem Modul gibt es ein Formular, wo die Eigenschaften bearbeitet werden sollen. Den orginalen Produktname _product.name_ kann ich ausgeben, wie aber komme ich beispielsweise an _my\_product.name_? Also wie komme ich an die **MyProduct-Entität**? Muß da eine weitere Entität erstellt werden?

Das Beispiel BundleExample speichert ja nur Daten, welche schon vorhanden sind. Was ist mit den neuen, zusätzlichen und zu administrierenden Feldern?
