Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MerchantCountry.php
Go to the documentation of this file.
1 <?php
7 
11 class MerchantCountry extends \Magento\Framework\App\Config\Value
12 {
18  protected $directoryHelper;
19 
23  protected $_storeManager;
24 
36  public function __construct(
37  \Magento\Framework\Model\Context $context,
38  \Magento\Framework\Registry $registry,
40  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
42  \Magento\Directory\Helper\Data $directoryHelper,
43  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
44  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
45  array $data = []
46  ) {
47  $this->directoryHelper = $directoryHelper;
48  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
49  $this->_storeManager = $storeManager;
50  }
51 
57  protected function _afterLoad()
58  {
59  $value = (string)$this->getValue();
60  if (empty($value)) {
61  if ($this->getWebsite()) {
62  $defaultCountry = $this->_storeManager->getWebsite(
63  $this->getWebsite()
64  )->getConfig(
65  \Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY
66  );
67  } else {
68  $defaultCountry = $this->directoryHelper->getDefaultCountry($this->getStore());
69  }
70  $this->setValue($defaultCountry);
71  }
72  }
73 }
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Directory\Helper\Data $directoryHelper, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])