Skip to content

Commit ef3cc36

Browse files
committed
Missing key model in Wishlist value data
1 parent 0e8428c commit ef3cc36

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
1414
use Magento\Wishlist\Model\Wishlist;
1515
use Magento\Wishlist\Model\WishlistFactory;
16+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1617

1718
/**
1819
* Fetches the Wishlist data according to the GraphQL schema
@@ -51,6 +52,10 @@ public function resolve(
5152
) {
5253
$customerId = $context->getUserId();
5354

55+
/* Guest checking */
56+
if (!$customerId && 0 === $customerId) {
57+
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
58+
}
5459
/** @var Wishlist $wishlist */
5560
$wishlist = $this->wishlistFactory->create();
5661
$this->wishlistResource->load($wishlist, $customerId, 'customer_id');

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/WishlistTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,36 @@ public function testGetCustomerWishlist(): void
9393
$this->assertEquals($wishlistItemProduct->getName(), $response['wishlist']['items'][0]['product']['name']);
9494
}
9595

96+
/**
97+
* @expectedException \Exception
98+
* @expectedExceptionMessage The current user cannot perform operations on wishlist
99+
*/
100+
public function testGetGuestWishlist()
101+
{
102+
$query =
103+
<<<QUERY
104+
{
105+
wishlist {
106+
items_count
107+
name
108+
sharing_code
109+
updated_at
110+
items {
111+
id
112+
qty
113+
description
114+
added_at
115+
product {
116+
sku
117+
name
118+
}
119+
}
120+
}
121+
}
122+
QUERY;
123+
$this->graphQlQuery($query);
124+
}
125+
96126
/**
97127
* @param string $email
98128
* @param string $password

0 commit comments

Comments
 (0)