Directory data helper
@api
- Since
- 100.0.2
Definition at line 17 of file Data.php.
◆ __construct()
- Parameters
-
\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 | |
Definition at line 122 of file Data.php.
131 parent::__construct($context);
132 $this->_configCacheType = $configCacheType;
133 $this->_countryCollection = $countryCollection;
134 $this->_regCollectionFactory = $regCollectionFactory;
137 $this->_currencyFactory = $currencyFactory;
◆ currencyConvert()
currencyConvert |
( |
|
$amount, |
|
|
|
$from, |
|
|
|
$to = null |
|
) |
| |
Convert currency
- Parameters
-
float | $amount | |
string | $from | |
string | $to | |
- Returns
- float @SuppressWarnings(PHPMD.ShortVariable)
Definition at line 203 of file Data.php.
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);
◆ getBaseCurrencyCode()
Retrieve application base currency code
- Returns
- string
Definition at line 304 of file Data.php.
306 return $this->scopeConfig->getValue(\
Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
'default');
◆ getCountriesWithOptionalZip()
getCountriesWithOptionalZip |
( |
|
$asJson = false | ) |
|
Return ISO2 country codes, which have optional Zip/Postal pre-configured
- Parameters
-
- Returns
- array|string
Definition at line 221 of file Data.php.
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);
◆ getCountriesWithStatesRequired()
getCountriesWithStatesRequired |
( |
|
$asJson = false | ) |
|
Returns the list of countries, for which region is required
- Parameters
-
- Returns
- array
Definition at line 256 of file Data.php.
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);
◆ getCountryCollection()
getCountryCollection |
( |
|
$store = null | ) |
|
Retrieve country collection
- Parameters
-
null | int | string | \Magento\Store\Model\Store | $store | |
- Returns
- \Magento\Directory\Model\ResourceModel\Country\Collection
Definition at line 160 of file Data.php.
162 if (!$this->_countryCollection->isLoaded()) {
163 $this->_countryCollection->loadByStore(
$store);
◆ getDefaultCountry()
getDefaultCountry |
( |
|
$store = null | ) |
|
Return default country code
- Parameters
-
\Magento\Store\Model\Store | string | int | $store | |
- Returns
- string
Definition at line 315 of file Data.php.
317 return $this->scopeConfig->getValue(
318 self::XML_PATH_DEFAULT_COUNTRY,
◆ getRegionCollection()
Retrieve region collection
- Returns
- \Magento\Directory\Model\ResourceModel\Region\Collection
Definition at line 145 of file Data.php.
147 if (!$this->_regionCollection) {
148 $this->_regionCollection = $this->_regCollectionFactory->create();
149 $this->_regionCollection->addCountryFilter($this->getAddress()->getCountryId())->load();
◆ getRegionJson()
Retrieve regions data json
- Returns
- string
Definition at line 173 of file Data.php.
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__);
◆ getTopCountryCodes()
Retrieve list of codes of the most used countries
- Returns
- array
Definition at line 361 of file Data.php.
363 $configValue = (string)$this->scopeConfig->getValue(
364 self::XML_PATH_TOP_COUNTRIES,
367 return !empty($configValue) ? explode(
',', $configValue) : [];
◆ getWeightUnit()
Retrieve weight unit
- Returns
- string
Definition at line 375 of file Data.php.
◆ isRegionRequired()
isRegionRequired |
( |
|
$countryId | ) |
|
Returns flag, which indicates whether region is required for specified country
- Parameters
-
- Returns
- bool
Definition at line 290 of file Data.php.
293 if (!is_array($countyList)) {
296 return in_array($countryId, $countyList);
getCountriesWithStatesRequired($asJson=false)
◆ isShowNonRequiredState()
isShowNonRequiredState |
( |
| ) |
|
Return, whether non-required state should be shown
- Returns
- bool
Definition at line 276 of file Data.php.
278 return (
bool)$this->scopeConfig->getValue(
279 self::XML_PATH_DISPLAY_ALL_STATES,
◆ isZipCodeOptional()
isZipCodeOptional |
( |
|
$countryCode | ) |
|
Check whether zip code is optional for specified country code
- Parameters
-
- Returns
- boolean
Definition at line 244 of file Data.php.
247 return in_array($countryCode, $this->_optZipCountries);
getCountriesWithOptionalZip($asJson=false)
◆ $_configCacheType
◆ $_countryCollection
◆ $_currencyCache
◆ $_currencyFactory
◆ $_optZipCountries
◆ $_regCollectionFactory
◆ $_regionCollection
◆ $_regionJson
◆ $_storeManager
◆ $jsonHelper
◆ OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH
const OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH = 'general/country/optional_zip_countries' |
Config value that lists ISO2 country codes which have optional Zip/Postal pre-configured
Definition at line 22 of file Data.php.
◆ XML_PATH_DEFAULT_COUNTRY
const XML_PATH_DEFAULT_COUNTRY = 'general/country/default' |
#+ Path to config value, which is default country
Definition at line 37 of file Data.php.
◆ XML_PATH_DEFAULT_LOCALE
const XML_PATH_DEFAULT_LOCALE = 'general/locale/code' |
◆ XML_PATH_DEFAULT_TIMEZONE
const XML_PATH_DEFAULT_TIMEZONE = 'general/locale/timezone' |
◆ XML_PATH_DISPLAY_ALL_STATES
const XML_PATH_DISPLAY_ALL_STATES = 'general/region/display_all' |
◆ XML_PATH_STATES_REQUIRED
const XML_PATH_STATES_REQUIRED = 'general/region/state_required' |
◆ XML_PATH_TOP_COUNTRIES
const XML_PATH_TOP_COUNTRIES = 'general/country/destinations' |
#- Path to config value that contains codes of the most used countries. Such countries can be shown on the top of the country list.
Definition at line 46 of file Data.php.
◆ XML_PATH_WEIGHT_UNIT
const XML_PATH_WEIGHT_UNIT = 'general/locale/weight_unit' |
Path to config value that contains weight unit
Definition at line 51 of file Data.php.
The documentation for this class was generated from the following file:
- vendor/magento/module-directory/Helper/Data.php