How to get the shop-id from the storefront or twig template in shopware 6 app?

35 Views Asked by At

I am trying to obtain the shop-id from the twig template or storefront, which is included in the app registration procedure. Inside the twig template there is only the individual sales-channel-id, which is good, but I can not figure out how to get a relation between those two ids in a third party API which is not part of the app itself. The frontend should make fetch calls to it, with the shop-id, or sales-channel-id, but only if the api can make a relation to it. Thanks for advices or help.

1

There are 1 best solutions below

0
Rune Laenen On

When in a PHP service, you can use this function: \Shopware\Core\Framework\App\ShopId\ShopIdProvider::getShopId

When in twig you should be able to directly use the global appShopId variable. This variable is only available when there is at least 1 app active in the system.