Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the sales channel url in Shopware 6?

Tags:

shopware

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

like image 784
David Avatar asked Sep 13 '25 12:09

David


2 Answers

The URL of a sales channel is stored in the associated SalesChannelDomainEntity object. It is a one to many association, so a sales channel can have multiple domains.

For example to get the URL of the first domain use:

$url = $salesChannel->getDomains()->first()->getUrl();
like image 158
Paweł Napierała Avatar answered Sep 17 '25 00:09

Paweł Napierała


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());
            }
        }
like image 22
David Avatar answered Sep 17 '25 02:09

David