Skip to content

Commit 67f73a7

Browse files
MAGETWO-70052: Fix not detecting current store using store code in url #9429
2 parents fad560a + 28000f6 commit 67f73a7

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
namespace Magento\Checkout\Block\Checkout;
77

88
use Magento\Directory\Helper\Data as DirectoryHelper;
9+
use Magento\Store\Model\StoreManagerInterface;
910
use Magento\Store\Api\StoreResolverInterface;
11+
use Magento\Framework\App\ObjectManager;
1012

1113
/**
1214
* Directory data processor.
@@ -37,9 +39,9 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
3739
private $countryCollectionFactory;
3840

3941
/**
40-
* @var StoreResolverInterface
42+
* @var StoreManagerInterface
4143
*/
42-
private $storeResolver;
44+
private $storeManager;
4345

4446
/**
4547
* @var DirectoryHelper
@@ -49,19 +51,22 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
4951
/**
5052
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection
5153
* @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection
52-
* @param StoreResolverInterface $storeResolver
54+
* @param StoreResolverInterface $storeResolver @deprecated
5355
* @param DirectoryHelper $directoryHelper
56+
* @param StoreManagerInterface $storeManager
57+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5458
*/
5559
public function __construct(
5660
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection,
5761
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection,
5862
StoreResolverInterface $storeResolver,
59-
DirectoryHelper $directoryHelper
63+
DirectoryHelper $directoryHelper,
64+
StoreManagerInterface $storeManager = null
6065
) {
6166
$this->countryCollectionFactory = $countryCollection;
6267
$this->regionCollectionFactory = $regionCollection;
63-
$this->storeResolver = $storeResolver;
6468
$this->directoryHelper = $directoryHelper;
69+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6570
}
6671

6772
/**
@@ -91,7 +96,7 @@ private function getCountryOptions()
9196
{
9297
if (!isset($this->countryOptions)) {
9398
$this->countryOptions = $this->countryCollectionFactory->create()->loadByStore(
94-
$this->storeResolver->getCurrentStoreId()
99+
$this->storeManager->getStore()->getId()
95100
)->toOptionArray();
96101
$this->countryOptions = $this->orderCountryOptions($this->countryOptions);
97102
}
@@ -108,7 +113,7 @@ private function getRegionOptions()
108113
{
109114
if (!isset($this->regionOptions)) {
110115
$this->regionOptions = $this->regionCollectionFactory->create()->addAllowedCountriesFilter(
111-
$this->storeResolver->getCurrentStoreId()
116+
$this->storeManager->getStore()->getId()
112117
)->toOptionArray();
113118
}
114119

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ class DirectoryDataProcessorTest extends \PHPUnit_Framework_TestCase
4040
/**
4141
* @var \PHPUnit_Framework_MockObject_MockObject
4242
*/
43-
protected $directoryDataHelperMock;
43+
protected $storeManagerMock;
44+
45+
/**
46+
* @var \PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
private $directoryDataHelperMock;
4449

4550
protected function setUp()
4651
{
@@ -75,6 +80,9 @@ protected function setUp()
7580
$this->storeResolverMock = $this->getMock(
7681
\Magento\Store\Api\StoreResolverInterface::class
7782
);
83+
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
84+
->disableOriginalConstructor()
85+
->getMock();
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

@@ -98,6 +107,12 @@ public function testProcess()
98107
'region_id' => [],
99108
];
100109

110+
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
111+
->disableOriginalConstructor()
112+
->getMock();
113+
$storeMock->expects($this->atLeastOnce())->method('getId')->willReturn(42);
114+
$this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')->willReturn($storeMock);
115+
101116
$this->countryCollectionFactoryMock->expects($this->once())
102117
->method('create')
103118
->willReturn($this->countryCollectionMock);

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)