From 7b470a95baebb9c7140d2688e37fcad9648604dc Mon Sep 17 00:00:00 2001 From: "anna.bicevska" Date: Thu, 11 Jul 2019 11:51:32 +0300 Subject: [PATCH] Fixing wishlist graphql error for missing model --- src/Model/Resolver/WishlistResolver.php | 82 +++++++++++++++++++++++++ src/etc/di.xml | 17 +++++ 2 files changed, 99 insertions(+) create mode 100644 src/Model/Resolver/WishlistResolver.php create mode 100644 src/etc/di.xml diff --git a/src/Model/Resolver/WishlistResolver.php b/src/Model/Resolver/WishlistResolver.php new file mode 100644 index 0000000..f4777d3 --- /dev/null +++ b/src/Model/Resolver/WishlistResolver.php @@ -0,0 +1,82 @@ +wishlistResource = $wishlistResource; + $this->wishlistFactory = $wishlistFactory; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $customerId = $context->getUserId(); + + /** @var Wishlist $wishlist */ + $wishlist = $this->wishlistFactory->create(); + $this->wishlistResource->load($wishlist, $customerId, 'customer_id'); + + if (null === $wishlist->getId()) { + return [ + 'model' => $wishlist, + ]; + } + + return [ + 'sharing_code' => $wishlist->getSharingCode(), + 'updated_at' => $wishlist->getUpdatedAt(), + 'items_count' => $wishlist->getItemsCount(), + 'name' => $wishlist->getName(), + 'model' => $wishlist, + ]; + } +} diff --git a/src/etc/di.xml b/src/etc/di.xml new file mode 100644 index 0000000..4541144 --- /dev/null +++ b/src/etc/di.xml @@ -0,0 +1,17 @@ + + + + +