Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Let's start with the `CustomExtension` class by adding a new field in the `exten
namespace Swag\BasicExample\Extension\Content\Product;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

Expand All @@ -96,7 +97,7 @@ class CustomExtension extends EntityExtension
public function extendFields(FieldCollection $collection): void
{
$collection->add(
new OneToOneAssociationField('exampleExtension', 'id', 'product_id', ExampleExtensionDefinition::class, true)
(new OneToOneAssociationField('exampleExtension', 'id', 'product_id', ExampleExtensionDefinition::class, true))->addFlags(new CascadeDelete())
);
}

Expand All @@ -115,6 +116,9 @@ As you can see, we're adding a new `OneToOneAssociationField`. Its parameters ar
* `referenceClass`: The class name of the definition that we want to connect via the association.
* `autoload`: As the name suggests, this parameter defines if this association should always be loaded by default when the product is loaded. In this case, we definitely want that.

Associations marked with the `CascadeDelete` flag are considered in the clone process. Take a look at the [clone behaviour](../../../../../resources/references/adr/2020-07-02-control-clone-behavior.md)
If the associated entity should not be cloned when cloning a product having it, change it to `CascadeDelete(false)` or remove the flag.

#### Creating ExampleExtensionDefinition

You most likely noticed the new class `ExampleExtensionDefinition`, which we're going to create now. It will contain the actual string field that we wanted to add to the product.
Expand Down