Skip to content

Commit 5705fbf

Browse files
committed
MAGETWO-70052: Fix not detecting current store using store code in url #9429
- Merge Pull Request #9429 from mimarcel/magento2:fix/wrong_allowed_countries_in_checkout - Merged commits: 1. b4e3113 2. 0fcb792 3. 5475184
2 parents d844e31 + 5475184 commit 5705fbf

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

app/code/Magento/Checkout/Block/Checkout/DirectoryDataProcessor.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Directory\Helper\Data as DirectoryHelper;
99
use Magento\Store\Api\StoreResolverInterface;
10+
use Magento\Store\Model\StoreManagerInterface;
1011

1112
/**
1213
* Directory data processor.
@@ -37,9 +38,9 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
3738
private $countryCollectionFactory;
3839

3940
/**
40-
* @var StoreResolverInterface
41+
* @var StoreManagerInterface
4142
*/
42-
private $storeResolver;
43+
private $storeManager;
4344

4445
/**
4546
* @var DirectoryHelper
@@ -51,17 +52,19 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
5152
* @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection
5253
* @param StoreResolverInterface $storeResolver
5354
* @param DirectoryHelper $directoryHelper
55+
* @param StoreManagerInterface $storeManager
5456
*/
5557
public function __construct(
5658
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection,
5759
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection,
5860
StoreResolverInterface $storeResolver,
59-
DirectoryHelper $directoryHelper
61+
DirectoryHelper $directoryHelper,
62+
StoreManagerInterface $storeManager = null
6063
) {
6164
$this->countryCollectionFactory = $countryCollection;
6265
$this->regionCollectionFactory = $regionCollection;
63-
$this->storeResolver = $storeResolver;
6466
$this->directoryHelper = $directoryHelper;
67+
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
6568
}
6669

6770
/**
@@ -91,7 +94,7 @@ private function getCountryOptions()
9194
{
9295
if (!isset($this->countryOptions)) {
9396
$this->countryOptions = $this->countryCollectionFactory->create()->loadByStore(
94-
$this->storeResolver->getCurrentStoreId()
97+
$this->storeManager->getStore()->getId()
9598
)->toOptionArray();
9699
$this->countryOptions = $this->orderCountryOptions($this->countryOptions);
97100
}
@@ -108,7 +111,7 @@ private function getRegionOptions()
108111
{
109112
if (!isset($this->regionOptions)) {
110113
$this->regionOptions = $this->regionCollectionFactory->create()->addAllowedCountriesFilter(
111-
$this->storeResolver->getCurrentStoreId()
114+
$this->storeManager->getStore()->getId()
112115
)->toOptionArray();
113116
}
114117

app/code/Magento/Checkout/Test/Unit/Block/Checkout/DirectoryDataProcessorTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class DirectoryDataProcessorTest extends \PHPUnit_Framework_TestCase
3737
*/
3838
protected $storeResolverMock;
3939

40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
protected $storeManagerMock;
44+
4045
/**
4146
* @var \PHPUnit_Framework_MockObject_MockObject
4247
*/
@@ -75,6 +80,9 @@ protected function setUp()
7580
$this->storeResolverMock = $this->getMock(
7681
\Magento\Store\Api\StoreResolverInterface::class
7782
);
83+
$this->storeManagerMock = $this->getMock(
84+
\Magento\Store\Model\StoreManagerInterface::class
85+
);
7886
$this->directoryDataHelperMock = $this->getMock(
7987
\Magento\Directory\Helper\Data::class,
8088
[],
@@ -87,7 +95,8 @@ protected function setUp()
8795
$this->countryCollectionFactoryMock,
8896
$this->regionCollectionFactoryMock,
8997
$this->storeResolverMock,
90-
$this->directoryDataHelperMock
98+
$this->directoryDataHelperMock,
99+
$this->storeManagerMock
91100
);
92101
}
93102

app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/Country.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
*/
1212
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;
1313

14-
use Magento\Checkout\Model\Session;
1514
use Magento\Framework\App\ObjectManager;
16-
use Magento\Store\Api\StoreResolverInterface;
1715
use Magento\Store\Model\StoreManagerInterface;
1816

1917
/**
@@ -28,9 +26,9 @@ class Country extends \Magento\Eav\Model\Entity\Attribute\Source\Table
2826
protected $_countriesFactory;
2927

3028
/**
31-
* @var StoreResolverInterface
29+
* @var StoreManagerInterface
3230
*/
33-
private $storeResolver;
31+
private $storeManager;
3432

3533
/**
3634
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
@@ -55,7 +53,7 @@ public function getAllOptions()
5553
{
5654
if (!$this->_options) {
5755
$this->_options = $this->_createCountriesCollection()->loadByStore(
58-
$this->getStoreResolver()->getCurrentStoreId()
56+
$this->getStoreManager()->getStore()->getId()
5957
)->toOptionArray();
6058
}
6159
return $this->_options;
@@ -70,16 +68,16 @@ protected function _createCountriesCollection()
7068
}
7169

7270
/**
73-
* Retrieve Store Resolver
71+
* Retrieve Store Manager
7472
* @deprecated
75-
* @return StoreResolverInterface
73+
* @return StoreManagerInterface
7674
*/
77-
private function getStoreResolver()
75+
private function getStoreManager()
7876
{
79-
if (!$this->storeResolver) {
80-
$this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class);
77+
if (!$this->storeManager) {
78+
$this->storeManager = ObjectManager::getInstance()->get(StoreManagerInterface::class);
8179
}
8280

83-
return $this->storeResolver;
81+
return $this->storeManager;
8482
}
8583
}

0 commit comments

Comments
 (0)