-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # README.md
- Loading branch information
Showing
49 changed files
with
1,848 additions
and
1,859 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,57 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_GiftCardGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\GiftCardGraphQl\Model\Cart\BuyRequest; | ||
|
||
use Magento\Framework\Stdlib\ArrayManager; | ||
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface; | ||
|
||
/** | ||
* Class GiftCardOptionsDataProvider | ||
* @package Mageplaza\GiftCardGraphQl\Model\Cart\BuyRequest | ||
*/ | ||
class GiftCardOptionsDataProvider implements BuyRequestDataProviderInterface | ||
{ | ||
/** | ||
* @var ArrayManager | ||
*/ | ||
private $arrayManager; | ||
|
||
/** | ||
* GiftCardOptionsDataProvider constructor. | ||
* | ||
* @param ArrayManager $arrayManager | ||
*/ | ||
public function __construct( | ||
ArrayManager $arrayManager | ||
) { | ||
$this->arrayManager = $arrayManager; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(array $cartItemData): array | ||
{ | ||
return $this->arrayManager->get('giftcard_options', $cartItemData); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\GiftCardGraphQl\Model; | ||
|
||
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; | ||
use Mageplaza\GiftCard\Model\Product\Type\GiftCard as Type; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class GiftCardProductTypeResolver implements TypeResolverInterface | ||
{ | ||
/** | ||
* Configurable product type resolver code | ||
*/ | ||
const TYPE_RESOLVER = 'MpGiftCardProduct'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolveType(array $data): string | ||
{ | ||
if (isset($data['type_id']) && $data['type_id'] === Type::TYPE_GIFTCARD) { | ||
return self::TYPE_RESOLVER; | ||
} | ||
return ''; | ||
} | ||
} |
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,89 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_GiftCardGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\GiftCardGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\QuoteGraphQl\Model\Cart\AddProductsToCart; | ||
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; | ||
|
||
/** | ||
* Class AddGiftCardProductsToCart | ||
* @package Mageplaza\GiftCardGraphQl\Model\Resolver | ||
*/ | ||
class AddGiftCardProductsToCart implements ResolverInterface | ||
{ | ||
/** | ||
* @var GetCartForUser | ||
*/ | ||
private $getCartForUser; | ||
|
||
/** | ||
* @var AddProductsToCart | ||
*/ | ||
private $addProductsToCart; | ||
|
||
/** | ||
* AddGiftCardProductsToCart constructor. | ||
* | ||
* @param GetCartForUser $getCartForUser | ||
* @param AddProductsToCart $addProductsToCart | ||
*/ | ||
public function __construct( | ||
GetCartForUser $getCartForUser, | ||
AddProductsToCart $addProductsToCart | ||
) { | ||
$this->getCartForUser = $getCartForUser; | ||
$this->addProductsToCart = $addProductsToCart; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) { | ||
throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); | ||
} | ||
$maskedCartId = $args['input']['cart_id']; | ||
|
||
if (!isset($args['input']['cart_items']) || empty($args['input']['cart_items']) | ||
|| !is_array($args['input']['cart_items']) | ||
) { | ||
throw new GraphQlInputException(__('Required parameter "cart_items" is missing')); | ||
} | ||
$cartItems = $args['input']['cart_items']; | ||
|
||
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); | ||
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); | ||
$this->addProductsToCart->execute($cart, $cartItems); | ||
|
||
return [ | ||
'cart' => [ | ||
'model' => $cart, | ||
], | ||
]; | ||
} | ||
} |
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,99 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_GiftCardGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\GiftCardGraphQl\Model\Resolver; | ||
|
||
use Exception; | ||
use Magento\CustomerGraphQl\Model\Customer\GetCustomer; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\GraphQl\Model\Query\ContextInterface; | ||
use Mageplaza\GiftCard\Api\GiftCardManagementInterface; | ||
use Mageplaza\GiftCard\Helper\Product; | ||
|
||
/** | ||
* Class AddList | ||
* @package Mageplaza\GiftCardGraphQl\Model\Resolver | ||
*/ | ||
class AddList implements ResolverInterface | ||
{ | ||
/** | ||
* @var GetCustomer | ||
*/ | ||
private $getCustomer; | ||
|
||
/** | ||
* @var Product | ||
*/ | ||
private $productHelper; | ||
|
||
/** | ||
* @var GiftCardManagementInterface | ||
*/ | ||
private $giftCardManagement; | ||
|
||
/** | ||
* AddList constructor. | ||
* | ||
* @param GetCustomer $getCustomer | ||
* @param Product $productHelper | ||
* @param GiftCardManagementInterface $giftCardManagement | ||
*/ | ||
public function __construct( | ||
GetCustomer $getCustomer, | ||
Product $productHelper, | ||
GiftCardManagementInterface $giftCardManagement | ||
) { | ||
$this->getCustomer = $getCustomer; | ||
$this->productHelper = $productHelper; | ||
$this->giftCardManagement = $giftCardManagement; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$this->productHelper->isEnabled()) { | ||
throw new GraphQlInputException(__('The module is disabled')); | ||
} | ||
/** @var ContextInterface $context */ | ||
if ($context->getExtensionAttributes()->getIsCustomer() === false) { | ||
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.')); | ||
} | ||
|
||
$customer = $this->getCustomer->execute($context); | ||
try { | ||
return $this->giftCardManagement->addList($customer->getId(), $args['code']); | ||
} catch (Exception $e) { | ||
throw new GraphQlInputException(__($e->getMessage())); | ||
} | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_GiftCardGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\GiftCardGraphQl\Model\Resolver; | ||
|
||
use Exception; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Mageplaza\GiftCard\Api\GiftCodeManagementInterface; | ||
use Mageplaza\GiftCard\Helper\Product; | ||
|
||
/** | ||
* Class CheckCode | ||
* @package Mageplaza\GiftCardGraphQl\Model\Resolver | ||
*/ | ||
class CheckCode implements ResolverInterface | ||
{ | ||
/** | ||
* @var Product | ||
*/ | ||
private $productHelper; | ||
|
||
/** | ||
* @var GiftCodeManagementInterface | ||
*/ | ||
private $giftCodeManagement; | ||
|
||
/** | ||
* CheckCode constructor. | ||
* | ||
* @param Product $productHelper | ||
* @param GiftCodeManagementInterface $giftCodeManagement | ||
*/ | ||
public function __construct( | ||
Product $productHelper, | ||
GiftCodeManagementInterface $giftCodeManagement | ||
) { | ||
$this->productHelper = $productHelper; | ||
$this->giftCodeManagement = $giftCodeManagement; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$this->productHelper->isEnabled()) { | ||
throw new GraphQlInputException(__('The module is disabled')); | ||
} | ||
|
||
try { | ||
$result = $this->giftCodeManagement->check($args['code']); | ||
} catch (Exception $e) { | ||
throw new GraphQlInputException(__($e->getMessage())); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.