Search code examples
shopware

How to get the sales channel url in Shopware 6?


How to get the sales channel URL in Shopware 6 php, e.g. in a scheduled task. Which object does keep such information?


Solution

  • I actually found a way to get all of the urls:

    // retrieve all urls
            $urls = [];
            $salesChannelRepository = $this->container->get('sales_channel.repository');
            $criteria = new Criteria();
            $criteria->addAssociation('domains');
            $salesChannelIds = $salesChannelRepository->search($criteria, Context::createDefaultContext());
            foreach($salesChannelIds->getEntities()->getElements() as $key => $salesChannel){
                foreach($salesChannel->getDomains()->getElements() as $element){
                    array_push($urls, $element->getUrl());
                }
            }