I have done a product entity extension with OneToOneAssociation. It was to add a new short description field. I was able to save the field when editing and adding products from admin. The issue is I am not able to import or export the contents of the new fields using shopware import/export in settings. I mapped the field using “shortDescription.translations.DEFAULT.shortDescriptionValue”. I am wondering if there is anything I should add in the code for this to work.
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new OneToOneAssociationField(
'shortDescription',
'id',
'product_id',
ShortDescriptionDefinition::class, false))->addFlags(new Inherited())
);
}
Hi, I would also like to add a teaser description field to the product, could you share or give me pointers about how to add this? I have create a Struct/CustomProductExtension.php with the following:
class CustomProductStruct extends Struct
{
/**
* @var string|null
*/
protected $teaserDescription;
public function getTeaserDescription(): ?string
{
return $this->teaserDescription;
}
public function setTeaserDescription(?string $teaserDescription): void
{
$this->teaserDescription = $teaserDescription;
}
}
and then added in my Extension/Content/Product/CustomProductExtension.php
class CustomProductExtension extends EntityExtension
{
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new OneToOneAssociationField(
'teaserDescription',
'id',
'product_id',
CustomProductStruct::class, false))->addFlags(new Inherited())
);
}
public function getDefinitionClass(): string
{
return ProductDefinition::class;
}
}
add overrode the template by adding to my Resources/app/administration/src/extension/sw-product-detail-base/sw-product-detail-base.html.twig
{% block sw_product_detail_base_basic_info_card %}
{% block sw_product_detail_base_basic_info_teaser_form %}
{% endblock %}
{% block sw_product_detail_base_basic_info_form %}
{% parent %}
{% endblock %}
{% endblock %}
but wondering how to see, edit, add this on my Product page.