Search code examples
shopware

What is the difference between the SalesChannelRepository and the EntityRepository repositories?


In Shopware 6 you have 2 types of auto generated repositories. Those who implement the \Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface and those who implement the \Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface.

What is the difference between them and when to use which?


Solution

  • Generally you should use the EntityRepositoryInterface for "admin" work, for example to update, import or delete data.

    The SalesChannelRepositoryInterface should be used every time a SalesChannelContext is available. For instance the product instance returns SalesChannelProductEntity a extension of the Product Entity, with more data.