Skip to content

Commit a1aa2b6

Browse files
committed
ACP2E-4294: Restricted Category Products Still Counted in Wishlist After Customer Group Update
1 parent 8450a1f commit a1aa2b6

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

app/code/Magento/Wishlist/Block/AbstractBlock.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66

77
namespace Magento\Wishlist\Block;
88

9-
use Magento\Catalog\Block\Product\Context;
109
use Magento\Catalog\Helper\Image;
1110
use Magento\Catalog\Model\Product\Image\UrlBuilder;
12-
use Magento\Framework\Exception\NoSuchEntityException;
1311
use Magento\Framework\View\ConfigInterface;
1412
use Magento\Framework\App\ObjectManager;
15-
use Magento\Wishlist\Model\WishlistItemPermissionsCollectionProcessor;
1613

1714
/**
1815
* Wishlist Product Items abstract Block
19-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2016
*/
2117
abstract class AbstractBlock extends \Magento\Catalog\Block\Product\AbstractProduct
2218
{
@@ -50,25 +46,18 @@ abstract class AbstractBlock extends \Magento\Catalog\Block\Product\AbstractProd
5046
private $imageUrlBuilder;
5147

5248
/**
53-
* @var WishlistItemPermissionsCollectionProcessor
54-
*/
55-
private $permissionCollectionProcessor;
56-
57-
/**
58-
* @param Context $context
49+
* @param \Magento\Catalog\Block\Product\Context $context
5950
* @param \Magento\Framework\App\Http\Context $httpContext
6051
* @param array $data
6152
* @param ConfigInterface|null $config
6253
* @param UrlBuilder|null $urlBuilder
63-
* @param WishlistItemPermissionsCollectionProcessor|null $permissionCollectionProcessor
6454
*/
6555
public function __construct(
6656
\Magento\Catalog\Block\Product\Context $context,
6757
\Magento\Framework\App\Http\Context $httpContext,
6858
array $data = [],
6959
?ConfigInterface $config = null,
70-
?UrlBuilder $urlBuilder = null,
71-
?WishlistItemPermissionsCollectionProcessor $permissionCollectionProcessor = null
60+
?UrlBuilder $urlBuilder = null
7261
) {
7362
$this->httpContext = $httpContext;
7463
parent::__construct(
@@ -77,8 +66,6 @@ public function __construct(
7766
);
7867
$this->viewConfig = $config ?? ObjectManager::getInstance()->get(ConfigInterface::class);
7968
$this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
80-
$this->permissionCollectionProcessor = $permissionCollectionProcessor ??
81-
ObjectManager::getInstance()->get(WishlistItemPermissionsCollectionProcessor::class);
8269
}
8370

8471
/**
@@ -117,12 +104,10 @@ protected function _prepareCollection($collection)
117104
* Create wishlist item collection
118105
*
119106
* @return \Magento\Wishlist\Model\ResourceModel\Item\Collection
120-
* @throws NoSuchEntityException
121107
*/
122108
protected function _createWishlistItemCollection()
123109
{
124-
$itemCollection = $this->_getWishlist()->getItemCollection();
125-
return $this->permissionCollectionProcessor->execute($itemCollection);
110+
return $this->_getWishlist()->getItemCollection();
126111
}
127112

128113
/**
@@ -247,7 +232,6 @@ public function hasDescription($item)
247232
*
248233
* @param string $date
249234
* @deprecated 101.1.1
250-
* @see getFormattedDate
251235
* @return string
252236
*/
253237
public function getFormatedDate($date)

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public function getItemCollection()
388388
)->addStoreFilter(
389389
$this->getSharedStoreIds()
390390
)->setVisibilityFilter($this->_useCurrentWebsite);
391-
$this->permissionCollectionProcessor->execute($this->_itemCollection);
391+
$this->_itemCollection = $this->permissionCollectionProcessor->execute($this->_itemCollection);
392392
}
393393

394394
return $this->_itemCollection;

app/code/Magento/Wishlist/Model/WishlistItemPermissionsCollectionProcessor.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(
3737
*/
3838
public function execute(Collection $collection): Collection
3939
{
40+
$initialCollection = clone $collection;
41+
4042
$items = $collection->getItems();
4143
if (empty($items)) {
4244
return $collection;
@@ -64,12 +66,12 @@ public function execute(Collection $collection): Collection
6466
}
6567

6668
if (!empty($this->validProductIds[$cacheKey])) {
67-
$collection->addFilter(
69+
$initialCollection->addFieldToFilter(
6870
'main_table.product_id',
69-
'main_table.product_id IN(' . implode(",", $this->validProductIds[$cacheKey]) . ')',
70-
'string'
71+
['in' => $this->validProductIds[$cacheKey]]
7172
);
72-
$collection->clear();
73+
74+
$collection = $initialCollection;
7375
}
7476

7577
return $collection;

0 commit comments

Comments
 (0)