forked from Smile-SA/magento2-module-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Smile-SA#13 from delyriand/fix_Smile-SA/magento2-m…
…odule-seller#9 Fix Smile-SA/magento2-module-seller#9 - Display country information e…
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this module to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\Map | ||
* @author Maxime Leclercq <[email protected]> | ||
* @copyright 2018 Smile | ||
* @license Apache License Version 2.0 | ||
*/ | ||
namespace Smile\Map\Model; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
/** | ||
* Override default implementation of the Magento CountryInformationAcquirer | ||
* for find country information even if it is not in the list of authorized countries. | ||
* | ||
* @category Smile | ||
* @package Smile\Map | ||
*/ | ||
class CountryInformationAcquirer extends \Magento\Directory\Model\CountryInformationAcquirer | ||
{ | ||
/** | ||
* CountryInformationAcquirer constructor. | ||
* | ||
* @param \Magento\Directory\Model\Data\CountryInformationFactory $countryInformationFactory | ||
* @param \Magento\Directory\Model\Data\RegionInformationFactory $regionInformationFactory | ||
* @param \Magento\Directory\Helper\Data $directoryHelper | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection | ||
*/ | ||
public function __construct( | ||
\Magento\Directory\Model\Data\CountryInformationFactory $countryInformationFactory, | ||
\Magento\Directory\Model\Data\RegionInformationFactory $regionInformationFactory, | ||
\Magento\Directory\Helper\Data $directoryHelper, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection | ||
) { | ||
$this->countryCollection = $countryCollection; | ||
parent::__construct($countryInformationFactory, $regionInformationFactory, $directoryHelper, $scopeConfig, $storeManager); | ||
} | ||
|
||
/** | ||
* Get country and region information for the store. | ||
* | ||
* @param string $countryId Country Id | ||
* | ||
* @return \Magento\Directory\Api\Data\CountryInformationInterface | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function getCountryInfo($countryId) | ||
{ | ||
$store = $this->storeManager->getStore(); | ||
$storeLocale = $this->scopeConfig->getValue( | ||
'general/locale/code', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, | ||
$store->getCode() | ||
); | ||
|
||
$countriesCollection = $this->countryCollection->addCountryIdFilter($countryId); | ||
$regions = $this->directoryHelper->getRegionData(); | ||
$country = $countriesCollection->getFirstItem(); | ||
|
||
if (!$country || !$country->getId()) { | ||
throw new NoSuchEntityException( | ||
__( | ||
'Requested country is not available.' | ||
) | ||
); | ||
} | ||
$countryInfo = $this->setCountryInfo($country, $regions, $storeLocale); | ||
|
||
return $countryInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters