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