Skip to content

Commit 8f1b315

Browse files
author
Jacker
committed
Merge branch 'develop'
2 parents db51637 + 0779d72 commit 8f1b315

File tree

9 files changed

+485
-27
lines changed

9 files changed

+485
-27
lines changed

Model/Resolver/AbstractGetList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ abstract class AbstractGetList implements ResolverInterface
4949

5050
/**
5151
* AbstractGetList constructor.
52+
*
5253
* @param SearchCriteriaBuilder $searchCriteriaBuilder
5354
*/
5455
public function __construct(
@@ -100,7 +101,7 @@ abstract protected function getSearchResult($customer, $searchCriteria);
100101
* @return array
101102
* @throws GraphQlInputException
102103
*/
103-
private function getPageInfo($searchResult, $args)
104+
protected function getPageInfo($searchResult, $args)
104105
{
105106
$totalPages = ceil($searchResult->getTotalCount() / $args['pageSize']);
106107
$currentPage = $args['currentPage'];

Model/Resolver/Orders/MpReward.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_RewardPointsGraphQl
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Mageplaza\RewardPointsGraphQl\Model\Resolver\Orders;
25+
26+
use Exception;
27+
use Magento\Framework\Exception\LocalizedException;
28+
use Magento\Framework\GraphQl\Config\Element\Field;
29+
use Magento\Framework\GraphQl\Query\ResolverInterface;
30+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
31+
use Magento\Sales\Model\Order;
32+
use Magento\Sales\Model\OrderFactory;
33+
use Mageplaza\RewardPoints\Helper\Data;
34+
35+
/**
36+
* Class MpReward
37+
* @package Mageplaza\RewardPointsGraphQl\Model\Resolver\Orders
38+
*/
39+
class MpReward implements ResolverInterface
40+
{
41+
/**
42+
* @var Data
43+
*/
44+
protected $helperData;
45+
46+
/**
47+
* @var OrderFactory
48+
*/
49+
protected $orderFactory;
50+
51+
/**
52+
* MpReward constructor.
53+
*
54+
* @param Data $helperData
55+
* @param OrderFactory $orderFactory
56+
*/
57+
public function __construct(
58+
Data $helperData,
59+
OrderFactory $orderFactory
60+
) {
61+
$this->helperData = $helperData;
62+
$this->orderFactory = $orderFactory;
63+
}
64+
65+
/**
66+
* @inheritDoc
67+
*/
68+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
69+
{
70+
if (!$this->helperData->isEnabled()) {
71+
return null;
72+
}
73+
74+
try {
75+
if (isset($value['increment_id'])) {
76+
$order = $this->orderFactory->create()->loadByIncrementId($value['increment_id']);
77+
78+
return [
79+
'earn' => $order->getData('mp_reward_earn'),
80+
'spent' => $order->getData('mp_reward_spent'),
81+
'discount' => abs($order->getData('mp_reward_discount'))
82+
];
83+
}
84+
85+
return null;
86+
} catch (Exception $e) {
87+
return null;
88+
}
89+
}
90+
}

Model/Resolver/RewardCustomer/Account.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Magento\Framework\GraphQl\Query\ResolverInterface;
3030
use Mageplaza\RewardPoints\Helper\Data;
3131
use Mageplaza\RewardPoints\Model\AccountFactory as RewardCustomerFactory;
32+
use Magento\Framework\Encryption\EncryptorInterface;
3233

3334
/**
3435
* Class Account
@@ -46,17 +47,26 @@ class Account implements ResolverInterface
4647
*/
4748
protected $helperData;
4849

50+
/**
51+
* @var EncryptorInterface
52+
*/
53+
protected $encryptor;
54+
4955
/**
5056
* Account constructor.
57+
*
5158
* @param RewardCustomerFactory $rewardCustomerFactory
5259
* @param Data $helperData
60+
* @param EncryptorInterface $encryptor
5361
*/
5462
public function __construct(
5563
RewardCustomerFactory $rewardCustomerFactory,
56-
Data $helperData
64+
Data $helperData,
65+
EncryptorInterface $encryptor
5766
) {
5867
$this->helperData = $helperData;
5968
$this->rewardCustomerFactory = $rewardCustomerFactory;
69+
$this->encryptor = $encryptor;
6070
}
6171

6272
/**
@@ -84,6 +94,7 @@ public function resolve(
8494
$data = $rewardCustomer->toArray();
8595
$data['point_spent'] = $rewardCustomer->getPointSpent();
8696
$data['point_earned'] = $rewardCustomer->getPointEarned();
97+
$data['refer_code'] = $this->encrypt($customer->getId());
8798

8899
$pointHelper = $this->helperData->getPointHelper();
89100
if ($this->helperData->getMaxPointPerCustomer()) {
@@ -105,4 +116,14 @@ public function resolve(
105116

106117
return $data;
107118
}
119+
120+
/**
121+
* @param string|int $data
122+
*
123+
* @return string
124+
*/
125+
public function encrypt($data)
126+
{
127+
return base64_encode($this->encryptor->encrypt((string) $data));
128+
}
108129
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_RewardPointsGraphQl
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Mageplaza\RewardPointsGraphQl\Model\Resolver\RewardCustomer;
25+
26+
use Exception;
27+
use Magento\Framework\Api\Search\SearchCriteriaInterface;
28+
use Magento\Framework\Exception\LocalizedException;
29+
use Magento\Framework\GraphQl\Config\Element\Field;
30+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
31+
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder;
32+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
33+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
34+
use Magento\Sales\Model\Order;
35+
use Mageplaza\RewardPointsGraphQl\Model\Resolver\AbstractGetList;
36+
use Mageplaza\RewardPoints\Model\TransactionRepository;
37+
38+
/**
39+
* Class TransactionsByOrder
40+
* @package Mageplaza\RewardPointsGraphQl\Model\Resolver\RewardCustomer
41+
*/
42+
class TransactionsByOrder extends AbstractGetList
43+
{
44+
/**
45+
* @var string
46+
*/
47+
protected $fieldName = 'mp_reward_transactions';
48+
49+
/**
50+
* @var TransactionRepository
51+
*/
52+
protected $transactionRepository;
53+
54+
/**
55+
* @var Order
56+
*/
57+
protected $order;
58+
59+
/**
60+
* TransactionsByOrder constructor.
61+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
62+
* @param TransactionRepository $transactionRepository
63+
* @param Order $order
64+
*/
65+
public function __construct(
66+
SearchCriteriaBuilder $searchCriteriaBuilder,
67+
TransactionRepository $transactionRepository,
68+
Order $order
69+
) {
70+
$this->transactionRepository = $transactionRepository;
71+
$this->order = $order;
72+
73+
parent::__construct($searchCriteriaBuilder);
74+
}
75+
76+
/**
77+
* @param Field $field
78+
* @param ContextInterface $context
79+
* @param ResolveInfo $info
80+
* @param array|null $value
81+
* @param array|null $args
82+
* @return array
83+
*/
84+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
85+
{
86+
try {
87+
/** @var Order $order */
88+
$order = isset($value['model']) ? $value['model'] : null;
89+
if (!$order) {
90+
$order = $this->order->loadByIncrementId($value['increment_id']);
91+
}
92+
93+
if (isset($args['currentPage']) && $args['currentPage'] < 1) {
94+
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
95+
}
96+
97+
if (isset($args['pageSize']) && $args['pageSize'] < 1) {
98+
throw new GraphQlInputException(__('pageSize value must be greater than 0.'));
99+
}
100+
101+
$searchCriteria = $this->searchCriteriaBuilder->build($this->fieldName, $args);
102+
$searchCriteria->setCurrentPage($args['currentPage']);
103+
$searchCriteria->setPageSize($args['pageSize']);
104+
$searchResult = $this->getSearchResult($order->getId(), $searchCriteria);
105+
106+
return [
107+
'total_count' => $searchResult->getTotalCount(),
108+
'items' => $searchResult->getItems(),
109+
'page_info' => $this->getPageInfo($searchResult, $args)
110+
];
111+
} catch (Exception $e) {
112+
return [];
113+
}
114+
}
115+
116+
/**
117+
* @param int $orderId
118+
* @param SearchCriteriaInterface $searchCriteria
119+
*
120+
* @return mixed
121+
* @throws LocalizedException
122+
*/
123+
public function getSearchResult($orderId, $searchCriteria)
124+
{
125+
$result = $this->transactionRepository->getListByOrderId($searchCriteria, $orderId);
126+
foreach ($result->getItems() as $item) {
127+
$item->setComment($item->getTitle());
128+
}
129+
130+
return $result;
131+
}
132+
}

0 commit comments

Comments
 (0)