Skip to content

Commit

Permalink
CORE-978 Customer address country options got reduced to match store …
Browse files Browse the repository at this point in the history
…configuration
  • Loading branch information
tamasnyulas committed Jul 10, 2017
1 parent bcf1b1b commit d262765
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,17 @@ public function createAddressFormDataProvider()
{
return new AddressFormDataProvider(
$this->getProvidedDependency(CustomerDependencyProvider::FACADE_COUNTRY),
$this->getQueryContainer()
$this->getQueryContainer(),
$this->getStore()
);
}

/**
* @return \Spryker\Shared\Kernel\Store
*/
protected function getStore()
{
return $this->getProvidedDependency(CustomerDependencyProvider::STORE);
}

}
3 changes: 2 additions & 1 deletion src/Spryker/Zed/Customer/Communication/Form/AddressForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(static::OPTION_SALUTATION_CHOICES);
$resolver->setRequired(static::OPTION_COUNTRY_CHOICES);
$resolver->setRequired(static::OPTION_PREFERRED_COUNTRY_CHOICES);
$resolver->setDefined(static::OPTION_PREFERRED_COUNTRY_CHOICES);

$resolver->setDefaults([
'required' => false,
static::OPTION_PREFERRED_COUNTRY_CHOICES => [],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

namespace Spryker\Zed\Customer\Communication\Form\DataProvider;

use Spryker\Shared\Kernel\Store;
use Spryker\Zed\Customer\Communication\Form\AddressForm;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface;

class AddressFormDataProvider extends AbstractCustomerDataProvider
{

const PREFERRED_COUNTRY_NAME = 'Germany';

/**
* @var \Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface
*/
Expand All @@ -26,14 +25,21 @@ class AddressFormDataProvider extends AbstractCustomerDataProvider
*/
protected $customerQueryContainer;

/**
* @var \Spryker\Shared\Kernel\Store
*/
protected $store;

/**
* @param \Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface $countryFacade
* @param \Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface $customerQueryContainer
* @param \Spryker\Shared\Kernel\Store $store
*/
public function __construct(CustomerToCountryInterface $countryFacade, CustomerQueryContainerInterface $customerQueryContainer)
public function __construct(CustomerToCountryInterface $countryFacade, CustomerQueryContainerInterface $customerQueryContainer, Store $store)
{
$this->countryFacade = $countryFacade;
$this->customerQueryContainer = $customerQueryContainer;
$this->store = $store;
}

/**
Expand All @@ -60,7 +66,6 @@ public function getOptions()
return [
AddressForm::OPTION_SALUTATION_CHOICES => $this->getSalutationChoices(),
AddressForm::OPTION_COUNTRY_CHOICES => $this->getCountryChoices(),
AddressForm::OPTION_PREFERRED_COUNTRY_CHOICES => $this->getPreferredCountryChoices(),
];
}

Expand All @@ -69,26 +74,13 @@ public function getOptions()
*/
protected function getCountryChoices()
{
$countryCollection = $this->countryFacade->getAvailableCountries();

$result = [];
if (count($countryCollection->getCountries()) > 0) {
foreach ($countryCollection->getCountries() as $country) {
$result[$country->getIdCountry()] = $country->getName();
}
foreach ($this->store->getCountries() as $iso2Code) {
$countryTransfer = $this->countryFacade->getCountryByIso2Code($iso2Code);
$result[$countryTransfer->getIdCountry()] = $countryTransfer->getName();
}

return $result;
}

/**
* @return array
*/
protected function getPreferredCountryChoices()
{
return [
$this->countryFacade->getPreferredCountryByName(self::PREFERRED_COUNTRY_NAME)->getIdCountry(),
];
}

}
21 changes: 17 additions & 4 deletions src/Spryker/Zed/Customer/CustomerDependencyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public function provideBusinessLayerDependencies(Container $container)
return $container->getLocator()->locale()->queryContainer();
};

$container[static::STORE] = function (Container $container) {
return Store::getInstance();
};

$container = $this->addStore($container);
$container = $this->addCustomerAnonymizerPlugins($container);

return $container;
Expand All @@ -78,6 +75,8 @@ public function provideCommunicationLayerDependencies(Container $container)
return $container->getLocator()->utilDateTime()->service();
};

$container = $this->addStore($container);

return $container;
}

Expand All @@ -103,4 +102,18 @@ protected function getCustomerAnonymizerPlugins()
return [];
}

/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
protected function addStore(Container $container)
{
$container[static::STORE] = function (Container $container) {
return Store::getInstance();
};

return $container;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function getAvailableCountries()
}

/**
* @deprecated Use getCountryByIso2Code() instead.
*
* @param string $iso2Code
*
* @return int
Expand All @@ -51,4 +53,14 @@ public function getIdCountryByIso2Code($iso2Code)
return $this->countryFacade->getIdCountryByIso2Code($iso2Code);
}

/**
* @param string $iso2Code
*
* @return \Generated\Shared\Transfer\CountryTransfer
*/
public function getCountryByIso2Code($iso2Code)
{
return $this->countryFacade->getCountryByIso2Code($iso2Code);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface CustomerToCountryInterface
{

/**
* @deprecated Use getCountryByIso2Code() instead.
*
* @param string $iso2Code
*
* @return int
Expand All @@ -29,4 +31,11 @@ public function getPreferredCountryByName($countryName);
*/
public function getAvailableCountries();

/**
* @param string $iso2Code
*
* @return \Generated\Shared\Transfer\CountryTransfer
*/
public function getCountryByIso2Code($iso2Code);

}

0 comments on commit d262765

Please sign in to comment.