124 \
Magento\Framework\
App\Cache\Type\Config $configCacheType,
129 \
Magento\Directory\Model\CurrencyFactory $currencyFactory
131 parent::__construct($context);
132 $this->_configCacheType = $configCacheType;
133 $this->_countryCollection = $countryCollection;
134 $this->_regCollectionFactory = $regCollectionFactory;
137 $this->_currencyFactory = $currencyFactory;
147 if (!$this->_regionCollection) {
148 $this->_regionCollection = $this->_regCollectionFactory->create();
149 $this->_regionCollection->addCountryFilter($this->getAddress()->getCountryId())->load();
162 if (!$this->_countryCollection->isLoaded()) {
163 $this->_countryCollection->loadByStore(
$store);
175 \Magento\Framework\Profiler::start(
'TEST: ' . __METHOD__, [
'group' =>
'TEST',
'method' => __METHOD__]);
176 if (!$this->_regionJson) {
177 $cacheKey =
'DIRECTORY_REGIONS_JSON_STORE' . $this->_storeManager->getStore()->getId();
178 $json = $this->_configCacheType->load($cacheKey);
180 $regions = $this->getRegionData();
181 $json = $this->jsonHelper->jsonEncode($regions);
182 if ($json ===
false) {
185 $this->_configCacheType->save($json, $cacheKey);
187 $this->_regionJson = $json;
190 \Magento\Framework\Profiler::stop(
'TEST: ' . __METHOD__);
205 if (empty($this->_currencyCache[$from])) {
206 $this->_currencyCache[$from] = $this->_currencyFactory->create()->load($from);
209 $to = $this->_storeManager->getStore()->getCurrentCurrencyCode();
211 $converted = $this->_currencyCache[$from]->convert(
$amount, $to);
223 if (
null === $this->_optZipCountries) {
225 $this->scopeConfig->getValue(
226 self::OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH,
230 $this->_optZipCountries = preg_split(
'/\,/',
$value, 0, PREG_SPLIT_NO_EMPTY);
233 return $this->jsonHelper->jsonEncode($this->_optZipCountries);
247 return in_array($countryCode, $this->_optZipCountries);
259 $this->scopeConfig->getValue(
260 self::XML_PATH_STATES_REQUIRED,
264 $countryList = preg_split(
'/\,/',
$value, 0, PREG_SPLIT_NO_EMPTY);
266 return $this->jsonHelper->jsonEncode($countryList);
278 return (
bool)$this->scopeConfig->getValue(
279 self::XML_PATH_DISPLAY_ALL_STATES,
293 if (!is_array($countyList)) {
296 return in_array($countryId, $countyList);
306 return $this->scopeConfig->getValue(\
Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
'default');
317 return $this->scopeConfig->getValue(
318 self::XML_PATH_DEFAULT_COUNTRY,
329 public function getRegionData()
333 $countryIds[] = $country->getCountryId();
335 $collection = $this->_regCollectionFactory->create();
336 $collection->addCountryFilter($countryIds)->load();
345 if (!$region->getRegionId()) {
348 $regions[$region->getCountryId()][$region->getRegionId()] = [
349 'code' => $region->getCode(),
350 'name' => (string)
__($region->getName()),
363 $configValue = (string)$this->scopeConfig->getValue(
364 self::XML_PATH_TOP_COUNTRIES,
367 return !empty($configValue) ? explode(
',', $configValue) : [];
isZipCodeOptional($countryCode)
getCountriesWithOptionalZip($asJson=false)
const OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Cache\Type\Config $configCacheType, \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regCollectionFactory, \Magento\Framework\Json\Helper\Data $jsonHelper, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Directory\Model\CurrencyFactory $currencyFactory)
isRegionRequired($countryId)
const XML_PATH_STATES_REQUIRED
const XML_PATH_DISPLAY_ALL_STATES
getDefaultCountry($store=null)
currencyConvert($amount, $from, $to=null)
getCountriesWithStatesRequired($asJson=false)
const XML_PATH_TOP_COUNTRIES
const XML_PATH_DEFAULT_TIMEZONE
const XML_PATH_DEFAULT_COUNTRY
const XML_PATH_WEIGHT_UNIT
getCountryCollection($store=null)
const XML_PATH_DEFAULT_LOCALE