Skip to content

Commit 2bd9ac4

Browse files
committed
PWA-1299: [Graphql] Unable to update the items of a bundle-product in a wishlist
* Minor refactor
1 parent 23b9627 commit 2bd9ac4

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
1616
use Magento\Wishlist\Model\Wishlist;
1717
use Magento\Wishlist\Model\Wishlist\Config as WishlistConfig;
18+
use Magento\Wishlist\Model\Wishlist\Data\Error;
1819
use Magento\Wishlist\Model\Wishlist\Data\WishlistItemFactory;
1920
use Magento\Wishlist\Model\WishlistFactory;
2021
use Magento\WishlistGraphQl\Mapper\WishlistDataMapper;
@@ -98,23 +99,24 @@ public function resolve(
9899
}
99100

100101
$wishlistItems = $this->getWishlistItems($args['wishlistItems'], $wishlist);
101-
$userErrors = [];
102102

103103
foreach ($wishlistItems as $wishlistItem) {
104-
$wishlistOutput = $this->updateWishlistItem->execute($wishlistItem, $wishlist);
105-
$wishlist = $wishlistOutput->getWishlist();
106-
107-
foreach ($wishlistOutput->getErrors() as $error) {
108-
$userErrors[] = [
109-
'code' => $error->getCode(),
110-
'message' => $error->getMessage()
111-
];
112-
}
104+
$this->updateWishlistItem->execute($wishlistItem, $wishlist);
113105
}
114106

107+
$wishlistOutput = $this->updateWishlistItem->prepareOutput($wishlist);
108+
115109
return [
116-
'wishlist' => $this->wishlistDataMapper->map($wishlist),
117-
'user_errors' => $userErrors
110+
'wishlist' => $this->wishlistDataMapper->map($wishlistOutput->getWishlist()),
111+
'user_errors' => array_map(
112+
function (Error $error) {
113+
return [
114+
'code' => $error->getCode(),
115+
'message' => $error->getMessage(),
116+
];
117+
},
118+
$wishlistOutput->getErrors()
119+
)
118120
];
119121
}
120122

app/code/Magento/WishlistGraphQl/Model/UpdateWishlistItem.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public function __construct(
5757
* @param WishlistItemData $wishlistItemData
5858
* @param Wishlist $wishlist
5959
*
60-
* @return WishlistOutput
6160
* @throws LocalizedException
6261
* @throws AlreadyExistsException
6362
*/
@@ -85,8 +84,6 @@ public function execute(WishlistItemData $wishlistItemData, Wishlist $wishlist)
8584

8685
$this->wishlistResource->save($wishlist);
8786
}
88-
89-
return $this->prepareOutput($wishlist);
9087
}
9188

9289
/**
@@ -165,7 +162,7 @@ private function addError(string $message, string $code = null): void
165162
*
166163
* @return WishlistOutput
167164
*/
168-
private function prepareOutput(Wishlist $wishlist): WishlistOutput
165+
public function prepareOutput(Wishlist $wishlist): WishlistOutput
169166
{
170167
$output = new WishlistOutput($wishlist, $this->errors);
171168
$this->errors = [];

0 commit comments

Comments
 (0)