Simple question, but I can't find a solution.
I'm trying to get the sales channel ID in Shopware 6 programmatically, but I'm not succeeding!
// This will fetch product object successfully
$product = $this->productRepository->search($productCriteria, $context)->first();
// This will throw Exception
$salesChannelId = $product->getSalesChannelId();
Any ideas on how to achieve this?
Add association
to your criteria
:
$productCriteria->addAssociation('visibilities');
The visibilities
control in which sales channel the product should be visible.
$product->getVisibilities();
Additional documentation that will help you: