I have created a custom entity. It has a connection with the ProductDefinition
. Now, I want that I need SaleChannelProductEntity
in the Product association.
How can I get the SalesChannelProductEntity
association(ManyToOne)?
I tried with the Product
association, but it's getting ProductEntity as the association is added with the ProductDefinition
.
You can just extend your regular definition and implement the SalesChannelDefinitionInterface
. Just have a look at the SalesChannelCategoryDefinition
for reference. Then you register the sales channel definition additionally:
<service id="My\Plugin\Definition\SalesChannelCustomEntityDefinition">
<tag name="shopware.sales_channel.entity.definition"/>
</service>
You can then inject the sales channel repository of your custom entity like so: sales_channel.custom_entity.repository
. If you use that repository, associations to ProductDefinition
should then yield instances of SalesChannelProductEntity
instead.