I want to add a single auto-increment column into the core order_delivery
table in Shopware 6.
To implement that I built the following extension:
#[Autoconfigure(tags: ['shopware.entity.extension'])]
class OrderDeliveryReferenceExtension extends EntityExtension
{
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new IntField('reference_number', 'referenceNumber'))
->addFlags(new ApiAware(), new Runtime()),
);
}
public function getDefinitionClass(): string
{
return OrderDeliveryDefinition::class;
}
}
This column exists in the table and it is populated with the data but I cannot read them with $this->delivery->get('referenceNumber')
. I got the "Property 'referenceNumber' not found" error.
Did I miss something?
Did you extend the database table as well? Your EntityExtension
only extends the class which represents your database table.
You can follow this example from the shopware docs. It shows how to add a new field to an existing entity. Your example won't work because of:
Since you must not extend the product table with a new column, you'll have to add a new table which contains the new data for the product. This new table will then be associated using a OneToOne association