-
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.
Merge pull request #2 from atravkovs/configurable
Added support for Configurable products & implemented 3 endpoints
- Loading branch information
Showing
11 changed files
with
656 additions
and
137 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
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 |
---|---|---|
|
@@ -17,6 +17,10 @@ | |
{ | ||
"name": "Alfreds Genkins", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Artjoms Travkovs", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license": [ | ||
|
This file was deleted.
Oops, something went wrong.
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,84 @@ | ||
<?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 Exception; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
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; | ||
|
||
class ClearWishlist implements ResolverInterface | ||
{ | ||
/** | ||
* @var WishlistFactory | ||
*/ | ||
protected $wishlistFactory; | ||
|
||
/** | ||
* @var WishlistResourceModel | ||
*/ | ||
protected $wishlistResource; | ||
|
||
public function __construct( | ||
WishlistFactory $wishlistFactory, | ||
WishlistResourceModel $wishlistResource | ||
) { | ||
$this->wishlistFactory = $wishlistFactory; | ||
$this->wishlistResource = $wishlistResource; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
$customerId = $context->getUserId(); | ||
if (!$customerId) { | ||
throw new GraphQlAuthorizationException(__('Authorization unsuccessful')); | ||
} | ||
|
||
/** @var Wishlist $wishlist */ | ||
$wishlist = $this->wishlistFactory->create(); | ||
$this->wishlistResource->load($wishlist, $customerId, 'customer_id'); | ||
|
||
if (!$wishlist->getId() || $wishlist->getItemsCount() <= 0) { | ||
return true; | ||
} | ||
|
||
$wishlistItems = $wishlist->getItemCollection(); | ||
foreach ($wishlistItems as $item) { | ||
$item->delete(); | ||
} | ||
|
||
try { | ||
$wishlist->save(); | ||
} catch (Exception $e) { | ||
throw new GraphQlNoSuchEntityException(__('There was an error when clearing wishlist')); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.