Skip to content

Commit 49926d7

Browse files
phoenix128mage2pratik
authored andcommitted
FIX for issue#14869 - Wrong price at backend after update A previous commit 9d3be73 changed the default behaviour of \Magento\Quote\Model\ResourceModel\Quote\Item\Collection::getStoreId() using the store coming from the current session instead of using the one from quote. The previous commit was made to fix an error while using getItems() without setting a quote. The current fix restore the previous behaviour and adds a check if the quote is not specified.
1 parent 1d469f8 commit 49926d7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
4545
*/
4646
protected $_quoteConfig;
4747

48+
/**
49+
* @var \Magento\Store\Model\StoreManagerInterface|null
50+
*/
51+
private $storeManager;
52+
4853
/**
4954
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
5055
* @param \Psr\Log\LoggerInterface $logger
@@ -54,6 +59,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
5459
* @param Option\CollectionFactory $itemOptionCollectionFactory
5560
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
5661
* @param \Magento\Quote\Model\Quote\Config $quoteConfig
62+
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
5763
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
5864
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
5965
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -67,6 +73,7 @@ public function __construct(
6773
\Magento\Quote\Model\ResourceModel\Quote\Item\Option\CollectionFactory $itemOptionCollectionFactory,
6874
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
6975
\Magento\Quote\Model\Quote\Config $quoteConfig,
76+
\Magento\Store\Model\StoreManagerInterface $storeManager = null,
7077
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
7178
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
7279
) {
@@ -82,6 +89,10 @@ public function __construct(
8289
$this->_itemOptionCollectionFactory = $itemOptionCollectionFactory;
8390
$this->_productCollectionFactory = $productCollectionFactory;
8491
$this->_quoteConfig = $quoteConfig;
92+
93+
// Backward compatibility constructor parameters
94+
$this->storeManager = $storeManager ?:
95+
\Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Store\Model\StoreManagerInterface::class);
8596
}
8697

8798
/**
@@ -101,7 +112,10 @@ protected function _construct()
101112
*/
102113
public function getStoreId()
103114
{
104-
return (int)$this->_productCollectionFactory->create()->getStoreId();
115+
// Fallback to current storeId if no quote is provided
116+
// (see https://github.com/magento/magento2/commit/9d3be732a88884a66d667b443b3dc1655ddd0721)
117+
return $this->_quote === null ?
118+
(int) $this->storeManager->getStore()->getId() : (int) $this->_quote->getStoreId();
105119
}
106120

107121
/**

0 commit comments

Comments
 (0)