@@ -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
@@ -54,6 +59,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
54
59
* @param Option\CollectionFactory $itemOptionCollectionFactory
55
60
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
56
61
* @param \Magento\Quote\Model\Quote\Config $quoteConfig
62
+ * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
57
63
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
58
64
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
59
65
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -67,6 +73,7 @@ public function __construct(
67
73
\Magento \Quote \Model \ResourceModel \Quote \Item \Option \CollectionFactory $ itemOptionCollectionFactory ,
68
74
\Magento \Catalog \Model \ResourceModel \Product \CollectionFactory $ productCollectionFactory ,
69
75
\Magento \Quote \Model \Quote \Config $ quoteConfig ,
76
+ \Magento \Store \Model \StoreManagerInterface $ storeManager = null ,
70
77
\Magento \Framework \DB \Adapter \AdapterInterface $ connection = null ,
71
78
\Magento \Framework \Model \ResourceModel \Db \AbstractDb $ resource = null
72
79
) {
@@ -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