From dd74f6bd4f70be344f751a3a6896008ab267bf04 Mon Sep 17 00:00:00 2001 From: Riccardo Tempesta Date: Sun, 29 Apr 2018 20:18:57 +0200 Subject: [PATCH 1/2] FIX for issue#14869 - Wrong price at backend after update A previous commit 9d3be732a88884a66d667b443b3dc1655ddd0721 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. --- .../ResourceModel/Quote/Item/Collection.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 0487d7e46eb26..8a89b331172a9 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -45,6 +45,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro */ protected $_quoteConfig; + /** + * @var \Magento\Store\Model\StoreManagerInterface|null + */ + private $storeManager; + /** * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory * @param \Psr\Log\LoggerInterface $logger @@ -54,6 +59,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro * @param Option\CollectionFactory $itemOptionCollectionFactory * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory * @param \Magento\Quote\Model\Quote\Config $quoteConfig + * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -67,6 +73,7 @@ public function __construct( \Magento\Quote\Model\ResourceModel\Quote\Item\Option\CollectionFactory $itemOptionCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Quote\Model\Quote\Config $quoteConfig, + \Magento\Store\Model\StoreManagerInterface $storeManager = null, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null ) { @@ -82,6 +89,10 @@ public function __construct( $this->_itemOptionCollectionFactory = $itemOptionCollectionFactory; $this->_productCollectionFactory = $productCollectionFactory; $this->_quoteConfig = $quoteConfig; + + // Backward compatibility constructor parameters + $this->storeManager = $storeManager ?: + \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Store\Model\StoreManagerInterface::class); } /** @@ -101,7 +112,10 @@ protected function _construct() */ public function getStoreId() { - return (int)$this->_productCollectionFactory->create()->getStoreId(); + // Fallback to current storeId if no quote is provided + // (see https://github.com/magento/magento2/commit/9d3be732a88884a66d667b443b3dc1655ddd0721) + return $this->_quote === null ? + (int) $this->storeManager->getStore()->getId() : (int) $this->_quote->getStoreId(); } /** From e610b72df807218b61526ad8b333fd74e3e9e7b8 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Wed, 2 May 2018 17:29:29 +0300 Subject: [PATCH 2/2] FIX for issue#14869 - Wrong price at backend after update #14904 --- .../Quote/Model/ResourceModel/Quote/Item/Collection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 8a89b331172a9..2405eaa9d37a3 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -59,9 +59,9 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro * @param Option\CollectionFactory $itemOptionCollectionFactory * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory * @param \Magento\Quote\Model\Quote\Config $quoteConfig - * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource + * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -73,9 +73,9 @@ public function __construct( \Magento\Quote\Model\ResourceModel\Quote\Item\Option\CollectionFactory $itemOptionCollectionFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Quote\Model\Quote\Config $quoteConfig, - \Magento\Store\Model\StoreManagerInterface $storeManager = null, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null + \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null, + \Magento\Store\Model\StoreManagerInterface $storeManager = null ) { parent::__construct( $entityFactory,