9
9
use Magento \Catalog \Model \ResourceModel \Product \LinkedProductSelectBuilderInterface ;
10
10
use Magento \Framework \App \ResourceConnection ;
11
11
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
12
+ use Magento \Store \Model \StoreManagerInterface ;
13
+ use Magento \Framework \App \ObjectManager ;
12
14
13
15
/**
14
16
* Retrieve list of products where each product contains lower price than others at least for one possible price type
@@ -31,7 +33,12 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
31
33
private $ collectionFactory ;
32
34
33
35
/**
34
- * Key is product id. Value is prepared product collection
36
+ * @var StoreManagerInterface
37
+ */
38
+ private $ storeManager ;
39
+
40
+ /**
41
+ * Key is product id and store id. Value is array of prepared linked products
35
42
*
36
43
* @var array
37
44
*/
@@ -41,34 +48,39 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
41
48
* @param ResourceConnection $resourceConnection
42
49
* @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder
43
50
* @param CollectionFactory $collectionFactory
51
+ * @param StoreManagerInterface $storeManager
44
52
*/
45
53
public function __construct (
46
54
ResourceConnection $ resourceConnection ,
47
55
LinkedProductSelectBuilderInterface $ linkedProductSelectBuilder ,
48
- CollectionFactory $ collectionFactory
56
+ CollectionFactory $ collectionFactory ,
57
+ StoreManagerInterface $ storeManager = null
49
58
) {
50
59
$ this ->resource = $ resourceConnection ;
51
60
$ this ->linkedProductSelectBuilder = $ linkedProductSelectBuilder ;
52
61
$ this ->collectionFactory = $ collectionFactory ;
62
+ $ this ->storeManager = $ storeManager
63
+ ?: ObjectManager::getInstance ()->get (StoreManagerInterface::class);
53
64
}
54
65
55
66
/**
56
67
* {@inheritdoc}
57
68
*/
58
69
public function getProducts (ProductInterface $ product )
59
70
{
60
- if (!isset ($ this ->productsMap [$ product ->getId ()])) {
71
+ $ key = $ this ->storeManager ->getStore ()->getId () . '- ' . $ product ->getId ();
72
+ if (!isset ($ this ->productsMap [$ key ])) {
61
73
$ productIds = $ this ->resource ->getConnection ()->fetchCol (
62
74
'( ' . implode (') UNION ( ' , $ this ->linkedProductSelectBuilder ->build ($ product ->getId ())) . ') '
63
75
);
64
76
65
- $ this ->productsMap [$ product -> getId () ] = $ this ->collectionFactory ->create ()
77
+ $ this ->productsMap [$ key ] = $ this ->collectionFactory ->create ()
66
78
->addAttributeToSelect (
67
79
['price ' , 'special_price ' , 'special_from_date ' , 'special_to_date ' , 'tax_class_id ' ]
68
80
)
69
81
->addIdFilter ($ productIds )
70
82
->getItems ();
71
83
}
72
- return $ this ->productsMap [$ product -> getId () ];
84
+ return $ this ->productsMap [$ key ];
73
85
}
74
86
}
0 commit comments