Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JackerNgo committed Dec 10, 2020
2 parents ce025fe + 07b28db commit f226fd2
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 204 deletions.
3 changes: 2 additions & 1 deletion Model/Resolver/AbstractReward.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Mageplaza\RewardPointsUltimate\Helper\Data;
use Mageplaza\RewardPoints\Helper\Data;

/**
* Class AbstractReward
Expand All @@ -43,6 +43,7 @@ abstract class AbstractReward implements ResolverInterface

/**
* AbstractReward constructor.
*
* @param Data $helperData
*/
public function __construct(Data $helperData)
Expand Down
28 changes: 20 additions & 8 deletions Model/Resolver/Cart/SpendingConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@

namespace Mageplaza\RewardPointsGraphQl\Model\Resolver\Cart;

use Magento\Framework\DataObject;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
use Mageplaza\RewardPointsGraphQl\Model\Resolver\AbstractReward;
use Mageplaza\RewardPointsUltimate\Helper\Data;
use Mageplaza\RewardPointsUltimate\Model\CartRepository;
use Mageplaza\RewardPoints\Helper\Data;
use Magento\Framework\Event\ManagerInterface as EventManager;

/**
* Class SpendingConfiguration
Expand All @@ -43,24 +44,24 @@ class SpendingConfiguration extends AbstractReward
private $getCartForUser;

/**
* @var CartRepository
* @var EventManager
*/
protected $cartRepository;
private $eventManager;

/**
* SpendingConfiguration constructor.
*
* @param Data $helperData
* @param GetCartForUser $getCartForUser
* @param CartRepository $cartRepository
* @param EventManager $eventManager
*/
public function __construct(
Data $helperData,
GetCartForUser $getCartForUser,
CartRepository $cartRepository
EventManager $eventManager
) {
$this->getCartForUser = $getCartForUser;
$this->cartRepository = $cartRepository;
$this->eventManager = $eventManager;
parent::__construct($helperData);
}

Expand All @@ -69,6 +70,11 @@ public function __construct(
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{

if (!$this->helperData->isModuleOutputEnabled('Mageplaza_RewardPointsPro')) {
throw new GraphQlInputException(__('Reward Points Pro extension is required.'));
}

parent::resolve($field, $context, $info, $value, $args);

if (empty($args['cart_id'])) {
Expand All @@ -81,7 +87,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
} else {
$quote = $this->getCartForUser->execute($args['cart_id'], $context->getUserId());
}
$spendingRuleObject = new DataObject(['rules' => []]);
$this->eventManager->dispatch('mp_reward_graphql_get_spending_rules', [
'object' => $spendingRuleObject,
'quote' => $quote
]
);

return $this->cartRepository->getSpendingRules($quote);
return $spendingRuleObject->getRules();
}
}
79 changes: 79 additions & 0 deletions Model/Resolver/Configs/Get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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_RewardPointsGraphQl
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

declare(strict_types=1);

namespace Mageplaza\RewardPointsGraphQl\Model\Resolver\Configs;

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\RewardPoints\Helper\Data;
use Mageplaza\RewardPoints\Model\ConfigRepository;

