Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/navarr/m2-module-regionlookup
RegionInformationAcquirer Service Contract
https://github.com/navarr/m2-module-regionlookup
Last synced: about 6 hours ago
JSON representation
RegionInformationAcquirer Service Contract
- Host: GitHub
- URL: https://github.com/navarr/m2-module-regionlookup
- Owner: navarr
- Created: 2017-06-06T14:09:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-06T15:52:29.000Z (over 7 years ago)
- Last Synced: 2024-05-01T19:32:12.089Z (6 months ago)
- Language: PHP
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RegionInformationAcquirer Service Contract
## Installation
This module is really only for developers. You can duplicate it in `app/code` if for some reason you can't use composer (how would that happen??) or you can just
composer require navarr/m2-module-regionlookup
So far this works with all Magento versions, and the composer version constraints are setup so that it won't install if the modules it uses have a breaking change.## Usage
There are three methods for use, however only two are currently implemented:
* `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` is thrown when:
* Country ID could not be found
* Region Name/Code could not be foundA `LocalizedException` is thrown if you dare to use `getRegionInfoById(int $regionId)`
## Example
public function __construct(RegionInformationAcquirerInterface $regionAcquirer)
{
$state = $regionAcquirer->getRegionInfoByCode('US', 'OH');
$state->getId(); // some number
$state->getName(); // Ohio
$state->getCode(); // OH
}