Skip to content

Commit ff50247

Browse files
authored
Merge pull request #1448 from algolia/bugfix/MAGE-800
Cart recommendations issue for grouped products in add to cart
2 parents 0247b4c + 3cbe7e5 commit ff50247

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

ViewModel/Recommend/Cart.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace Algolia\AlgoliaSearch\ViewModel\Recommend;
44

55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
67
use Magento\Checkout\Model\Session;
8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Framework\Exception\NoSuchEntityException;
710
use Magento\Framework\View\Element\Block\ArgumentInterface;
8-
use Magento\Framework\View\Element\Template\Context;
11+
use Magento\Store\Model\StoreManagerInterface;
912

1013
class Cart implements ArgumentInterface
1114
{
@@ -20,34 +23,49 @@ class Cart implements ArgumentInterface
2023
protected $configHelper;
2124

2225
/**
23-
* @param Context $context
26+
* @var ProductHelper
27+
*/
28+
protected $productHelper;
29+
30+
/**
31+
* @param StoreManagerInterface $storeManager
2432
* @param Session $checkoutSession
2533
* @param ConfigHelper $configHelper
26-
* @param array $data
34+
* @param ProductHelper $productHelper
2735
*/
2836
public function __construct(
29-
Context $context,
37+
StoreManagerInterface $storeManager,
3038
Session $checkoutSession,
3139
ConfigHelper $configHelper,
32-
array $data = []
40+
ProductHelper $productHelper
3341
) {
42+
$this->storeManager = $storeManager;
3443
$this->checkoutSession = $checkoutSession;
3544
$this->configHelper = $configHelper;
45+
$this->productHelper = $productHelper;
3646
}
3747

3848
/**
3949
* @return array
40-
* @throws \Magento\Framework\Exception\LocalizedException
41-
* @throws \Magento\Framework\Exception\NoSuchEntityException
50+
* @throws LocalizedException
51+
* @throws NoSuchEntityException
4252
*/
4353
public function getAllCartItems()
4454
{
4555
$cartItems = [];
56+
$visibleCartItem = [];
4657
$itemCollection = $this->checkoutSession->getQuote()->getAllVisibleItems();
4758
foreach ($itemCollection as $item) {
4859
$cartItems[] = $item->getProductId();
4960
}
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;
5169
}
5270

5371
/**

0 commit comments

Comments
 (0)