File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
app/code/Magento/WishlistGraphQl/Model/Resolver
dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 13
13
use Magento \Wishlist \Model \ResourceModel \Wishlist as WishlistResourceModel ;
14
14
use Magento \Wishlist \Model \Wishlist ;
15
15
use Magento \Wishlist \Model \WishlistFactory ;
16
+ use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
16
17
17
18
/**
18
19
* Fetches the Wishlist data according to the GraphQL schema
@@ -51,6 +52,10 @@ public function resolve(
51
52
) {
52
53
$ customerId = $ context ->getUserId ();
53
54
55
+ /* Guest checking */
56
+ if (!$ customerId && 0 === $ customerId ) {
57
+ throw new GraphQlAuthorizationException (__ ('The current user cannot perform operations on wishlist ' ));
58
+ }
54
59
/** @var Wishlist $wishlist */
55
60
$ wishlist = $ this ->wishlistFactory ->create ();
56
61
$ this ->wishlistResource ->load ($ wishlist , $ customerId , 'customer_id ' );
Original file line number Diff line number Diff line change @@ -93,6 +93,36 @@ public function testGetCustomerWishlist(): void
93
93
$ this ->assertEquals ($ wishlistItemProduct ->getName (), $ response ['wishlist ' ]['items ' ][0 ]['product ' ]['name ' ]);
94
94
}
95
95
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
+
96
126
/**
97
127
* @param string $email
98
128
* @param string $password
You can’t perform that action at this time.
0 commit comments