class StoreCountryResolver in Commerce Core 8.2
Returns the store's billing country.
A precise default country is important for currency formatting, and the store's billing country is usually more precise than the site's default country returned in DefaultCountryResolver.
Note that this resolver sets the convention of the current store being resolved before the current country. Custom resolvers can reverse that convention if needed.
Hierarchy
- class \Drupal\commerce_store\Resolver\StoreCountryResolver implements CountryResolverInterface
Expanded class hierarchy of StoreCountryResolver
1 string reference to 'StoreCountryResolver'
- commerce_store.services.yml in modules/
store/ commerce_store.services.yml - modules/store/commerce_store.services.yml
1 service uses StoreCountryResolver
File
- modules/
store/ src/ Resolver/ StoreCountryResolver.php, line 20
Namespace
Drupal\commerce_store\ResolverView source
class StoreCountryResolver implements CountryResolverInterface {
/**
* The current store.
*
* @var \Drupal\commerce_store\CurrentStoreInterface
*/
protected $currentStore;
/**
* Constructs a new StoreCountryResolver object.
*
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
* The current store.
*/
public function __construct(CurrentStoreInterface $current_store) {
$this->currentStore = $current_store;
}
/**
* {@inheritdoc}
*/
public function resolve() {
$store = $this->currentStore
->getStore();
$address = $store ? $store
->getAddress() : NULL;
if ($address) {
return new Country($address
->getCountryCode());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StoreCountryResolver:: |
protected | property | The current store. | |
StoreCountryResolver:: |
public | function |
Resolves the country. Overrides CountryResolverInterface:: |
|
StoreCountryResolver:: |
public | function | Constructs a new StoreCountryResolver object. |