Skip to content

Commit

Permalink
Add locale helper method (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkniest authored Nov 15, 2023
1 parent dfbea32 commit 6289329
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.0] - 2023-11-15
### Added
- Added new helper to get locale by iso code

## [2.3.0] - 2023-08-25
### Added
- Added new helper method to load a TaxEntity by its value.
Expand Down Expand Up @@ -129,6 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `getNotSpecifiedSalutationId`
- `getGermanCountryId`

[2.4.0]: https://github.com/basecom/FixturesPlugin/compare/2.3.0...2.4.0
[2.3.0]: https://github.com/basecom/FixturesPlugin/compare/2.2.1...2.3.0
[2.2.1]: https://github.com/basecom/FixturesPlugin/compare/2.2.0...2.2.1
[2.2.0]: https://github.com/basecom/FixturesPlugin/compare/2.1.0...2.2.0
Expand Down
18 changes: 17 additions & 1 deletion src/Utils/SalesChannelUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Shopware\Core\System\Country\CountryEntity;
use Shopware\Core\System\Currency\CurrencyEntity;
use Shopware\Core\System\Language\LanguageEntity;
use Shopware\Core\System\Locale\LocaleEntity;
use Shopware\Core\System\SalesChannel\SalesChannelEntity;
use Shopware\Core\System\Snippet\Aggregate\SnippetSet\SnippetSetEntity;
use Shopware\Core\System\Tax\TaxEntity;
Expand All @@ -24,15 +25,17 @@ class SalesChannelUtils
private EntityRepository $countryRepository;
private EntityRepository $languageRepository;
private EntityRepository $currencyRepository;
private EntityRepository $localeRepository;

public function __construct(EntityRepository $salesChannelRepository, EntityRepository $snippetSetRepository, EntityRepository $taxRepository, EntityRepository $countryRepository, EntityRepository $languageRepository, EntityRepository $currencyRepository)
public function __construct(EntityRepository $salesChannelRepository, EntityRepository $snippetSetRepository, EntityRepository $taxRepository, EntityRepository $countryRepository, EntityRepository $languageRepository, EntityRepository $currencyRepository, EntityRepository $localeRepository)
{
$this->salesChannelRepository = $salesChannelRepository;
$this->snippetSetRepository = $snippetSetRepository;
$this->taxRepository = $taxRepository;
$this->countryRepository = $countryRepository;
$this->languageRepository = $languageRepository;
$this->currencyRepository = $currencyRepository;
$this->localeRepository = $localeRepository;
}

public function getStorefrontSalesChannel(): ?SalesChannelEntity
Expand Down Expand Up @@ -89,6 +92,19 @@ public function getLanguage(string $languageName): ?LanguageEntity
return $language instanceof LanguageEntity ? $language : null;
}

public function getLocale(string $code): ?LocaleEntity
{
$criteria = (new Criteria())->addFilter(
new EqualsFilter('code', $code)
)->setLimit(1);

$locale = $this->localeRepository
->search($criteria, Context::createDefaultContext())
->first();

return $locale instanceof LocaleEntity ? $locale : null;
}

public function getCountry(string $countryIso): ?CountryEntity
{
$criteria = (new Criteria())->addFilter(
Expand Down

0 comments on commit 6289329

Please sign in to comment.