You are here

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

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
commerce_store.store_country_resolver in modules/store/commerce_store.services.yml
Drupal\commerce_store\Resolver\StoreCountryResolver

File

modules/store/src/Resolver/StoreCountryResolver.php, line 20

Namespace

Drupal\commerce_store\Resolver
View 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

Namesort descending Modifiers Type Description Overrides
StoreCountryResolver::$currentStore protected property The current store.
StoreCountryResolver::resolve public function Resolves the country. Overrides CountryResolverInterface::resolve
StoreCountryResolver::__construct public function Constructs a new StoreCountryResolver object.