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 2 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 @@ -6,7 +6,7 @@
namespace Magento\Checkout\Block\Checkout;

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 +37,9 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
private $countryCollectionFactory;

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

/**
* @var DirectoryHelper
Expand All @@ -49,18 +49,18 @@ class DirectoryDataProcessor implements \Magento\Checkout\Block\Checkout\LayoutP
/**
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection
* @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection
* @param StoreResolverInterface $storeResolver
* @param StoreManagerInterface $storeManager
* @param DirectoryHelper $directoryHelper
*/
public function __construct(
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection,
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollection,
StoreResolverInterface $storeResolver,
StoreManagerInterface $storeManager,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, due to backwards compatibility policy we may not change constructor arguments. Please add another optional dependency and deprecate the old one if it is not used anymore.

DirectoryHelper $directoryHelper
) {
$this->countryCollectionFactory = $countryCollection;
$this->regionCollectionFactory = $regionCollection;
$this->storeResolver = $storeResolver;
$this->storeManager = $storeManager;
$this->directoryHelper = $directoryHelper;
}

Expand Down Expand Up @@ -91,7 +91,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 +108,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 @@ -35,7 +35,7 @@ class DirectoryDataProcessorTest extends \PHPUnit_Framework_TestCase
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $storeResolverMock;
protected $storeManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -72,8 +72,8 @@ protected function setUp()
'',
false
);
$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 @@ -86,7 +86,7 @@ protected function setUp()
$this->model = new \Magento\Checkout\Block\Checkout\DirectoryDataProcessor(
$this->countryCollectionFactoryMock,
$this->regionCollectionFactoryMock,
$this->storeResolverMock,
$this->storeManagerMock,
$this->directoryDataHelperMock
);
}
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;
}
}