Skip to content

Commit 802ee71

Browse files
Fix country and state selection criteria to select only active
A customer reported a problem with our plugin. She couldn't select Poland from a country list when Endereco plugin was active. After researching the problem, we found out, that Poland was created two time in customer shop, the first one was deactivated, the second was active. Endereco plugin used the deactivated country for country mapping table, the frontend used active country record for display, so it would not be possible to select a correct Poland in the options list via ID. the ID was from the deactivated country which was not in the list. The solution is to filter out inactive countries and - while we are at it - also the states (possibly similar problem). Ref: EST-493
1 parent 87c0d8f commit 802ee71

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Service/AddDataToPage.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Shopware\Core\System\Country\Aggregate\CountryState\CountryStateEntity;
1414
use Shopware\Core\System\Salutation\SalutationEntity;
1515
use Shopware\Core\Framework\Context;
16+
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
1617

1718
class AddDataToPage implements EventSubscriberInterface
1819
{
@@ -421,8 +422,10 @@ private function addAddressCheckData(stdClass &$configContainer, Context $contex
421422
$this->systemConfigService
422423
->get('EnderecoShopware6Client.config.enderecoCheckPayPalExpressAddress', $salesChannelId);
423424

425+
$criteria = (new Criteria())->addFilter(new EqualsFilter('active', 1));
426+
424427
/** @var EntitySearchResult $countries */
425-
$countries = $this->countryRepository->search(new Criteria(), $context);
428+
$countries = $this->countryRepository->search($criteria, $context);
426429
$mapping = [];
427430
$mappingReverse = [];
428431
$codeToNameMapping = [];
@@ -443,8 +446,10 @@ private function addAddressCheckData(stdClass &$configContainer, Context $contex
443446
$configContainer->countryMapping = $this->createSafeJsonString($mapping);
444447
$configContainer->countryMappingReverse = $this->createSafeJsonString($mappingReverse);
445448

449+
$criteria = (new Criteria())->addFilter(new EqualsFilter('active', 1));
450+
446451
/** @var EntitySearchResult $states */
447-
$states = $this->stateRepository->search(new Criteria(), $context);
452+
$states = $this->stateRepository->search($criteria, $context);
448453
$statesMapping = [];
449454
$statesMappingReverse = [];
450455
$statesCodeToNameMapping = [];

0 commit comments

Comments
 (0)