-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing wishlist graphql error for missing model (#1)
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* ScandiPWA - Progressive Web App for Magento | ||
* | ||
* Copyright © Scandiweb, Inc. All rights reserved. | ||
* See LICENSE for license details. | ||
* | ||
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0) | ||
* @package scandipwa/wishlist-graphql | ||
* @link https://github.com/scandipwa/wishlist-graphql | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ScandiPWA\WishlistGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel; | ||
use Magento\Wishlist\Model\Wishlist; | ||
use Magento\Wishlist\Model\WishlistFactory; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
|
||
/** | ||
* Fetches the Wishlist data according to the GraphQL schema | ||
*/ | ||
class WishlistResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var WishlistResourceModel | ||
*/ | ||
private $wishlistResource; | ||
|
||
/** | ||
* @var WishlistFactory | ||
*/ | ||
private $wishlistFactory; | ||
|
||
/** | ||
* @param WishlistResourceModel $wishlistResource | ||
* @param WishlistFactory $wishlistFactory | ||
*/ | ||
public function __construct(WishlistResourceModel $wishlistResource, WishlistFactory $wishlistFactory) | ||
{ | ||
$this->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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* ScandiPWA - Progressive Web App for Magento | ||
* | ||
* Copyright © Scandiweb, Inc. All rights reserved. | ||
* See LICENSE for license details. | ||
* | ||
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0) | ||
* @package scandipwa/wishlist-graphql | ||
* @link https://github.com/scandipwa/wishlist-graphql | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Magento\WishlistGraphQl\Model\Resolver\WishlistResolver" | ||
type="ScandiPWA\WishlistGraphQl\Model\Resolver\WishlistResolver"/> | ||
</config> |