@@ -45,6 +45,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
45
45
*/
46
46
protected $ _quoteConfig ;
47
47
48
+ /**
49
+ * @var \Magento\Store\Model\StoreManagerInterface|null
50
+ */
51
+ private $ storeManager ;
52
+
48
53
/**
49
54
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
50
55
* @param \Psr\Log\LoggerInterface $logger
@@ -56,6 +61,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
56
61
* @param \Magento\Quote\Model\Quote\Config $quoteConfig
57
62
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
58
63
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
64
+ * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
59
65
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
60
66
*/
61
67
public function __construct (
@@ -68,7 +74,8 @@ public function __construct(
68
74
\Magento \Catalog \Model \ResourceModel \Product \CollectionFactory $ productCollectionFactory ,
69
75
\Magento \Quote \Model \Quote \Config $ quoteConfig ,
70
76
\Magento \Framework \DB \Adapter \AdapterInterface $ connection = null ,
71
- \Magento \Framework \Model \ResourceModel \Db \AbstractDb $ resource = null
77
+ \Magento \Framework \Model \ResourceModel \Db \AbstractDb $ resource = null ,
78
+ \Magento \Store \Model \StoreManagerInterface $ storeManager = null
72
79
) {
73
80
parent ::__construct (
74
81
$ entityFactory ,
@@ -82,6 +89,10 @@ public function __construct(
82
89
$ this ->_itemOptionCollectionFactory = $ itemOptionCollectionFactory ;
83
90
$ this ->_productCollectionFactory = $ productCollectionFactory ;
84
91
$ 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);
85
96
}
86
97
87
98
/**
@@ -101,7 +112,10 @@ protected function _construct()
101
112
*/
102
113
public function getStoreId ()
103
114
{
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 ();
105
119
}
106
120
107
121
/**
0 commit comments