Skip to content

Commit 59aa476

Browse files
committed
ACP2E-3380: [GraphQl] Wishlist items are visible via GraphQl but not visible on storefront
1 parent a3e7d5a commit 59aa476

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare (strict_types = 1);
77

@@ -13,7 +13,6 @@
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1414
use Magento\Store\Api\Data\StoreInterface;
1515
use Magento\Store\Model\StoreManagerInterface;
16-
use Magento\Wishlist\Model\Item;
1716
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
1817
use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory as WishlistItemCollectionFactory;
1918
use Magento\Wishlist\Model\Wishlist;
@@ -26,12 +25,12 @@ class WishlistItems implements ResolverInterface
2625
/**
2726
* @var WishlistItemCollectionFactory
2827
*/
29-
private $wishlistItemCollectionFactory;
28+
private WishlistItemCollectionFactory $wishlistItemCollectionFactory;
3029

3130
/**
3231
* @var StoreManagerInterface
3332
*/
34-
private $storeManager;
33+
private StoreManagerInterface $storeManager;
3534

3635
/**
3736
* @param WishlistItemCollectionFactory $wishlistItemCollectionFactory
@@ -62,7 +61,7 @@ public function resolve(
6261
$wishlist = $value['model'];
6362

6463
if ($context->getExtensionAttributes()->getStore() instanceof StoreInterface) {
65-
$args['store_id'] = $context->getExtensionAttributes()->getStore()->getStoreId();
64+
$args['store_id'] = $context->getExtensionAttributes()->getStore()->getId();
6665
}
6766

6867
/** @var WishlistItemCollection $wishlistItemCollection */
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare (strict_types = 1);
7+
8+
namespace Magento\WishlistGraphQl\Test\Unit\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\GraphQl\Model\Query\ContextInterface;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\GraphQl\Model\Query\ContextExtensionInterface;
14+
use Magento\Store\Api\Data\StoreInterface;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Wishlist\Model\ResourceModel\Item;
17+
use Magento\Wishlist\Model\ResourceModel\Item\Collection as WishlistItemCollection;
18+
use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory as WishlistItemCollectionFactory;
19+
use Magento\Wishlist\Model\Wishlist;
20+
use Magento\WishlistGraphQl\Model\Resolver\WishlistItems;
21+
use PHPUnit\Framework\MockObject\MockObject;
22+
use PHPUnit\Framework\TestCase;
23+
24+
class WishlistItemsTest extends TestCase
25+
{
26+
/**
27+
* @var WishlistItemCollectionFactory|MockObject
28+
*/
29+
private WishlistItemCollectionFactory $wishlistItemCollectionFactory;
30+
31+
/**
32+
* @var StoreManagerInterface|MockObject
33+
*/
34+
private StoreManagerInterface $storeManager;
35+
36+
/**
37+
* @return void
38+
* @throws \PHPUnit\Framework\MockObject\Exception
39+
*/
40+
protected function setUp(): void
41+
{
42+
$this->wishlistItemCollectionFactory = $this->createMock(WishlistItemCollectionFactory::class);
43+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
44+
}
45+
46+
/**
47+
* @return void
48+
* @throws \PHPUnit\Framework\MockObject\Exception
49+
*/
50+
public function testResolve(): void
51+
{
52+
$storeId = $itemId = 1;
53+
54+
$field = $this->createMock(Field::class);
55+
$context = $this->getMockBuilder(ContextInterface::class)
56+
->disableOriginalConstructor()
57+
->getMock();
58+
$store = $this->createMock(StoreInterface::class);
59+
$store->expects($this->once())->method('getId')->willReturn($storeId);
60+
61+
$extensionAttributes = $this->createMock(ContextExtensionInterface::class);
62+
$extensionAttributes->expects($this->exactly(2))
63+
->method('getStore')
64+
->willReturn($store);
65+
$context->expects($this->exactly(2))
66+
->method('getExtensionAttributes')
67+
->willReturn($extensionAttributes);
68+
$info = $this->createMock(ResolveInfo::class);
69+
$wishlist = $this->createMock(Wishlist::class);
70+
71+
$item = $this->getMockBuilder(Item::class)
72+
->addMethods(['getId', 'getData', 'getDescription', 'getAddedAt', 'getProduct'])
73+
->disableOriginalConstructor()
74+
->getMock();
75+
$item->expects($this->once())->method('getId')->willReturn($itemId);
76+
$item->expects($this->once())->method('getData')->with('qty');
77+
$item->expects($this->once())->method('getDescription');
78+
$item->expects($this->once())->method('getAddedAt');
79+
$item->expects($this->once())->method('getProduct');
80+
81+
$wishlistCollection = $this->createMock(WishlistItemCollection::class);
82+
$wishlistCollection->expects($this->once())
83+
->method('addWishlistFilter')
84+
->willReturnSelf();
85+
$wishlistCollection->expects($this->once())
86+
->method('addStoreFilter')
87+
->with($storeId)
88+
->willReturnSelf();
89+
$wishlistCollection->expects($this->once())->method('setVisibilityFilter')->willReturnSelf();
90+
$wishlistCollection->expects($this->once())->method('setCurPage')->willReturnSelf();
91+
$wishlistCollection->expects($this->once())->method('setPageSize')->willReturnSelf();
92+
$wishlistCollection->expects($this->once())->method('getItems')->willReturn([$item]);
93+
$wishlistCollection->expects($this->once())->method('getCurPage');
94+
$wishlistCollection->expects($this->once())->method('getPageSize');
95+
$wishlistCollection->expects($this->once())->method('getLastPageNumber');
96+
$this->wishlistItemCollectionFactory->expects($this->once())
97+
->method('create')
98+
->willReturn($wishlistCollection);
99+
100+
$resolver = new WishlistItems($this->wishlistItemCollectionFactory, $this->storeManager);
101+
$resolver->resolve($field, $context, $info, ['model' => $wishlist]);
102+
}
103+
}

0 commit comments

Comments
 (0)