Skip to content

Commit a3073c5

Browse files
committed
ACP2E-4294: Restricted Category Products Still Counted in Wishlist After Customer Group Update
1 parent 09c2a3f commit a3073c5

File tree

8 files changed

+1284
-1245
lines changed

8 files changed

+1284
-1245
lines changed

app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ protected function _assignOptions()
319319
* @return $this
320320
*/
321321
protected function _assignProducts()
322-
{
322+
{//here
323323
\Magento\Framework\Profiler::start(
324324
'WISHLIST:' . __METHOD__,
325325
['group' => 'WISHLIST', 'method' => __METHOD__]
@@ -351,7 +351,7 @@ protected function _assignProducts()
351351
/** @var \Magento\Wishlist\Model\Item $item */
352352
foreach ($this as $item) {
353353
$product = $productCollection->getItemById($item->getProductId());
354-
if ($product) {
354+
if ($product && !$product->getIsHidden()) {
355355
if ($checkInStock && !$product->isInStock()) {
356356
$this->removeItemByKey($item->getId());
357357
} else {

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

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

394393
return $this->_itemCollection;

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

Lines changed: 0 additions & 80 deletions
This file was deleted.

app/code/Magento/Wishlist/Test/Unit/Block/Customer/Wishlist/Item/OptionsTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
use Magento\Framework\App\Http\Context;
1414
use Magento\Framework\Escaper;
1515
use Magento\Framework\Event\ManagerInterface;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1617
use Magento\Wishlist\Block\Customer\Wishlist\Item\Options;
1718
use Magento\Wishlist\Model\Item;
1819
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021

2122
class OptionsTest extends TestCase
2223
{
23-
public const TEST_PRODUCT_TYPE = 'testProductType';
24-
public const TEST_HELPER_CLASS_NAME = 'testHelperClass';
24+
const TEST_PRODUCT_TYPE = 'testProductType';
25+
const TEST_HELPER_CLASS_NAME = 'testHelperClass';
2526

2627
/**
2728
* @var Escaper|MockObject
@@ -76,7 +77,15 @@ protected function setUp(): void
7677
->disableOriginalConstructor()
7778
->getMock();
7879

79-
$this->block = new Options($productContextMock, $this->httpContextMock, $this->helperPoolMock);
80+
$objectManager = new ObjectManager($this);
81+
$this->block = $objectManager->getObject(
82+
Options::class,
83+
[
84+
'context' => $productContextMock,
85+
'httpContext' => $this->httpContextMock,
86+
'helperPool' => $this->helperPoolMock,
87+
]
88+
);
8089
$this->block->setItem($this->itemMock);
8190
$this->block->addOptionsRenderCfg(self::TEST_PRODUCT_TYPE, self::TEST_HELPER_CLASS_NAME);
8291
}

app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Magento\Framework\Registry;
2727
use Magento\Framework\Serialize\Serializer\Json;
2828
use Magento\Framework\Stdlib\DateTime;
29-
use Magento\Store\Api\Data\StoreInterface;
3029
use Magento\Store\Model\StoreManagerInterface;
3130
use Magento\Wishlist\Helper\Data;
3231
use Magento\Wishlist\Model\Item;
@@ -36,7 +35,6 @@
3635
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResource;
3736
use Magento\Wishlist\Model\ResourceModel\Wishlist\Collection as WishlistCollection;
3837
use Magento\Wishlist\Model\Wishlist;
39-
use Magento\Wishlist\Model\WishlistItemPermissionsCollectionProcessor;
4038
use PHPUnit\Framework\MockObject\MockObject;
4139
use PHPUnit\Framework\TestCase;
4240

@@ -140,11 +138,6 @@ class WishlistTest extends TestCase
140138
*/
141139
private $stockConfiguration;
142140

143-
/**
144-
* @var WishlistItemPermissionsCollectionProcessor|MockObject
145-
*/
146-
private WishlistItemPermissionsCollectionProcessor $permissionCollectionProcessor;
147-
148141
protected function setUp(): void
149142
{
150143
$context = $this->getMockBuilder(Context::class)
@@ -207,7 +200,6 @@ protected function setUp(): void
207200
->willReturn($this->eventDispatcher);
208201

209202
$this->stockConfiguration = $this->createMock(StockConfigurationInterface::class);
210-
$this->permissionCollectionProcessor = $this->createMock(WishlistItemPermissionsCollectionProcessor::class);
211203

212204
$this->wishlist = new Wishlist(
213205
$context,
@@ -229,36 +221,11 @@ protected function setUp(): void
229221
$this->serializer,
230222
$this->stockRegistry,
231223
$this->scopeConfig,
232-
$this->stockConfiguration,
233-
$this->permissionCollectionProcessor
224+
$this->stockConfiguration
234225
);
235226
}
236227

237-
/**
238-
* @return void
239-
* @throws \Magento\Framework\Exception\NoSuchEntityException
240-
* @throws \PHPUnit\Framework\MockObject\Exception
241-
*/
242-
public function testGetItemCollection(): void
243-
{
244-
$wishlistItemCollection = $this->createMock(Collection::class);
245-
$wishlistItemCollection->expects($this->once())->method('addWishlistFilter')->willReturnSelf();
246-
$wishlistItemCollection->expects($this->once())->method('addStoreFilter')->willReturnSelf();
247-
$wishlistItemCollection->expects($this->once())->method('setVisibilityFilter')->willReturnSelf();
248-
$this->permissionCollectionProcessor->expects($this->once())
249-
->method('execute')
250-
->with($wishlistItemCollection);
251-
$this->itemsFactory->expects($this->once())->method('create')->willReturn($wishlistItemCollection);
252-
$store = $this->createMock(StoreInterface::class);
253-
$this->storeManager->expects($this->any())->method('getStores')->willReturn([$store]);
254-
$this->wishlist->getItemCollection();
255-
}
256-
257-
/**
258-
* @return void
259-
* @throws LocalizedException
260-
*/
261-
public function testLoadByCustomerId(): void
228+
public function testLoadByCustomerId()
262229
{
263230
$customerId = 1;
264231
$customerIdFieldName = 'customer_id';
@@ -375,7 +342,6 @@ public function testUpdateItem($itemId, $buyRequest, $param): void
375342
$this->itemsFactory->expects($this->any())
376343
->method('create')
377344
->willReturn($items);
378-
$this->permissionCollectionProcessor->expects($this->once())->method('execute')->willReturn($items);
379345

380346
$this->productRepository->expects($this->once())
381347
->method('getById')
@@ -414,8 +380,7 @@ private function prepareWishlistItem(): MockObject
414380
return $newItem;
415381
}
416382

417-
protected function getMockForDataObject()
418-
{
383+
protected function getMockForDataObject() {
419384
$dataObjectMock = $this->createMock(DataObject::class);
420385
$dataObjectMock->expects($this->once())
421386
->method('setData')

app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItemsResolver.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory as WishlistItemCollectionFactory;
1818
use Magento\Wishlist\Model\Item;
1919
use Magento\Wishlist\Model\Wishlist;
20-
use Magento\Wishlist\Model\WishlistItemPermissionsCollectionProcessor;
2120

2221
/**
2322
* Fetches the Wishlist Items data according to the GraphQL schema
@@ -27,31 +26,23 @@ class WishlistItemsResolver implements ResolverInterface
2726
/**
2827
* @var WishlistItemCollectionFactory
2928
*/
30-
private WishlistItemCollectionFactory $wishlistItemCollectionFactory;
29+
private $wishlistItemCollectionFactory;
3130

3231
/**
3332
* @var StoreManagerInterface
3433
*/
35-
private StoreManagerInterface $storeManager;
36-
37-
/**
38-
* @var WishlistItemPermissionsCollectionProcessor
39-
*/
40-
private WishlistItemPermissionsCollectionProcessor $permissionCollectionProcessor;
34+
private $storeManager;
4135

4236
/**
4337
* @param WishlistItemCollectionFactory $wishlistItemCollectionFactory
4438
* @param StoreManagerInterface $storeManager
45-
* @param WishlistItemPermissionsCollectionProcessor $permissionCollectionProcessor
4639
*/
4740
public function __construct(
4841
WishlistItemCollectionFactory $wishlistItemCollectionFactory,
49-
StoreManagerInterface $storeManager,
50-
WishlistItemPermissionsCollectionProcessor $permissionCollectionProcessor
42+
StoreManagerInterface $storeManager
5143
) {
5244
$this->wishlistItemCollectionFactory = $wishlistItemCollectionFactory;
5345
$this->storeManager = $storeManager;
54-
$this->permissionCollectionProcessor = $permissionCollectionProcessor;
5546
}
5647

5748
/**
@@ -90,7 +81,6 @@ public function resolve(
9081
*
9182
* @param Wishlist $wishlist
9283
* @return Item[]
93-
* @throws \Exception
9484
*/
9585
private function getWishListItems(Wishlist $wishlist): array
9686
{
@@ -102,7 +92,6 @@ private function getWishListItems(Wishlist $wishlist): array
10292
return $store->getId();
10393
}, $this->storeManager->getStores()))
10494
->setVisibilityFilter();
105-
$this->permissionCollectionProcessor->execute($wishlistItemCollection);
10695
return $wishlistItemCollection->getItems();
10796
}
10897
}

0 commit comments

Comments
 (0)