navarr / m2-module-regionlookup
Magento 2 地区查找 API
1.0.0
2017-06-06 14:25 UTC
Requires
- php: ^5.6|^7.0
- magento/module-directory: ^100.0.2
Requires (Dev)
- magento/marketplace-eqp: @stable
- phpmd/phpmd: @stable
- squizlabs/php_codesniffer: ^2.0
This package is auto-updated.
Last update: 2024-09-12 04:31:03 UTC
README
安装
此模块实际上仅供开发者使用。如果由于某些原因您不能使用composer(怎么会这样?),您可以在app/code
中复制它,或者您可以只
composer require navarr/m2-module-regionlookup
到目前为止,该模块与所有Magento版本兼容,并且已设置composer版本约束,以便在它使用的模块有破坏性更改时不会安装。
用法
有三种使用方法,但目前只实现了两种
getRegionInfoByCode(string $countryId, string $regionCode) : \Magento\Directory\Api\Data\RegionInformationInterface, throws NoSuchEntityException
getRegionInfoByName(string $countryId, string $regionName) : \Magento\Directory\Api\Data\RegionInformationInterface, throws NoSuchEntityException
NoSuchEntityException
在以下情况下抛出
- 找不到国家ID
- 找不到地区名称/代码
如果您敢使用getRegionInfoById(int $regionId)
,则会抛出LocalizedException
示例
public function __construct(RegionInformationAcquirerInterface $regionAcquirer)
{
$state = $regionAcquirer->getRegionInfoByCode('US', 'OH');
$state->getId(); // some number
$state->getName(); // Ohio
$state->getCode(); // OH
}