Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not detecting current store using store code in url using $storeResolver->getCurrentStoreId() #9429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Directory data processor.
Expand Down Expand Up @@ -37,9 +38,9 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
private $countryCollectionFactory;

/**
* @var StoreResolverInterface
* @var StoreManagerInterface
*/
private $storeResolver;
private $storeManager;

/**
* @var DirectoryHelper
Expand All @@ -51,17 +52,19 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
* @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection
* @param StoreResolverInterface $storeResolver
* @param DirectoryHelper $directoryHelper
* @param StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection,
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection,
StoreResolverInterface $storeResolver,
DirectoryHelper $directoryHelper
DirectoryHelper $directoryHelper,
StoreManagerInterface $storeManager = null
) {
$this->countryCollectionFactory = $countryCollection;
$this->regionCollectionFactory = $regionCollection;
$this->storeResolver = $storeResolver;
$this->directoryHelper = $directoryHelper;
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand Down Expand Up @@ -91,7 +94,7 @@ private function getCountryOptions()
{
if (!isset($this->countryOptions)) {
$this->countryOptions = $this->countryCollectionFactory->create()->loadByStore(
$this->storeResolver->getCurrentStoreId()
$this->storeManager->getStore()->getId()
)->toOptionArray();
$this->countryOptions = $this->orderCountryOptions($this->countryOptions);
}
Expand All @@ -108,7 +111,7 @@ private function getRegionOptions()
{
if (!isset($this->regionOptions)) {
$this->regionOptions = $this->regionCollectionFactory->create()->addAllowedCountriesFilter(
$this->storeResolver->getCurrentStoreId()
$this->storeManager->getStore()->getId()
)->toOptionArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class DirectoryDataProcessorTest extends \PHPUnit_Framework_TestCase
*/
protected $storeResolverMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -75,6 +80,9 @@ protected function setUp()
$this->storeResolverMock = $this->getMock(
\Magento\Store\Api\StoreResolverInterface::class
);
$this->storeManagerMock = $this->getMock(
\Magento\Store\Model\StoreManagerInterface::class
);
$this->directoryDataHelperMock = $this->getMock(
\Magento\Directory\Helper\Data::class,
[],
Expand All @@ -87,7 +95,8 @@ protected function setUp()
$this->countryCollectionFactoryMock,
$this->regionCollectionFactoryMock,
$this->storeResolverMock,
$this->directoryDataHelperMock
$this->directoryDataHelperMock,
$this->storeManagerMock
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*/
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;

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

/**
* @var StoreResolverInterface
* @var StoreManagerInterface
*/
private $storeResolver;
private $storeManager;

/**
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
Expand All @@ -55,7 +53,7 @@ public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->_createCountriesCollection()->loadByStore(
$this->getStoreResolver()->getCurrentStoreId()
$this->getStoreManager()->getStore()->getId()
)->toOptionArray();
}
return $this->_options;
Expand All @@ -70,16 +68,16 @@ protected function _createCountriesCollection()
}

/**
* Retrieve Store Resolver
* Retrieve Store Manager
* @deprecated
* @return StoreResolverInterface
* @return StoreManagerInterface
*/
private function getStoreResolver()
private function getStoreManager()
{
if (!$this->storeResolver) {
$this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class);
if (!$this->storeManager) {
$this->storeManager = ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

return $this->storeResolver;
return $this->storeManager;
}
}