3
3
namespace Algolia \AlgoliaSearch \ViewModel \Recommend ;
4
4
5
5
use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
6
+ use Algolia \AlgoliaSearch \Helper \Entity \ProductHelper ;
6
7
use Magento \Checkout \Model \Session ;
8
+ use Magento \Framework \Exception \LocalizedException ;
9
+ use Magento \Framework \Exception \NoSuchEntityException ;
7
10
use Magento \Framework \View \Element \Block \ArgumentInterface ;
8
- use Magento \Framework \ View \ Element \ Template \ Context ;
11
+ use Magento \Store \ Model \ StoreManagerInterface ;
9
12
10
13
class Cart implements ArgumentInterface
11
14
{
@@ -20,34 +23,49 @@ class Cart implements ArgumentInterface
20
23
protected $ configHelper ;
21
24
22
25
/**
23
- * @param Context $context
26
+ * @var ProductHelper
27
+ */
28
+ protected $ productHelper ;
29
+
30
+ /**
31
+ * @param StoreManagerInterface $storeManager
24
32
* @param Session $checkoutSession
25
33
* @param ConfigHelper $configHelper
26
- * @param array $data
34
+ * @param ProductHelper $productHelper
27
35
*/
28
36
public function __construct (
29
- Context $ context ,
37
+ StoreManagerInterface $ storeManager ,
30
38
Session $ checkoutSession ,
31
39
ConfigHelper $ configHelper ,
32
- array $ data = []
40
+ ProductHelper $ productHelper
33
41
) {
42
+ $ this ->storeManager = $ storeManager ;
34
43
$ this ->checkoutSession = $ checkoutSession ;
35
44
$ this ->configHelper = $ configHelper ;
45
+ $ this ->productHelper = $ productHelper ;
36
46
}
37
47
38
48
/**
39
49
* @return array
40
- * @throws \Magento\Framework\Exception\ LocalizedException
41
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
50
+ * @throws LocalizedException
51
+ * @throws NoSuchEntityException
42
52
*/
43
53
public function getAllCartItems ()
44
54
{
45
55
$ cartItems = [];
56
+ $ visibleCartItem = [];
46
57
$ itemCollection = $ this ->checkoutSession ->getQuote ()->getAllVisibleItems ();
47
58
foreach ($ itemCollection as $ item ) {
48
59
$ cartItems [] = $ item ->getProductId ();
49
60
}
50
- return array_unique ($ cartItems );
61
+ $ storeId = $ this ->storeManager ->getStore ()->getId ();
62
+ $ cartProductCollection = $ this ->productHelper ->getProductCollectionQuery ($ storeId , array_unique ($ cartItems ));
63
+ if ($ cartProductCollection ->getSize () > 0 ){
64
+ foreach ($ cartProductCollection as $ product ) {
65
+ $ visibleCartItem [] = $ product ->getId ();
66
+ }
67
+ }
68
+ return $ visibleCartItem ;
51
69
}
52
70
53
71
/**
0 commit comments