How to get the sales channel URL in Shopware 6 php, e.g. in a scheduled task. Which object does keep such information?
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();
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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With