Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
JackerNgo committed Nov 30, 2020
2 parents 0b12086 + 1b4377d commit 913c685
Show file tree
Hide file tree
Showing 49 changed files with 1,848 additions and 1,859 deletions.
57 changes: 57 additions & 0 deletions Model/Cart/BuyRequest/GiftCardOptionsDataProvider.php
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);
}
}
33 changes: 33 additions & 0 deletions Model/GiftCardProductTypeResolver.php
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 '';
}
}
89 changes: 89 additions & 0 deletions Model/Resolver/AddGiftCardProductsToCart.php
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,
],
];
}
}
99 changes: 99 additions & 0 deletions Model/Resolver/AddList.php
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()));
}
}
}
85 changes: 85 additions & 0 deletions Model/Resolver/CheckCode.php
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;
}
}
Loading

0 comments on commit 913c685

Please sign in to comment.