I’m trying to add an inheritable boolean field to the product entity with a switch field setting on the admin page, but I couln’t find a proper way to do this. I could use custom fields but they’re not inheritable, which is the main reason why I’m using this approach.
I tried following the tutorials to add a custom entity, an entity extension and an entity extension definition, but I couldn’t find any resources on how to implement this setting on the admin page.
this is my extension class:
class CustomizationExtension extends EntityExtension
{
public const EXTENSION_NAME = 'customizationExtension';
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new OneToOneAssociationField(self::EXTENSION_NAME, 'id', 'product_id', CustomizationExtensionDefinition::class, true))
//->addFlags(new Inherited())
);
}
public function getDefinitionClass(): string
{
return ProductDefinition::class;
}
}
and my entity definition:
class CustomizationExtensionDefinition extends EntityDefinition
{
public const ENTITY_NAME = 'maxim_customization_extension';
public function getEntityName(): string
{
return self::ENTITY_NAME;
}
public function getEntityClass():string {
return ProductCustomizationEntity::class;
}
public function getCollectionClass():string {
return ProductCustomizationCollection::class;
}
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
new FkField('product_id', 'productId', ProductDefinition::class),
//(new StringField('customization_text', 'customizationString')),
(new BoolField('is_customizable', 'isCustomizable'))
//->addFlags(new Inherited()),
,
new OneToOneAssociationField('product', 'product_id', 'id', ProductDefinition::class, false),
/*
new ParentFkField(self::class),
new ParentAssociationField(self::class, 'id'),
new ChildrenAssociationField(self::class), */
]);
}
public function isInheritanceAware(): bool
{
// return true;
return false;
}
}
and the entity:
class ProductCustomizationEntity extends Entity
{
use EntityIdTrait;
public const ENTITY_NAME = 'maxim_customization_extension';
public function getEntityName(): string
{
return self::ENTITY_NAME;
}
public function getEntityClass(): string
{
return ExampleEntity::class;
}
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
new FkField('product_id', 'productId', ProductDefinition::class),
//(new StringField('customization_text', 'customizationString')),
(new BoolField('is_customizable', 'isCustomizable'))
//->addFlags(new Inherited()),
,
new CreatedAtField(),
new UpdatedAtField(),
new OneToOneAssociationField('product', 'product_id', 'id', ProductDefinition::class, false),
/* new ParentFkField(self::class),
new ParentAssociationField(Product::class, 'product_id'),
new ChildrenAssociationField(self::class), */
]);
}
public function isInheritanceAware(): bool
{
//return true;
return false;
}
}
I also tried the lines that are commented out.
And finally the product detail form on the admin page:
<sw-switch-field
:label="'asdf'"
v-model="product.isCustomizable"
/>
The switch field shows up but nothing happens when I save it. I tried writing v-model=„product.customizationExtension.isCustomizable“ but I get the error that it’s undefined.
Is it a problem with the extension definition or do I have to further extend the admin form? How do I make the field inheritable for product variations?