I am new to shopware 6 and I am not getting the flow how data is displaying on the frontend? Can anyone please help me load categories on the storefront?
Here is the screenshot of categories to display on frontend:
To load entities in shopware 6 you can require the service sales_channel.category.repository
which is an instance of \Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface
.
With this object you are able to search for the wanted categories.
You can add the needed SalesChannelContext
as a parameter of your Route function, shopware will auto fill it if you add the right RouteScope.
See also the shopware docs for this: https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-controller#adding-custom-storefront-controller