Load entities with translations in a different language
0
To load an entity (e.g. a product) with translations from another language than the current context, you'll have to construct a context for that language:
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Api\Context\SystemSource;
use Shopware\Core\Framework\Context;
//...
// This will simply use the default context and therefore use the currently active language!
$context = Context::createDefaultContext();
// Instead, create the Context yourself with the language ID / Currency ID, etc. that you wish to use,
// i.e. one specific to a certain saleschannel
$context = new Context(
new SystemSource(),
[],
$salesChannel->getCurrencyId(),
[$salesChannel->getLanguageId(), Defaults::LANGUAGE_SYSTEM]
);
// When using this context, the DAL will pull translations and other localized content from the language you specified.
$searchResult = $this->productRepository->search($someCriteria, $context);
There are no comments yet
Be the first one to comment