Skip to content

Commit a5cc790

Browse files
committed
Improving checking the customer wishlist
1 parent 73650e3 commit a5cc790

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function resolve(
8888
$customerId = $context->getUserId();
8989

9090
/* Guest checking */
91-
if (!$customerId && 0 === $customerId) {
91+
if (null === $customerId || 0 === $customerId) {
9292
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
9393
}
9494

@@ -102,8 +102,8 @@ public function resolve(
102102
$wishlist->loadByCustomerId($customerId, true);
103103
}
104104

105-
if (null === $wishlist->getId()) {
106-
throw new GraphQlInputException(__('Something went wrong while creating the wishlist'));
105+
if (null === $wishlist->getId() || $customerId !== (int) $wishlist->getCustomerId()) {
106+
throw new GraphQlInputException(__('The wishlist was not found.'));
107107
}
108108

109109
$wishlistItems = [];

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,24 @@ public function resolve(
8787
$customerId = $context->getUserId();
8888

8989
/* Guest checking */
90-
if (!$customerId && 0 === $customerId) {
90+
if (null === $customerId || 0 === $customerId) {
9191
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
9292
}
9393

94-
$wishlistId = $args['wishlist_id'];
94+
$wishlistId = $args['wishlist_id'] ?: null;
95+
$wishlist = $this->wishlistFactory->create();
9596

96-
if (!$wishlistId) {
97-
throw new GraphQlInputException(__('The wishlist id is missing.'));
97+
if ($wishlistId) {
98+
$this->wishlistResource->load($wishlist, $wishlistId);
99+
} elseif ($customerId) {
100+
$wishlist->loadByCustomerId($customerId, true);
98101
}
99102

100-
$wishlist = $this->wishlistFactory->create();
101-
$this->wishlistResource->load($wishlist, $wishlistId);
103+
if ($wishlistId) {
104+
$this->wishlistResource->load($wishlist, $wishlistId);
105+
}
102106

103-
if (!$wishlist) {
107+
if (null === $wishlist->getId() || $customerId !== (int) $wishlist->getCustomerId()) {
104108
throw new GraphQlInputException(__('The wishlist was not found.'));
105109
}
106110

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,24 @@ public function resolve(
8888
$customerId = $context->getUserId();
8989

9090
/* Guest checking */
91-
if (!$customerId && 0 === $customerId) {
91+
if (null === $customerId || 0 === $customerId) {
9292
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
9393
}
9494

95-
$wishlistId = $args['wishlist_id'];
95+
$wishlistId = $args['wishlist_id'] ?: null;
96+
$wishlist = $this->wishlistFactory->create();
9697

97-
if (!$wishlistId) {
98-
throw new GraphQlInputException(__('The wishlist id is missing.'));
98+
if ($wishlistId) {
99+
$this->wishlistResource->load($wishlist, $wishlistId);
100+
} elseif ($customerId) {
101+
$wishlist->loadByCustomerId($customerId, true);
99102
}
100103

101-
$wishlist = $this->wishlistFactory->create();
102-
103104
if ($wishlistId) {
104105
$this->wishlistResource->load($wishlist, $wishlistId);
105106
}
106107

107-
if (null === $wishlist->getId()) {
108+
if (null === $wishlist->getId() || $customerId !== (int) $wishlist->getCustomerId()) {
108109
throw new GraphQlInputException(__('The wishlist was not found.'));
109110
}
110111

0 commit comments

Comments
 (0)