/**
* Class Get
* @package Mageplaza\RewardPointsGraphQl\Model\Resolver\Configs
*/
class Get implements ResolverInterface
{
/**
* @var Data
*/
protected $helperData;

/**
* @var ConfigRepository
*/
protected $configRepository;

/**
* Get constructor.
*
* @param Data $helperData
* @param ConfigRepository $configRepository
*/
public function __construct(
Data $helperData,
ConfigRepository $configRepository
) {
$this->helperData = $helperData;
$this->configRepository = $configRepository;
}

/**
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!$this->helperData->isEnabled()) {
throw new GraphQlInputException(__('Reward points is disabled.'));
}

$store = $context->getExtensionAttributes()->getStore();
$storeId = $store->getId();
$storeConfigs = $this->configRepository->getStoreConfigs($storeId);
$storeConfigs['earning']['earn_from_tax'] = $storeConfigs['earning']['earn_from'];

return $storeConfigs;
}
}
44 changes: 3 additions & 41 deletions Model/Resolver/Configs/GetIconUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@

namespace Mageplaza\RewardPointsGraphQl\Model\Resolver\Configs;

use Magento\Framework\App\Area;
use Magento\Framework\App\RequestInterface;
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\Framework\View\Asset\Repository as AssetRepository;
use Mageplaza\Core\Helper\Media;
use Mageplaza\RewardPoints\Helper\Data;

/**
Expand All @@ -44,39 +40,15 @@ class GetIconUrl implements ResolverInterface
*/
protected $helperData;

/**
* @var AssetRepository
*/
protected $assetRepo;

/**
* @var RequestInterface
*/
protected $request;

/**
* @var Media
*/
protected $mediaHelper;

/**
* GetIconUrl constructor.
*
* @param Data $helperData
* @param AssetRepository $assetRepo
* @param RequestInterface $request
* @param Media $media
*/
public function __construct(
Data $helperData,
AssetRepository $assetRepo,
RequestInterface $request,
Media $media
){
Data $helperData
) {
$this->helperData = $helperData;
$this->assetRepo = $assetRepo;
$this->request = $request;
$this->mediaHelper = $media;
}

/**
Expand All @@ -95,18 +67,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
return '';
}

$icon = $this->helperData->getConfigGeneral('icon', $storeId);
if ($icon && $this->mediaHelper->getMediaDirectory()->isExist('mageplaza/rewardpoints/' . $icon)) {
$iconUrl = $this->mediaHelper->getMediaUrl('mageplaza/rewardpoints/' . $icon);
} else {
$iconUrl = $this->assetRepo->getUrlWithParams(
'Mageplaza_RewardPoints::images/default/point.png',
['_secure' => $this->request->isSecure(), 'area' => Area::AREA_FRONTEND]
);
}

return [
'url' => $iconUrl
'url' => $this->helperData->getPointHelper()->getIconUrl($storeId)
];
}
}
49 changes: 33 additions & 16 deletions Model/Resolver/Customer/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@

namespace Mageplaza\RewardPointsGraphQl\Model\Resolver\Customer;

use Exception;
use Magento\Customer\Model\Customer;
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
use Magento\Framework\DataObject;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Mageplaza\RewardPointsUltimate\Helper\Data;
use Mageplaza\RewardPointsUltimate\Model\InvitationRepository;
use Mageplaza\RewardPoints\Helper\Data;
use Mageplaza\RewardPointsGraphQl\Model\Resolver\AbstractReward;

/**
Expand All @@ -37,29 +40,31 @@
*/
class Invite extends AbstractReward
{
/**
* @var InvitationRepository
*/
protected $invitationRepository;

/**
* @var GetCustomer
*/
protected $getCustomer;

/**
* @var EventManager
*/
protected $eventManager;

/**
* Invite constructor.
* @param InvitationRepository $invitationRepository
*
* @param GetCustomer $getCustomer
* @param Data $helperData
* @param EventManager $eventManager
*/
public function __construct(
InvitationRepository $invitationRepository,
GetCustomer $getCustomer,
Data $helperData
Data $helperData,
EventManager $eventManager
) {
$this->invitationRepository = $invitationRepository;
$this->getCustomer = $getCustomer;
$this->eventManager = $eventManager;

parent::__construct($helperData);
}
Expand All @@ -69,6 +74,10 @@ public function __construct(
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!$this->helperData->isModuleOutputEnabled('Mageplaza_RewardPointsUltimate')) {
throw new GraphQlInputException(__('Reward Points Ultimate extension is required.'));
}

parent::resolve($field, $context, $info, $value, $args);

/** @var Customer $customer */
Expand All @@ -77,11 +86,19 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
*/
$customer = $this->getCustomer->execute($context);

return $this->invitationRepository->sendInvitation(
$customer,
$args['send_from'],
$args['emails'],
$args['message']
);
$inviteObject = new DataObject(['status' => false]);

try {
$this->eventManager->dispatch('mp_reward_graphql_invite', [
'customer' => $customer,
'object' => $inviteObject,
'params' => $args
]
);
} catch (Exception $exception) {
throw new GraphQlInputException(__($exception->getMessage()));
}

return $inviteObject->getStatus();
}
}
Loading

0 comments on commit f226fd2

Please sign in to comment.