From 07ac55bb55773dc3f4602a6060ab38706f1a5537 Mon Sep 17 00:00:00 2001 From: datvm Date: Wed, 11 Dec 2019 17:54:00 +0700 Subject: [PATCH 01/12] create module --- Model/Resolver/AbstractResolver.php | 119 ++++++++++++ Model/Resolver/Filter/Query/Filter.php | 122 ++++++++++++ Model/Resolver/Filter/SearchResult.php | 71 +++++++ Model/Resolver/Filter/SearchResultFactory.php | 60 ++++++ Model/Resolver/FilterArgument.php | 67 +++++++ Model/Resolver/GiftCodes.php | 32 +++ Model/Resolver/GiftPools.php | 32 +++ Model/Resolver/GiftTemplates.php | 32 +++ etc/di.xml | 33 ++++ etc/module.xml | 30 +++ etc/schema.graphqls | 183 ++++++++++++++++++ registration.php | 28 +++ 12 files changed, 809 insertions(+) create mode 100644 Model/Resolver/AbstractResolver.php create mode 100644 Model/Resolver/Filter/Query/Filter.php create mode 100644 Model/Resolver/Filter/SearchResult.php create mode 100644 Model/Resolver/Filter/SearchResultFactory.php create mode 100644 Model/Resolver/FilterArgument.php create mode 100644 Model/Resolver/GiftCodes.php create mode 100644 Model/Resolver/GiftPools.php create mode 100644 Model/Resolver/GiftTemplates.php create mode 100644 etc/di.xml create mode 100644 etc/module.xml create mode 100644 etc/schema.graphqls create mode 100644 registration.php diff --git a/Model/Resolver/AbstractResolver.php b/Model/Resolver/AbstractResolver.php new file mode 100644 index 0000000..15e01da --- /dev/null +++ b/Model/Resolver/AbstractResolver.php @@ -0,0 +1,119 @@ +filter = $filter; + } + + /** + * {@inheritDoc} + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $this->validateArgs($args); + + $searchResult = $this->filter->getResult($args, $this->_type); + + return [ + 'total_count' => $searchResult->getTotalCount(), + 'items' => $searchResult->getItems(), + 'page_info' => $this->getPageInfo($searchResult, $args) + ]; + } + + /** + * @param array $args + * + * @throws GraphQlInputException + */ + protected function validateArgs(array $args) + { + if ($args['currentPage'] < 1) { + throw new GraphQlInputException(__('currentPage value must be greater than 0.')); + } + + if ($args['pageSize'] < 1) { + throw new GraphQlInputException(__('pageSize value must be greater than 0.')); + } + + if (!isset($args['filter'])) { + throw new GraphQlInputException(__("'filter' input argument is required.")); + } + } + + /** + * @param SearchResult $searchResult + * @param array $args + * + * @return array + * @throws GraphQlInputException + */ + protected function getPageInfo($searchResult, $args) + { + $totalPages = ceil($searchResult->getTotalCount() / $args['pageSize']); + $currentPage = $args['currentPage']; + + if ($currentPage > $totalPages && $searchResult->getTotalCount() > 0) { + throw new GraphQlInputException(__( + 'currentPage value %1 specified is greater than the %2 page(s) available.', + [$currentPage, $totalPages] + )); + } + + return [ + 'pageSize' => $args['pageSize'], + 'currentPage' => $currentPage, + 'hasNextPage' => $currentPage < $totalPages, + 'hasPreviousPage' => $currentPage > 1, + 'startPage' => 1, + 'endPage' => $totalPages, + ]; + } +} diff --git a/Model/Resolver/Filter/Query/Filter.php b/Model/Resolver/Filter/Query/Filter.php new file mode 100644 index 0000000..dff6779 --- /dev/null +++ b/Model/Resolver/Filter/Query/Filter.php @@ -0,0 +1,122 @@ +searchCriteriaBuilder = $searchCriteriaBuilder; + $this->searchResultFactory = $searchResultFactory; + $this->giftCodeManagement = $giftCodeManagement; + $this->giftPoolManagement = $giftPoolManagement; + $this->giftTemplateManagement = $giftTemplateManagement; + } + + /** + * @param array $args + * @param string $type + * + * @return SearchResult + */ + public function getResult($args, $type): SearchResult + { + $searchCriteria = $this->searchCriteriaBuilder->build($type, $args); + $searchCriteria->setCurrentPage($args['currentPage']); + $searchCriteria->setPageSize($args['pageSize']); + + switch ($type) { + case 'mpGiftCode': + $list = $this->giftCodeManagement->getList($searchCriteria); + break; + case 'mpGiftPool': + $list = $this->giftPoolManagement->getList($searchCriteria); + break; + case 'mpGiftTemplate': + default: + $list = $this->giftTemplateManagement->getList($searchCriteria); + break; + } + + $listArray = []; + /** @var GiftCardModel|PoolModel|TemplateModel $item */ + foreach ($list->getItems() as $item) { + $listArray[$item->getId()] = $item->getData(); + $listArray[$item->getId()]['model'] = $item; + } + + return $this->searchResultFactory->create($list->getTotalCount(), $listArray); + } +} diff --git a/Model/Resolver/Filter/SearchResult.php b/Model/Resolver/Filter/SearchResult.php new file mode 100644 index 0000000..e5d6010 --- /dev/null +++ b/Model/Resolver/Filter/SearchResult.php @@ -0,0 +1,71 @@ +totalCount = $totalCount; + $this->itemsSearchResult = $itemsSearchResult; + } + + /** + * Return total count of search and filtered result + * + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * Retrieve an array in the format of GraphQL-readable type containing product data. + * + * @return array + */ + public function getItems(): array + { + return $this->itemsSearchResult; + } +} diff --git a/Model/Resolver/Filter/SearchResultFactory.php b/Model/Resolver/Filter/SearchResultFactory.php new file mode 100644 index 0000000..239ee5a --- /dev/null +++ b/Model/Resolver/Filter/SearchResultFactory.php @@ -0,0 +1,60 @@ +objectManager = $objectManager; + } + + /** + * @param int $totalCount + * @param array $itemsSearchResult + * + * @return SearchResult + */ + public function create(int $totalCount, array $itemsSearchResult): SearchResult + { + return $this->objectManager->create( + SearchResult::class, + compact('totalCount', 'itemsSearchResult') + ); + } +} diff --git a/Model/Resolver/FilterArgument.php b/Model/Resolver/FilterArgument.php new file mode 100644 index 0000000..dd54984 --- /dev/null +++ b/Model/Resolver/FilterArgument.php @@ -0,0 +1,67 @@ +config = $config; + } + + /** + * {@inheritDoc} + */ + public function getEntityAttributes(): array + { + $fields = []; + + $elements = ['GiftCodeDetails', 'GiftPoolDetails', 'GiftTemplateDetails']; + foreach ($elements as $element) { + /** @var Field $field */ + foreach ($this->config->getConfigElement($element)->getFields() as $field) { + $fields[$field->getName()] = ''; + } + } + + return array_keys($fields); + } +} diff --git a/Model/Resolver/GiftCodes.php b/Model/Resolver/GiftCodes.php new file mode 100644 index 0000000..1986312 --- /dev/null +++ b/Model/Resolver/GiftCodes.php @@ -0,0 +1,32 @@ + + + + + + + Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument + Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument + Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument + + + + \ No newline at end of file diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..87a4b57 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/etc/schema.graphqls b/etc/schema.graphqls new file mode 100644 index 0000000..d60f300 --- /dev/null +++ b/etc/schema.graphqls @@ -0,0 +1,183 @@ +# 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 + +type Query { + mpGiftCardCode ( + filter: GiftCodeFilterInput @doc(description: "Identifies which fields to search for and return."), + pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") + ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCodes") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") + mpGiftCardPool ( + filter: GiftPoolFilterInput @doc(description: "Identifies which fields to search for and return."), + pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") + ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPools") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") + mpGiftCardTemplate ( + filter: GiftTemplateFilterInput @doc(description: "Identifies which fields to search for and return."), + pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") + ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftTemplates") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") +} + +input GiftCodeFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + giftcard_id: FilterTypeInput + code: FilterTypeInput + pattern: FilterTypeInput + init_balance: FilterTypeInput + balance: FilterTypeInput + status: FilterTypeInput + can_redeem: FilterTypeInput + store_id: FilterTypeInput + pool_id: FilterTypeInput + template_id: FilterTypeInput + image: FilterTypeInput + template_fields: FilterTypeInput + customer_ids: FilterTypeInput + order_item_id: FilterTypeInput + order_increment_id: FilterTypeInput + delivery_method: FilterTypeInput + delivery_address: FilterTypeInput + is_sent: FilterTypeInput + delivery_date: FilterTypeInput + timezone: FilterTypeInput + extra_content: FilterTypeInput + expired_at: FilterTypeInput + created_at: FilterTypeInput +} + +input GiftPoolFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + pool_id: FilterTypeInput + name: FilterTypeInput + status: FilterTypeInput + can_inherit: FilterTypeInput + pattern: FilterTypeInput + balance: FilterTypeInput + can_redeem: FilterTypeInput + store_id: FilterTypeInput + template_id: FilterTypeInput + image: FilterTypeInput + template_fields: FilterTypeInput + expired_at: FilterTypeInput + created_at: FilterTypeInput +} + +input GiftTemplateFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + template_id: FilterTypeInput + name: FilterTypeInput + status: FilterTypeInput + can_upload: FilterTypeInput + title: FilterTypeInput + font_family: FilterTypeInput + background_image: FilterTypeInput + design: FilterTypeInput + note: FilterTypeInput + images: FilterTypeInput + created_at: FilterTypeInput +} + +type GiftCodeOutput @doc(description:"Comment ...") { + total_count: Int @doc(description: "The number of items returned.") + items: [GiftCodeDetails] @doc(description: "An array of items that match the specified search criteria.") + page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") +} + +type GiftPoolOutput @doc(description:"Comment ...") { + total_count: Int @doc(description: "The number of items returned.") + items: [GiftPoolDetails] @doc(description: "An array of items that match the specified search criteria.") + page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") +} + +type GiftTemplateOutput @doc(description:"Comment ...") { + total_count: Int @doc(description: "The number of items returned.") + items: [GiftTemplateDetails] @doc(description: "An array of items that match the specified search criteria.") + page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") +} + +type GiftCodeDetails @doc(description: "Comment ...") +{ + giftcard_id: Int + code: String + pattern: String + init_balance: Float + balance: Float + status: String + can_redeem: String + store_id: String + pool_id: String + template_id: String + image: String + template_fields: GiftCardTemplateFields + customer_ids: String + order_item_id: String + order_increment_id: String + delivery_method: String + delivery_address: String + is_sent: String + delivery_date: String + timezone: String + extra_content: String + expired_at: String + created_at: String +} + +type GiftPoolDetails @doc(description: "Comment ...") +{ + pool_id: Int + name: String + status: String + can_inherit: String + pattern: String + balance: Float + can_redeem: String + store_id: String + template_id: String + image: String + template_fields: GiftCardTemplateFields + expired_at: String + created_at: String +} + +type GiftTemplateDetails @doc(description: "Comment ...") +{ + template_id: Int + name: String + status: String + can_upload: String + title: String + font_family: String + background_image: String + design: String + note: String + images: String + created_at: String +} + +type GiftCardTemplateFields @doc(description: "Comment ...") { + sender: String + recipient: String + message: String +} + +type PageInfo { + pageSize: Int @doc(description: "How many items should show on the page.") + currentPage: Int @doc(description: "Specifies which page of results to return.") + hasNextPage: Boolean @doc(description: "Has next page.") + hasPreviousPage: Boolean @doc(description: "Has previous page.") + startPage: Int @doc(description: "Start page.") + endPage: Int @doc(description: "End page.") +} \ No newline at end of file diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..8412836 --- /dev/null +++ b/registration.php @@ -0,0 +1,28 @@ + Date: Thu, 12 Dec 2019 16:39:56 +0700 Subject: [PATCH 02/12] [wip] update queries & mutations --- Model/Resolver/AbstractResolver.php | 62 +------- Model/Resolver/Delete/AbstractResolver.php | 48 +++++++ Model/Resolver/Delete/GiftCode.php | 32 +++++ Model/Resolver/Delete/GiftPool.php | 32 +++++ Model/Resolver/Delete/GiftTemplate.php | 32 +++++ Model/Resolver/Filter/Query/Filter.php | 100 ++++++++++++- Model/Resolver/FilterArgument.php | 2 +- Model/Resolver/Get/AbstractResolver.php | 51 +++++++ .../{GiftCodes.php => Get/GiftCode.php} | 8 +- .../{GiftPools.php => Get/GiftPool.php} | 8 +- .../GiftTemplate.php} | 8 +- Model/Resolver/GetList/AbstractResolver.php | 87 ++++++++++++ Model/Resolver/GetList/GiftCode.php | 32 +++++ Model/Resolver/GetList/GiftPool.php | 32 +++++ Model/Resolver/GetList/GiftTemplate.php | 32 +++++ Model/Resolver/GiftCard/AbstractResolver.php | 65 +++++++++ Model/Resolver/GiftCard/Redeem.php | 49 +++++++ Model/Resolver/GiftCard/RemoveGiftCode.php | 51 +++++++ Model/Resolver/GiftCard/SetGiftCode.php | 51 +++++++ Model/Resolver/GiftCard/SetGiftCredit.php | 51 +++++++ Model/Resolver/GiftPoolGenerate.php | 58 ++++++++ Model/Resolver/Save/AbstractResolver.php | 51 +++++++ Model/Resolver/Save/GiftCode.php | 32 +++++ Model/Resolver/Save/GiftPool.php | 32 +++++ Model/Resolver/Save/GiftTemplate.php | 32 +++++ etc/schema.graphqls | 134 +++++++++++++++--- 26 files changed, 1080 insertions(+), 92 deletions(-) create mode 100644 Model/Resolver/Delete/AbstractResolver.php create mode 100644 Model/Resolver/Delete/GiftCode.php create mode 100644 Model/Resolver/Delete/GiftPool.php create mode 100644 Model/Resolver/Delete/GiftTemplate.php create mode 100644 Model/Resolver/Get/AbstractResolver.php rename Model/Resolver/{GiftCodes.php => Get/GiftCode.php} (78%) rename Model/Resolver/{GiftPools.php => Get/GiftPool.php} (78%) rename Model/Resolver/{GiftTemplates.php => Get/GiftTemplate.php} (77%) create mode 100644 Model/Resolver/GetList/AbstractResolver.php create mode 100644 Model/Resolver/GetList/GiftCode.php create mode 100644 Model/Resolver/GetList/GiftPool.php create mode 100644 Model/Resolver/GetList/GiftTemplate.php create mode 100644 Model/Resolver/GiftCard/AbstractResolver.php create mode 100644 Model/Resolver/GiftCard/Redeem.php create mode 100644 Model/Resolver/GiftCard/RemoveGiftCode.php create mode 100644 Model/Resolver/GiftCard/SetGiftCode.php create mode 100644 Model/Resolver/GiftCard/SetGiftCredit.php create mode 100644 Model/Resolver/GiftPoolGenerate.php create mode 100644 Model/Resolver/Save/AbstractResolver.php create mode 100644 Model/Resolver/Save/GiftCode.php create mode 100644 Model/Resolver/Save/GiftPool.php create mode 100644 Model/Resolver/Save/GiftTemplate.php diff --git a/Model/Resolver/AbstractResolver.php b/Model/Resolver/AbstractResolver.php index 15e01da..d1c4b37 100644 --- a/Model/Resolver/AbstractResolver.php +++ b/Model/Resolver/AbstractResolver.php @@ -23,24 +23,22 @@ 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 Mageplaza\GiftCardGraphQl\Model\Resolver\Filter\Query\Filter; -use Mageplaza\GiftCardGraphQl\Model\Resolver\Filter\SearchResult; /** * Class AbstractResolver * @package Mageplaza\GiftCardGraphQl\Model\Resolver */ -class AbstractResolver implements ResolverInterface +abstract class AbstractResolver implements ResolverInterface { protected $_type = ''; /** * @var Filter */ - private $filter; + protected $filter; /** * AbstractResolver constructor. @@ -57,63 +55,13 @@ public function __construct(Filter $filter) */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - $this->validateArgs($args); - - $searchResult = $this->filter->getResult($args, $this->_type); - - return [ - 'total_count' => $searchResult->getTotalCount(), - 'items' => $searchResult->getItems(), - 'page_info' => $this->getPageInfo($searchResult, $args) - ]; + return $this->handleArgs($args); } /** * @param array $args * - * @throws GraphQlInputException + * @return mixed */ - protected function validateArgs(array $args) - { - if ($args['currentPage'] < 1) { - throw new GraphQlInputException(__('currentPage value must be greater than 0.')); - } - - if ($args['pageSize'] < 1) { - throw new GraphQlInputException(__('pageSize value must be greater than 0.')); - } - - if (!isset($args['filter'])) { - throw new GraphQlInputException(__("'filter' input argument is required.")); - } - } - - /** - * @param SearchResult $searchResult - * @param array $args - * - * @return array - * @throws GraphQlInputException - */ - protected function getPageInfo($searchResult, $args) - { - $totalPages = ceil($searchResult->getTotalCount() / $args['pageSize']); - $currentPage = $args['currentPage']; - - if ($currentPage > $totalPages && $searchResult->getTotalCount() > 0) { - throw new GraphQlInputException(__( - 'currentPage value %1 specified is greater than the %2 page(s) available.', - [$currentPage, $totalPages] - )); - } - - return [ - 'pageSize' => $args['pageSize'], - 'currentPage' => $currentPage, - 'hasNextPage' => $currentPage < $totalPages, - 'hasPreviousPage' => $currentPage > 1, - 'startPage' => 1, - 'endPage' => $totalPages, - ]; - } + abstract protected function handleArgs(array $args); } diff --git a/Model/Resolver/Delete/AbstractResolver.php b/Model/Resolver/Delete/AbstractResolver.php new file mode 100644 index 0000000..d692956 --- /dev/null +++ b/Model/Resolver/Delete/AbstractResolver.php @@ -0,0 +1,48 @@ +filter->deleteEntity($args['id'], $this->_type); + } catch (NoSuchEntityException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/Delete/GiftCode.php b/Model/Resolver/Delete/GiftCode.php new file mode 100644 index 0000000..bacf751 --- /dev/null +++ b/Model/Resolver/Delete/GiftCode.php @@ -0,0 +1,32 @@ +searchCriteriaBuilder = $searchCriteriaBuilder; $this->searchResultFactory = $searchResultFactory; $this->giftCodeManagement = $giftCodeManagement; $this->giftPoolManagement = $giftPoolManagement; $this->giftTemplateManagement = $giftTemplateManagement; + $this->giftCardFactory = $giftCardFactory; + $this->poolFactory = $poolFactory; + $this->templateFactory = $templateFactory; } /** @@ -119,4 +151,70 @@ public function getResult($args, $type): SearchResult return $this->searchResultFactory->create($list->getTotalCount(), $listArray); } + + /** + * @param string $id + * @param string $type + * + * @return GiftCodeInterface|GiftPoolInterface|GiftTemplateInterface + * @throws NoSuchEntityException + */ + public function getResultById($id, $type) + { + switch ($type) { + case 'mpGiftCode': + return $this->giftCodeManagement->get($id); + case 'mpGiftPool': + return $this->giftPoolManagement->get($id); + case 'mpGiftTemplate': + default: + return $this->giftTemplateManagement->get($id); + } + } + + /** + * @param array $data + * @param string $type + * + * @return GiftCodeInterface|GiftPoolInterface|GiftTemplateInterface + * @throws Exception + */ + public function saveEntity($data, $type) + { + switch ($type) { + case 'mpGiftCode': + $entity = $this->giftCardFactory->create()->setData($data); + + return $this->giftCodeManagement->save($entity); + case 'mpGiftPool': + $entity = $this->poolFactory->create()->setData($data); + + return $this->giftPoolManagement->save($entity); + case 'mpGiftTemplate': + default: + $entity = $this->templateFactory->create()->setData($data); + + return $this->giftTemplateManagement->save($entity); + } + } + + /** + * @param string $id + * @param string $type + * + * @return bool + * @throws NoSuchEntityException + */ + public function deleteEntity($id, $type) + { + switch ($type) { + case 'mpGiftCode': + return $this->giftCodeManagement->delete($id); + case 'mpGiftPool': + return $this->giftPoolManagement->delete($id); + case 'mpGiftTemplate': + default: + return $this->giftTemplateManagement->delete($id); + } + } } diff --git a/Model/Resolver/FilterArgument.php b/Model/Resolver/FilterArgument.php index dd54984..7ab49ef 100644 --- a/Model/Resolver/FilterArgument.php +++ b/Model/Resolver/FilterArgument.php @@ -54,7 +54,7 @@ public function getEntityAttributes(): array { $fields = []; - $elements = ['GiftCodeDetails', 'GiftPoolDetails', 'GiftTemplateDetails']; + $elements = ['GiftCodeOutput', 'GiftPoolOutput', 'GiftTemplateOutput']; foreach ($elements as $element) { /** @var Field $field */ foreach ($this->config->getConfigElement($element)->getFields() as $field) { diff --git a/Model/Resolver/Get/AbstractResolver.php b/Model/Resolver/Get/AbstractResolver.php new file mode 100644 index 0000000..fb183c3 --- /dev/null +++ b/Model/Resolver/Get/AbstractResolver.php @@ -0,0 +1,51 @@ +filter->getResultById($args['id'], $this->_type); + } catch (NoSuchEntityException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/GiftCodes.php b/Model/Resolver/Get/GiftCode.php similarity index 78% rename from Model/Resolver/GiftCodes.php rename to Model/Resolver/Get/GiftCode.php index 1986312..027aca1 100644 --- a/Model/Resolver/GiftCodes.php +++ b/Model/Resolver/Get/GiftCode.php @@ -20,13 +20,13 @@ */ declare(strict_types=1); -namespace Mageplaza\GiftCardGraphQl\Model\Resolver; +namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; /** - * Class GiftCodes - * @package Mageplaza\GiftCardGraphQl\Model\Resolver + * Class GiftCode + * @package Mageplaza\GiftCardGraphQl\Model\Resolver\Get */ -class GiftCodes extends AbstractResolver +class GiftCode extends AbstractResolver { protected $_type = 'mpGiftCode'; } diff --git a/Model/Resolver/GiftPools.php b/Model/Resolver/Get/GiftPool.php similarity index 78% rename from Model/Resolver/GiftPools.php rename to Model/Resolver/Get/GiftPool.php index 2cf0a2c..d2e1ecf 100644 --- a/Model/Resolver/GiftPools.php +++ b/Model/Resolver/Get/GiftPool.php @@ -20,13 +20,13 @@ */ declare(strict_types=1); -namespace Mageplaza\GiftCardGraphQl\Model\Resolver; +namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; /** - * Class GiftPools - * @package Mageplaza\GiftCardGraphQl\Model\Resolver + * Class GiftPool + * @package Mageplaza\GiftCardGraphQl\Model\Resolver\Get */ -class GiftPools extends AbstractResolver +class GiftPool extends AbstractResolver { protected $_type = 'mpGiftPool'; } diff --git a/Model/Resolver/GiftTemplates.php b/Model/Resolver/Get/GiftTemplate.php similarity index 77% rename from Model/Resolver/GiftTemplates.php rename to Model/Resolver/Get/GiftTemplate.php index 9a71dc2..99f6333 100644 --- a/Model/Resolver/GiftTemplates.php +++ b/Model/Resolver/Get/GiftTemplate.php @@ -20,13 +20,13 @@ */ declare(strict_types=1); -namespace Mageplaza\GiftCardGraphQl\Model\Resolver; +namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; /** - * Class GiftTemplates - * @package Mageplaza\GiftCardGraphQl\Model\Resolver + * Class GiftTemplate + * @package Mageplaza\GiftCardGraphQl\Model\Resolver\Get */ -class GiftTemplates extends AbstractResolver +class GiftTemplate extends AbstractResolver { protected $_type = 'mpGiftTemplate'; } diff --git a/Model/Resolver/GetList/AbstractResolver.php b/Model/Resolver/GetList/AbstractResolver.php new file mode 100644 index 0000000..a2c1824 --- /dev/null +++ b/Model/Resolver/GetList/AbstractResolver.php @@ -0,0 +1,87 @@ +filter->getResult($args, $this->_type); + + return [ + 'total_count' => $searchResult->getTotalCount(), + 'items' => $searchResult->getItems(), + 'page_info' => $this->getPageInfo($searchResult, $args) + ]; + } + + /** + * @param SearchResult $searchResult + * @param array $args + * + * @return array + * @throws GraphQlInputException + */ + private function getPageInfo($searchResult, $args) + { + $totalPages = ceil($searchResult->getTotalCount() / $args['pageSize']); + $currentPage = $args['currentPage']; + + if ($currentPage > $totalPages && $searchResult->getTotalCount() > 0) { + throw new GraphQlInputException(__( + 'currentPage value %1 specified is greater than the %2 page(s) available.', + [$currentPage, $totalPages] + )); + } + + return [ + 'pageSize' => $args['pageSize'], + 'currentPage' => $currentPage, + 'hasNextPage' => $currentPage < $totalPages, + 'hasPreviousPage' => $currentPage > 1, + 'startPage' => 1, + 'endPage' => $totalPages, + ]; + } +} diff --git a/Model/Resolver/GetList/GiftCode.php b/Model/Resolver/GetList/GiftCode.php new file mode 100644 index 0000000..092e4b0 --- /dev/null +++ b/Model/Resolver/GetList/GiftCode.php @@ -0,0 +1,32 @@ +giftCardManagement = $giftCardManagement; + } + + /** + * {@inheritDoc} + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + return $this->handleArgs($args); + } + + /** + * @param array $args + * + * @return mixed + */ + abstract protected function handleArgs(array $args); +} diff --git a/Model/Resolver/GiftCard/Redeem.php b/Model/Resolver/GiftCard/Redeem.php new file mode 100644 index 0000000..c7904f3 --- /dev/null +++ b/Model/Resolver/GiftCard/Redeem.php @@ -0,0 +1,49 @@ +giftCardManagement->redeem($args['customer_id'], $args['code']); + } catch (Exception $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/GiftCard/RemoveGiftCode.php b/Model/Resolver/GiftCard/RemoveGiftCode.php new file mode 100644 index 0000000..fc4004a --- /dev/null +++ b/Model/Resolver/GiftCard/RemoveGiftCode.php @@ -0,0 +1,51 @@ +giftCardManagement->remove($args['cart_id'], $args['code']); + } catch (CouldNotDeleteException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } catch (NoSuchEntityException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/GiftCard/SetGiftCode.php b/Model/Resolver/GiftCard/SetGiftCode.php new file mode 100644 index 0000000..9078d56 --- /dev/null +++ b/Model/Resolver/GiftCard/SetGiftCode.php @@ -0,0 +1,51 @@ +giftCardManagement->set($args['cart_id'], $args['code']); + } catch (CouldNotSaveException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } catch (NoSuchEntityException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/GiftCard/SetGiftCredit.php b/Model/Resolver/GiftCard/SetGiftCredit.php new file mode 100644 index 0000000..7451c15 --- /dev/null +++ b/Model/Resolver/GiftCard/SetGiftCredit.php @@ -0,0 +1,51 @@ +giftCardManagement->credit($args['cart_id'], $args['amount']); + } catch (CouldNotSaveException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } catch (NoSuchEntityException $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/GiftPoolGenerate.php b/Model/Resolver/GiftPoolGenerate.php new file mode 100644 index 0000000..1c676a4 --- /dev/null +++ b/Model/Resolver/GiftPoolGenerate.php @@ -0,0 +1,58 @@ +giftPoolManagement = $giftPoolManagement; + } + + /** + * {@inheritDoc} + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + return $this->giftPoolManagement->generate($args['id'], $args['pattern'], $args['qty']); + } +} diff --git a/Model/Resolver/Save/AbstractResolver.php b/Model/Resolver/Save/AbstractResolver.php new file mode 100644 index 0000000..6948c1f --- /dev/null +++ b/Model/Resolver/Save/AbstractResolver.php @@ -0,0 +1,51 @@ +filter->saveEntity($args['input'], $this->_type); + } catch (Exception $e) { + throw new GraphQlInputException(__($e->getMessage())); + } + } +} diff --git a/Model/Resolver/Save/GiftCode.php b/Model/Resolver/Save/GiftCode.php new file mode 100644 index 0000000..16a9143 --- /dev/null +++ b/Model/Resolver/Save/GiftCode.php @@ -0,0 +1,32 @@ + Date: Thu, 12 Dec 2019 17:44:09 +0700 Subject: [PATCH 03/12] [wip] update description --- etc/schema.graphqls | 250 +++++++++++++++++++++++--------------------- 1 file changed, 131 insertions(+), 119 deletions(-) diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 4187fcf..0a3b204 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -18,7 +18,7 @@ type Query { mpGiftCode ( - id: Int! @doc(description: "Comment ..."), + id: Int! @doc(description: "Specifies the gift code id to search for."), ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftCode") @doc(description: "Searches for an item that matches the id.") mpGiftCodeList ( filter: GiftCodeFilterInput! @doc(description: "Identifies which fields to search for and return."), @@ -26,7 +26,7 @@ type Query { currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") ): GiftCodeListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftCode") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") mpGiftPool ( - id: Int! @doc(description: "Comment ..."), + id: Int! @doc(description: "Specifies the gift pool id to search for."), ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftPool") @doc(description: "Searches for an item that matches the id.") mpGiftPoolList ( filter: GiftPoolFilterInput! @doc(description: "Identifies which fields to search for and return."), @@ -34,7 +34,7 @@ type Query { currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") ): GiftPoolListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftPool") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") mpGiftTemplate ( - id: Int! @doc(description: "Comment ..."), + id: Int! @doc(description: "Specifies the gift template id to search for."), ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftTemplate") @doc(description: "Searches for an item that matches the id.") mpGiftTemplateList ( filter: GiftTemplateFilterInput! @doc(description: "Identifies which fields to search for and return."), @@ -44,32 +44,44 @@ type Query { } type Mutation { - mpGiftCodeSave (input: GiftCodeInput!): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftCode") @doc(description: "Save gift code") - mpGiftPoolSave (input: GiftPoolInput!): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftPool") @doc(description: "Save gift pool") - mpGiftTemplateSave (input: GiftTemplateInput!): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftTemplate") @doc(description: "Save gift template") - mpGiftCodeDelete (id: Int!): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftCode") @doc(description: "Delete gift code") - mpGiftPoolDelete (id: Int!): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftPool") @doc(description: "Delete gift pool") - mpGiftTemplateDelete (id: Int!): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftTemplate") @doc(description: "Delete gift template") + mpGiftCodeSave ( + input: GiftCodeInput! @doc(description: "Specifies which fields to change. If 'giftcard_id' is presented, the gift code will be updated, otherwise create new gift code.") + ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftCode") @doc(description: "Save gift code") + mpGiftPoolSave ( + input: GiftPoolInput! @doc(description: "Specifies which fields to change. If 'pool_id' is presented, the gift pool will be updated, otherwise create new gift pool.") + ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftPool") @doc(description: "Save gift pool") + mpGiftTemplateSave ( + input: GiftTemplateInput! @doc(description: "Specifies which fields to change. If 'template_id' is presented, the gift template will be updated, otherwise create new gift template.") + ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftTemplate") @doc(description: "Save gift template") + mpGiftCodeDelete ( + id: Int! @doc(description: "Specifies the gift code id to search for and delete.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftCode") @doc(description: "Delete gift code") + mpGiftPoolDelete ( + id: Int! @doc(description: "Specifies the gift pool id to search for and delete.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftPool") @doc(description: "Delete gift pool") + mpGiftTemplateDelete ( + id: Int! @doc(description: "Specifies the gift template id to search for and delete.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftTemplate") @doc(description: "Delete gift template") mpGiftPoolGenerate ( - id: Int!, - pattern: String!, - qty: Int = 1 + id: Int! @doc(description: "Specifies the gift template id to search for and generate."), + pattern: String! @doc(description: "Specifies the gift code pattern."), + qty: Int = 1 @doc(description: "How many gift codes will be generated.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPoolGenerate") @doc(description: "Generate gift code from gift pool") mpGiftCardSetCode ( - cartId: Int!, - code: String! + cartId: Int! @doc(description: "Specifies the quote id to search for and apply the gift code."), + code: String! @doc(description: "Specifies what gift code will be applied.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCode") @doc(description: "Apply gift card code") mpGiftCardRemoveCode ( - cartId: Int!, - code: String! + cartId: Int! @doc(description: "Specifies the quote id to search for and remove the gift code."), + code: String! @doc(description: "Specifies what gift code will be removed") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\RemoveGiftCode") @doc(description: "Remove gift card code") mpGiftCardSetCredit ( - cartId: Int!, - amount: String! + cartId: Int! @doc(description: "Specifies the quote id to search for and set the gift credit."), + amount: String! @doc(description: "Specifies how much gift credit will be applied.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCredit") @doc(description: "Apply gift credit amount") mpGiftCardRedeem ( - customerId: Int!, - code: String! + customerId: Int! @doc(description: "Specifies the customer id to search for and redeem the gift code."), + code: String! @doc(description: "Specifies what gift code will be redeemed.") ): GiftCardRedeemDetail @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\Redeem") @doc(description: "Redeem gift card code for customer") } @@ -130,139 +142,139 @@ input GiftTemplateFilterInput @doc(description: "Defines the filters to be used } input GiftCodeInput { - giftcard_id: Int - pattern: String - init_balance: Float - balance: Float - status: String - can_redeem: String - store_id: String - pool_id: String - template_id: String - image: String - template_fields: String + giftcard_id: Int @doc(description: "Gift card ID that is used to identify the gift card.") + pattern: String @doc(description: "Gift code pattern.") + init_balance: Float @doc(description: "Initial balance of the gift card.") + balance: Float @doc(description: "Current balance of the gift card.") + status: String @doc(description: "Is the gift card enable?") + can_redeem: String @doc(description: "Is the gift card redeemable?") + store_id: String @doc(description: "Specifies which store the gift card is available at.") + pool_id: String @doc(description: "Pool id that the gift code belongs to.") + template_id: String @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: String @doc(description: "Json encoded template fields.") # customer_ids: String # order_item_id: String # order_increment_id: String - delivery_method: String - delivery_address: String - is_sent: String - delivery_date: String - timezone: String - extra_content: String - expired_at: String + delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") + delivery_address: String @doc(description: "Delivery address that includes email or phone number.") + is_sent: String @doc(description: "Is gift card sent to recipient?") + delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") + timezone: String @doc(description: "Timezone for the gift card delivery date.") + extra_content: String @doc(description: "Extra content.") + expired_at: String @doc(description: "The date that the gift code is expired.") } input GiftPoolInput { - pool_id: Int - name: String - status: String - can_inherit: String - pattern: String - balance: Float - can_redeem: String - store_id: String - template_id: String - image: String - template_fields: String - expired_at: String + pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") + name: String @doc(description: "Gift pool name.") + status: String @doc(description: "Gift card status.") + can_inherit: String @doc(description: "Is the gift pool's properties applied for its gift cards?") + pattern: String @doc(description: "Gift code pattern.") + balance: Float @doc(description: "Balance of the gift cards that will bed generated.") + can_redeem: String @doc(description: "Is the gift card redeemable?") + store_id: String @doc(description: "Specifies which store the gift card is available at.") + template_id: String @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: String @doc(description: "Json encoded template fields.") + expired_at: String @doc(description: "The date that the gift code is expired.") } input GiftTemplateInput { - template_id: Int - name: String - status: String - can_upload: String - title: String - font_family: String - background_image: String - design: String - note: String - images: String + template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") + name: String @doc(description: "Gift template name.") + status: String @doc(description: "Gift template status.") + can_upload: String @doc(description: "Can customers upload images when using this gift template?") + title: String @doc(description: "Gift card title.") + font_family: String @doc(description: "Font family for the content of the gift template.") + background_image: String @doc(description: "Background image") + design: String @doc(description: "CSS style") + note: String @doc(description: "Note that can be displayed on the gift template.") + images: String @doc(description: "Array contains relative path, label and position of images belonged to the gift template.") } -type GiftCodeListOutput @doc(description:"Comment ...") { +type GiftCodeListOutput { total_count: Int @doc(description: "The number of items returned.") items: [GiftCodeOutput] @doc(description: "An array of items that match the specified search criteria.") page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") } -type GiftPoolListOutput @doc(description:"Comment ...") { +type GiftPoolListOutput { total_count: Int @doc(description: "The number of items returned.") items: [GiftPoolOutput] @doc(description: "An array of items that match the specified search criteria.") page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") } -type GiftTemplateListOutput @doc(description:"Comment ...") { +type GiftTemplateListOutput { total_count: Int @doc(description: "The number of items returned.") items: [GiftTemplateOutput] @doc(description: "An array of items that match the specified search criteria.") page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") } -type GiftCodeOutput @doc(description: "Comment ...") { - giftcard_id: Int - code: String - pattern: String - init_balance: Float - balance: Float - status: String - can_redeem: String - store_id: String - pool_id: String - template_id: String - image: String - template_fields: GiftCardTemplateFields - customer_ids: String - order_item_id: String - order_increment_id: String - delivery_method: String - delivery_address: String - is_sent: String - delivery_date: String - timezone: String - extra_content: String - expired_at: String - created_at: String +type GiftCodeOutput { + giftcard_id: Int @doc(description: "Gift card ID that is used to identify the gift card.") + code: String @doc(description: "Gift code") + pattern: String @doc(description: "Gift code pattern.") + init_balance: Float @doc(description: "Initial balance of the gift card.") + balance: Float @doc(description: "Current balance of the gift card.") + status: String @doc(description: "Is the gift card enable?") + can_redeem: String @doc(description: "Is the gift card redeemable?") + store_id: String @doc(description: "Specifies which store the gift card is available at.") + pool_id: String @doc(description: "Pool id that the gift code belongs to.") + template_id: String @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: GiftCardTemplateFields @doc(description: "Json encoded template fields.") + customer_ids: String @doc(description: "Customers that redeemed the gift card") + order_item_id: String @doc(description: "Specifies what gift card product generates the gift card.") + order_increment_id: String @doc(description: "Specifies what order contains the gift card product.") + delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") + delivery_address: String @doc(description: "Delivery address that includes email or phone number.") + is_sent: String @doc(description: "Is gift card sent to recipient?") + delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") + timezone: String @doc(description: "Timezone for the gift card delivery date.") + extra_content: String @doc(description: "Extra content.") + expired_at: String @doc(description: "The date that the gift code is expired.") + created_at: String @doc(description: "Timestamp indicating when the entity was created.") } -type GiftPoolOutput @doc(description: "Comment ...") { - pool_id: Int - name: String - status: String - can_inherit: String - pattern: String - balance: Float - can_redeem: String - store_id: String - template_id: String - image: String - template_fields: GiftCardTemplateFields - expired_at: String - created_at: String +type GiftPoolOutput { + pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") + name: String @doc(description: "Gift pool name.") + status: String @doc(description: "Gift card status.") + can_inherit: String @doc(description: "Is the gift pool's properties applied for its gift cards?") + pattern: String @doc(description: "Gift code pattern.") + balance: Float @doc(description: "Balance of the gift cards that will bed generated.") + can_redeem: String @doc(description: "Is the gift card redeemable?") + store_id: String @doc(description: "Specifies which store the gift card is available at.") + template_id: String @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: GiftCardTemplateFields @doc(description: "Json encoded template fields.") + expired_at: String @doc(description: "The date that the gift code is expired.") + created_at: String @doc(description: "Timestamp indicating when the entity was created.") } -type GiftTemplateOutput @doc(description: "Comment ...") { - template_id: Int - name: String - status: String - can_upload: String - title: String - font_family: String - background_image: String - design: String - note: String - images: String - created_at: String +type GiftTemplateOutput { + template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") + name: String @doc(description: "Gift template name.") + status: String @doc(description: "Gift template status.") + can_upload: String @doc(description: "Can customers upload images when using this gift template?") + title: String @doc(description: "Gift card title.") + font_family: String @doc(description: "Font family for the content of the gift template.") + background_image: String @doc(description: "Background image") + design: String @doc(description: "CSS style") + note: String @doc(description: "Note that can be displayed on the gift template.") + images: String @doc(description: "Array contains relative path, label and position of images belonged to the gift template.") + created_at: String @doc(description: "Timestamp indicating when the entity was created.") } -type GiftCardTemplateFields @doc(description: "Comment ...") { - sender: String - recipient: String - message: String +type GiftCardTemplateFields { + sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") + recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") + message: String @doc(description: "Message that is displayed on the gift card.") } -type GiftCardRedeemDetail @doc(description: "Comment ...") { - customer_balance: String +type GiftCardRedeemDetail { + customer_balance: String @doc(description: "Customer's balance after redeeming gift code.") } type PageInfo { From c857500465315fe362348fac493d8c6e7b5648d2 Mon Sep 17 00:00:00 2001 From: datvm Date: Tue, 17 Dec 2019 09:33:35 +0700 Subject: [PATCH 04/12] clean code --- Model/Resolver/AbstractResolver.php | 1 + Model/Resolver/Delete/AbstractResolver.php | 1 + Model/Resolver/Delete/GiftCode.php | 1 + Model/Resolver/Delete/GiftPool.php | 1 + Model/Resolver/Delete/GiftTemplate.php | 1 + Model/Resolver/Filter/Query/Filter.php | 1 + Model/Resolver/Filter/SearchResult.php | 1 + Model/Resolver/Filter/SearchResultFactory.php | 1 + Model/Resolver/FilterArgument.php | 1 + Model/Resolver/Get/AbstractResolver.php | 1 + Model/Resolver/Get/GiftCode.php | 1 + Model/Resolver/Get/GiftPool.php | 1 + Model/Resolver/Get/GiftTemplate.php | 1 + Model/Resolver/GetList/AbstractResolver.php | 1 + Model/Resolver/GetList/GiftCode.php | 1 + Model/Resolver/GetList/GiftPool.php | 1 + Model/Resolver/GetList/GiftTemplate.php | 1 + Model/Resolver/GiftCard/AbstractResolver.php | 1 + Model/Resolver/GiftCard/Redeem.php | 1 + Model/Resolver/GiftCard/RemoveGiftCode.php | 1 + Model/Resolver/GiftCard/SetGiftCode.php | 1 + Model/Resolver/GiftCard/SetGiftCredit.php | 1 + Model/Resolver/GiftPoolGenerate.php | 1 + Model/Resolver/Save/AbstractResolver.php | 1 + Model/Resolver/Save/GiftCode.php | 1 + Model/Resolver/Save/GiftPool.php | 1 + Model/Resolver/Save/GiftTemplate.php | 1 + etc/schema.graphqls | 3 --- 28 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Model/Resolver/AbstractResolver.php b/Model/Resolver/AbstractResolver.php index d1c4b37..795a81e 100644 --- a/Model/Resolver/AbstractResolver.php +++ b/Model/Resolver/AbstractResolver.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver; diff --git a/Model/Resolver/Delete/AbstractResolver.php b/Model/Resolver/Delete/AbstractResolver.php index d692956..ea2f511 100644 --- a/Model/Resolver/Delete/AbstractResolver.php +++ b/Model/Resolver/Delete/AbstractResolver.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete; diff --git a/Model/Resolver/Delete/GiftCode.php b/Model/Resolver/Delete/GiftCode.php index bacf751..f08b9f8 100644 --- a/Model/Resolver/Delete/GiftCode.php +++ b/Model/Resolver/Delete/GiftCode.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete; diff --git a/Model/Resolver/Delete/GiftPool.php b/Model/Resolver/Delete/GiftPool.php index 32674b0..ab364fc 100644 --- a/Model/Resolver/Delete/GiftPool.php +++ b/Model/Resolver/Delete/GiftPool.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete; diff --git a/Model/Resolver/Delete/GiftTemplate.php b/Model/Resolver/Delete/GiftTemplate.php index 60fe39b..6afac92 100644 --- a/Model/Resolver/Delete/GiftTemplate.php +++ b/Model/Resolver/Delete/GiftTemplate.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete; diff --git a/Model/Resolver/Filter/Query/Filter.php b/Model/Resolver/Filter/Query/Filter.php index 4688c51..9104792 100644 --- a/Model/Resolver/Filter/Query/Filter.php +++ b/Model/Resolver/Filter/Query/Filter.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Filter\Query; diff --git a/Model/Resolver/Filter/SearchResult.php b/Model/Resolver/Filter/SearchResult.php index e5d6010..d7bcddd 100644 --- a/Model/Resolver/Filter/SearchResult.php +++ b/Model/Resolver/Filter/SearchResult.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Filter; diff --git a/Model/Resolver/Filter/SearchResultFactory.php b/Model/Resolver/Filter/SearchResultFactory.php index 239ee5a..b3a8b23 100644 --- a/Model/Resolver/Filter/SearchResultFactory.php +++ b/Model/Resolver/Filter/SearchResultFactory.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Filter; diff --git a/Model/Resolver/FilterArgument.php b/Model/Resolver/FilterArgument.php index 7ab49ef..3ac1269 100644 --- a/Model/Resolver/FilterArgument.php +++ b/Model/Resolver/FilterArgument.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver; diff --git a/Model/Resolver/Get/AbstractResolver.php b/Model/Resolver/Get/AbstractResolver.php index fb183c3..56cd6b9 100644 --- a/Model/Resolver/Get/AbstractResolver.php +++ b/Model/Resolver/Get/AbstractResolver.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; diff --git a/Model/Resolver/Get/GiftCode.php b/Model/Resolver/Get/GiftCode.php index 027aca1..b52b6a3 100644 --- a/Model/Resolver/Get/GiftCode.php +++ b/Model/Resolver/Get/GiftCode.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; diff --git a/Model/Resolver/Get/GiftPool.php b/Model/Resolver/Get/GiftPool.php index d2e1ecf..669aae7 100644 --- a/Model/Resolver/Get/GiftPool.php +++ b/Model/Resolver/Get/GiftPool.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; diff --git a/Model/Resolver/Get/GiftTemplate.php b/Model/Resolver/Get/GiftTemplate.php index 99f6333..6eb15b0 100644 --- a/Model/Resolver/Get/GiftTemplate.php +++ b/Model/Resolver/Get/GiftTemplate.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Get; diff --git a/Model/Resolver/GetList/AbstractResolver.php b/Model/Resolver/GetList/AbstractResolver.php index a2c1824..9aa99be 100644 --- a/Model/Resolver/GetList/AbstractResolver.php +++ b/Model/Resolver/GetList/AbstractResolver.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GetList; diff --git a/Model/Resolver/GetList/GiftCode.php b/Model/Resolver/GetList/GiftCode.php index 092e4b0..c08c761 100644 --- a/Model/Resolver/GetList/GiftCode.php +++ b/Model/Resolver/GetList/GiftCode.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GetList; diff --git a/Model/Resolver/GetList/GiftPool.php b/Model/Resolver/GetList/GiftPool.php index 69a3ff6..9db0f17 100644 --- a/Model/Resolver/GetList/GiftPool.php +++ b/Model/Resolver/GetList/GiftPool.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GetList; diff --git a/Model/Resolver/GetList/GiftTemplate.php b/Model/Resolver/GetList/GiftTemplate.php index 71441f7..d0357bb 100644 --- a/Model/Resolver/GetList/GiftTemplate.php +++ b/Model/Resolver/GetList/GiftTemplate.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GetList; diff --git a/Model/Resolver/GiftCard/AbstractResolver.php b/Model/Resolver/GiftCard/AbstractResolver.php index 84556a8..a45e0d9 100644 --- a/Model/Resolver/GiftCard/AbstractResolver.php +++ b/Model/Resolver/GiftCard/AbstractResolver.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GiftCard; diff --git a/Model/Resolver/GiftCard/Redeem.php b/Model/Resolver/GiftCard/Redeem.php index c7904f3..183d374 100644 --- a/Model/Resolver/GiftCard/Redeem.php +++ b/Model/Resolver/GiftCard/Redeem.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GiftCard; diff --git a/Model/Resolver/GiftCard/RemoveGiftCode.php b/Model/Resolver/GiftCard/RemoveGiftCode.php index fc4004a..14ded3f 100644 --- a/Model/Resolver/GiftCard/RemoveGiftCode.php +++ b/Model/Resolver/GiftCard/RemoveGiftCode.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GiftCard; diff --git a/Model/Resolver/GiftCard/SetGiftCode.php b/Model/Resolver/GiftCard/SetGiftCode.php index 9078d56..da3e31b 100644 --- a/Model/Resolver/GiftCard/SetGiftCode.php +++ b/Model/Resolver/GiftCard/SetGiftCode.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GiftCard; diff --git a/Model/Resolver/GiftCard/SetGiftCredit.php b/Model/Resolver/GiftCard/SetGiftCredit.php index 7451c15..73e9513 100644 --- a/Model/Resolver/GiftCard/SetGiftCredit.php +++ b/Model/Resolver/GiftCard/SetGiftCredit.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GiftCard; diff --git a/Model/Resolver/GiftPoolGenerate.php b/Model/Resolver/GiftPoolGenerate.php index 1c676a4..f465cd5 100644 --- a/Model/Resolver/GiftPoolGenerate.php +++ b/Model/Resolver/GiftPoolGenerate.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver; diff --git a/Model/Resolver/Save/AbstractResolver.php b/Model/Resolver/Save/AbstractResolver.php index 6948c1f..32af982 100644 --- a/Model/Resolver/Save/AbstractResolver.php +++ b/Model/Resolver/Save/AbstractResolver.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Save; diff --git a/Model/Resolver/Save/GiftCode.php b/Model/Resolver/Save/GiftCode.php index 16a9143..78312ef 100644 --- a/Model/Resolver/Save/GiftCode.php +++ b/Model/Resolver/Save/GiftCode.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Save; diff --git a/Model/Resolver/Save/GiftPool.php b/Model/Resolver/Save/GiftPool.php index 60b4c39..9d3d053 100644 --- a/Model/Resolver/Save/GiftPool.php +++ b/Model/Resolver/Save/GiftPool.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Save; diff --git a/Model/Resolver/Save/GiftTemplate.php b/Model/Resolver/Save/GiftTemplate.php index d004947..581590a 100644 --- a/Model/Resolver/Save/GiftTemplate.php +++ b/Model/Resolver/Save/GiftTemplate.php @@ -18,6 +18,7 @@ * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ + declare(strict_types=1); namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Save; diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 0a3b204..090c537 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -153,9 +153,6 @@ input GiftCodeInput { template_id: String @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") template_fields: String @doc(description: "Json encoded template fields.") - # customer_ids: String - # order_item_id: String - # order_increment_id: String delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") delivery_address: String @doc(description: "Delivery address that includes email or phone number.") is_sent: String @doc(description: "Is gift card sent to recipient?") From 0e94b9a4ce199e0ad81f18343a7cf8349335bd99 Mon Sep 17 00:00:00 2001 From: datvm Date: Thu, 19 Dec 2019 09:51:23 +0700 Subject: [PATCH 05/12] prevent resolving when the module is turned off --- Model/Resolver/AbstractResolver.php | 19 +++++++++++++++++-- Model/Resolver/GiftCard/AbstractResolver.php | 19 +++++++++++++++++-- Model/Resolver/GiftPoolGenerate.php | 19 +++++++++++++++++-- etc/schema.graphqls | 4 ++-- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Model/Resolver/AbstractResolver.php b/Model/Resolver/AbstractResolver.php index 795a81e..8e11997 100644 --- a/Model/Resolver/AbstractResolver.php +++ b/Model/Resolver/AbstractResolver.php @@ -24,8 +24,10 @@ 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 Mageplaza\GiftCard\Helper\Data; use Mageplaza\GiftCardGraphQl\Model\Resolver\Filter\Query\Filter; /** @@ -41,14 +43,23 @@ abstract class AbstractResolver implements ResolverInterface */ protected $filter; + /** + * @var Data + */ + private $helper; + /** * AbstractResolver constructor. * * @param Filter $filter + * @param Data $helper */ - public function __construct(Filter $filter) - { + public function __construct( + Filter $filter, + Data $helper + ) { $this->filter = $filter; + $this->helper = $helper; } /** @@ -56,6 +67,10 @@ public function __construct(Filter $filter) */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { + if (!$this->helper->isEnabled()) { + throw new GraphQlInputException(__('The module is disabled')); + } + return $this->handleArgs($args); } diff --git a/Model/Resolver/GiftCard/AbstractResolver.php b/Model/Resolver/GiftCard/AbstractResolver.php index a45e0d9..6305f41 100644 --- a/Model/Resolver/GiftCard/AbstractResolver.php +++ b/Model/Resolver/GiftCard/AbstractResolver.php @@ -24,9 +24,11 @@ namespace Mageplaza\GiftCardGraphQl\Model\Resolver\GiftCard; 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\GiftCardManagementInterface; +use Mageplaza\GiftCard\Helper\Data; /** * Class AbstractResolver @@ -39,14 +41,23 @@ abstract class AbstractResolver implements ResolverInterface */ protected $giftCardManagement; + /** + * @var Data + */ + private $helper; + /** * AbstractResolver constructor. * * @param GiftCardManagementInterface $giftCardManagement + * @param Data $helper */ - public function __construct(GiftCardManagementInterface $giftCardManagement) - { + public function __construct( + GiftCardManagementInterface $giftCardManagement, + Data $helper + ) { $this->giftCardManagement = $giftCardManagement; + $this->helper = $helper; } /** @@ -54,6 +65,10 @@ public function __construct(GiftCardManagementInterface $giftCardManagement) */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { + if (!$this->helper->isEnabled()) { + throw new GraphQlInputException(__('The module is disabled')); + } + return $this->handleArgs($args); } diff --git a/Model/Resolver/GiftPoolGenerate.php b/Model/Resolver/GiftPoolGenerate.php index f465cd5..1d22ff5 100644 --- a/Model/Resolver/GiftPoolGenerate.php +++ b/Model/Resolver/GiftPoolGenerate.php @@ -24,9 +24,11 @@ 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 Mageplaza\GiftCard\Api\GiftPoolManagementInterface; +use Mageplaza\GiftCard\Helper\Data; /** * Class GiftPoolGenerate @@ -39,14 +41,23 @@ class GiftPoolGenerate implements ResolverInterface */ private $giftPoolManagement; + /** + * @var Data + */ + private $helper; + /** * AbstractResolver constructor. * * @param GiftPoolManagementInterface $giftPoolManagement + * @param Data $helper */ - public function __construct(GiftPoolManagementInterface $giftPoolManagement) - { + public function __construct( + GiftPoolManagementInterface $giftPoolManagement, + Data $helper + ) { $this->giftPoolManagement = $giftPoolManagement; + $this->helper = $helper; } /** @@ -54,6 +65,10 @@ public function __construct(GiftPoolManagementInterface $giftPoolManagement) */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { + if (!$this->helper->isEnabled()) { + throw new GraphQlInputException(__('The module is disabled')); + } + return $this->giftPoolManagement->generate($args['id'], $args['pattern'], $args['qty']); } } diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 090c537..753d66d 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -64,9 +64,9 @@ type Mutation { ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftTemplate") @doc(description: "Delete gift template") mpGiftPoolGenerate ( id: Int! @doc(description: "Specifies the gift template id to search for and generate."), - pattern: String! @doc(description: "Specifies the gift code pattern."), + pattern: String = "[4AN]-[4A]-[4N]" @doc(description: "Specifies the gift code pattern."), qty: Int = 1 @doc(description: "How many gift codes will be generated.") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPoolGenerate") @doc(description: "Generate gift code from gift pool") + ): [String] @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPoolGenerate") @doc(description: "Generate gift code from gift pool") mpGiftCardSetCode ( cartId: Int! @doc(description: "Specifies the quote id to search for and apply the gift code."), code: String! @doc(description: "Specifies what gift code will be applied.") From f20e19399aba852088a17aba8381ccbac52718a5 Mon Sep 17 00:00:00 2001 From: datvm Date: Thu, 19 Dec 2019 14:25:02 +0700 Subject: [PATCH 06/12] fix typo --- etc/schema.graphqls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 753d66d..6794e23 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -32,7 +32,7 @@ type Query { filter: GiftPoolFilterInput! @doc(description: "Identifies which fields to search for and return."), pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") - ): GiftPoolListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftPool") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") + ): GiftPoolListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftPool") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") mpGiftTemplate ( id: Int! @doc(description: "Specifies the gift template id to search for."), ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftTemplate") @doc(description: "Searches for an item that matches the id.") @@ -40,7 +40,7 @@ type Query { filter: GiftTemplateFilterInput! @doc(description: "Identifies which fields to search for and return."), pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") - ): GiftTemplateListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftTemplate") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") + ): GiftTemplateListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftTemplate") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") } type Mutation { From 27f0a4037d6ed38337517096c43d8720e6f2d7b5 Mon Sep 17 00:00:00 2001 From: datvm Date: Thu, 19 Dec 2019 17:12:08 +0700 Subject: [PATCH 07/12] fix template fields input --- Model/Resolver/Filter/Query/Filter.php | 5 +++++ etc/schema.graphqls | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Model/Resolver/Filter/Query/Filter.php b/Model/Resolver/Filter/Query/Filter.php index 9104792..9396c9d 100644 --- a/Model/Resolver/Filter/Query/Filter.php +++ b/Model/Resolver/Filter/Query/Filter.php @@ -32,6 +32,7 @@ use Mageplaza\GiftCard\Api\GiftCodeManagementInterface; use Mageplaza\GiftCard\Api\GiftPoolManagementInterface; use Mageplaza\GiftCard\Api\GiftTemplateManagementInterface; +use Mageplaza\GiftCard\Helper\Data; use Mageplaza\GiftCard\Model\GiftCard as GiftCardModel; use Mageplaza\GiftCard\Model\GiftCardFactory; use Mageplaza\GiftCard\Model\Pool as PoolModel; @@ -182,6 +183,10 @@ public function getResultById($id, $type) */ public function saveEntity($data, $type) { + if (isset($data['template_fields'])) { + $data['template_fields'] = Data::jsonEncode($data['template_fields']); + } + switch ($type) { case 'mpGiftCode': $entity = $this->giftCardFactory->create()->setData($data); diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 6794e23..4b7eb1f 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -152,7 +152,7 @@ input GiftCodeInput { pool_id: String @doc(description: "Pool id that the gift code belongs to.") template_id: String @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") - template_fields: String @doc(description: "Json encoded template fields.") + template_fields: GiftCardTemplateFieldsInput @doc(description: "Json encoded template fields.") delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") delivery_address: String @doc(description: "Delivery address that includes email or phone number.") is_sent: String @doc(description: "Is gift card sent to recipient?") @@ -173,7 +173,7 @@ input GiftPoolInput { store_id: String @doc(description: "Specifies which store the gift card is available at.") template_id: String @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") - template_fields: String @doc(description: "Json encoded template fields.") + template_fields: GiftCardTemplateFieldsInput @doc(description: "Json encoded template fields.") expired_at: String @doc(description: "The date that the gift code is expired.") } @@ -264,6 +264,12 @@ type GiftTemplateOutput { created_at: String @doc(description: "Timestamp indicating when the entity was created.") } +input GiftCardTemplateFieldsInput { + sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") + recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") + message: String @doc(description: "Message that is displayed on the gift card.") +} + type GiftCardTemplateFields { sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") From 7576c861249f06a1a4143db5df2d10149cb862c4 Mon Sep 17 00:00:00 2001 From: datvm Date: Fri, 20 Dec 2019 09:59:20 +0700 Subject: [PATCH 08/12] update input type --- etc/schema.graphqls | 60 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 4b7eb1f..707127e 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -146,16 +146,16 @@ input GiftCodeInput { pattern: String @doc(description: "Gift code pattern.") init_balance: Float @doc(description: "Initial balance of the gift card.") balance: Float @doc(description: "Current balance of the gift card.") - status: String @doc(description: "Is the gift card enable?") - can_redeem: String @doc(description: "Is the gift card redeemable?") - store_id: String @doc(description: "Specifies which store the gift card is available at.") - pool_id: String @doc(description: "Pool id that the gift code belongs to.") - template_id: String @doc(description: "Template id that is used for the gift card.") + status: Int @doc(description: "Is the gift card enable?") + can_redeem: Int @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + pool_id: Int @doc(description: "Pool id that the gift code belongs to.") + template_id: Int @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFieldsInput @doc(description: "Json encoded template fields.") + template_fields: GiftCardTemplateFieldsInput @doc(description: "Template fields.") delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") delivery_address: String @doc(description: "Delivery address that includes email or phone number.") - is_sent: String @doc(description: "Is gift card sent to recipient?") + is_sent: Int @doc(description: "Is gift card sent to recipient?") delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") timezone: String @doc(description: "Timezone for the gift card delivery date.") extra_content: String @doc(description: "Extra content.") @@ -165,23 +165,23 @@ input GiftCodeInput { input GiftPoolInput { pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") name: String @doc(description: "Gift pool name.") - status: String @doc(description: "Gift card status.") - can_inherit: String @doc(description: "Is the gift pool's properties applied for its gift cards?") + status: Int @doc(description: "Gift card status.") + can_inherit: Int @doc(description: "Is the gift pool's properties applied for its gift cards?") pattern: String @doc(description: "Gift code pattern.") balance: Float @doc(description: "Balance of the gift cards that will bed generated.") - can_redeem: String @doc(description: "Is the gift card redeemable?") - store_id: String @doc(description: "Specifies which store the gift card is available at.") - template_id: String @doc(description: "Template id that is used for the gift card.") + can_redeem: Int @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + template_id: Int @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFieldsInput @doc(description: "Json encoded template fields.") + template_fields: GiftCardTemplateFieldsInput @doc(description: "Template fields.") expired_at: String @doc(description: "The date that the gift code is expired.") } input GiftTemplateInput { template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") name: String @doc(description: "Gift template name.") - status: String @doc(description: "Gift template status.") - can_upload: String @doc(description: "Can customers upload images when using this gift template?") + status: Int @doc(description: "Gift template status.") + can_upload: Int @doc(description: "Can customers upload images when using this gift template?") title: String @doc(description: "Gift card title.") font_family: String @doc(description: "Font family for the content of the gift template.") background_image: String @doc(description: "Background image") @@ -214,19 +214,19 @@ type GiftCodeOutput { pattern: String @doc(description: "Gift code pattern.") init_balance: Float @doc(description: "Initial balance of the gift card.") balance: Float @doc(description: "Current balance of the gift card.") - status: String @doc(description: "Is the gift card enable?") + status: Int @doc(description: "Is the gift card enable?") can_redeem: String @doc(description: "Is the gift card redeemable?") - store_id: String @doc(description: "Specifies which store the gift card is available at.") - pool_id: String @doc(description: "Pool id that the gift code belongs to.") - template_id: String @doc(description: "Template id that is used for the gift card.") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + pool_id: Int @doc(description: "Pool id that the gift code belongs to.") + template_id: Int @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFields @doc(description: "Json encoded template fields.") + template_fields: GiftCardTemplateFields @doc(description: "Template fields.") customer_ids: String @doc(description: "Customers that redeemed the gift card") - order_item_id: String @doc(description: "Specifies what gift card product generates the gift card.") - order_increment_id: String @doc(description: "Specifies what order contains the gift card product.") + order_item_id: Int @doc(description: "Specifies what gift card product generates the gift card.") + order_increment_id: Int @doc(description: "Specifies what order contains the gift card product.") delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") delivery_address: String @doc(description: "Delivery address that includes email or phone number.") - is_sent: String @doc(description: "Is gift card sent to recipient?") + is_sent: Int @doc(description: "Is gift card sent to recipient?") delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") timezone: String @doc(description: "Timezone for the gift card delivery date.") extra_content: String @doc(description: "Extra content.") @@ -237,15 +237,15 @@ type GiftCodeOutput { type GiftPoolOutput { pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") name: String @doc(description: "Gift pool name.") - status: String @doc(description: "Gift card status.") - can_inherit: String @doc(description: "Is the gift pool's properties applied for its gift cards?") + status: Int @doc(description: "Gift card status.") + can_inherit: Int @doc(description: "Is the gift pool's properties applied for its gift cards?") pattern: String @doc(description: "Gift code pattern.") balance: Float @doc(description: "Balance of the gift cards that will bed generated.") - can_redeem: String @doc(description: "Is the gift card redeemable?") - store_id: String @doc(description: "Specifies which store the gift card is available at.") - template_id: String @doc(description: "Template id that is used for the gift card.") + can_redeem: Int @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + template_id: Int @doc(description: "Template id that is used for the gift card.") image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFields @doc(description: "Json encoded template fields.") + template_fields: GiftCardTemplateFields @doc(description: "Template fields.") expired_at: String @doc(description: "The date that the gift code is expired.") created_at: String @doc(description: "Timestamp indicating when the entity was created.") } @@ -253,7 +253,7 @@ type GiftPoolOutput { type GiftTemplateOutput { template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") name: String @doc(description: "Gift template name.") - status: String @doc(description: "Gift template status.") + status: Int @doc(description: "Gift template status.") can_upload: String @doc(description: "Can customers upload images when using this gift template?") title: String @doc(description: "Gift card title.") font_family: String @doc(description: "Font family for the content of the gift template.") From 04d4d400884561975d196da4a292b162f1ba83fc Mon Sep 17 00:00:00 2001 From: datvm Date: Mon, 23 Dec 2019 09:56:57 +0700 Subject: [PATCH 09/12] fix typo in param key --- Model/Resolver/GiftCard/Redeem.php | 2 +- Model/Resolver/GiftCard/RemoveGiftCode.php | 2 +- Model/Resolver/GiftCard/SetGiftCode.php | 2 +- Model/Resolver/GiftCard/SetGiftCredit.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/Resolver/GiftCard/Redeem.php b/Model/Resolver/GiftCard/Redeem.php index 183d374..4700664 100644 --- a/Model/Resolver/GiftCard/Redeem.php +++ b/Model/Resolver/GiftCard/Redeem.php @@ -42,7 +42,7 @@ class Redeem extends AbstractResolver protected function handleArgs(array $args) { try { - return $this->giftCardManagement->redeem($args['customer_id'], $args['code']); + return $this->giftCardManagement->redeem($args['customerId'], $args['code']); } catch (Exception $e) { throw new GraphQlInputException(__($e->getMessage())); } diff --git a/Model/Resolver/GiftCard/RemoveGiftCode.php b/Model/Resolver/GiftCard/RemoveGiftCode.php index 14ded3f..71173c0 100644 --- a/Model/Resolver/GiftCard/RemoveGiftCode.php +++ b/Model/Resolver/GiftCard/RemoveGiftCode.php @@ -42,7 +42,7 @@ class RemoveGiftCode extends AbstractResolver protected function handleArgs(array $args) { try { - return $this->giftCardManagement->remove($args['cart_id'], $args['code']); + return $this->giftCardManagement->remove($args['cartId'], $args['code']); } catch (CouldNotDeleteException $e) { throw new GraphQlInputException(__($e->getMessage())); } catch (NoSuchEntityException $e) { diff --git a/Model/Resolver/GiftCard/SetGiftCode.php b/Model/Resolver/GiftCard/SetGiftCode.php index da3e31b..79acff1 100644 --- a/Model/Resolver/GiftCard/SetGiftCode.php +++ b/Model/Resolver/GiftCard/SetGiftCode.php @@ -42,7 +42,7 @@ class SetGiftCode extends AbstractResolver protected function handleArgs(array $args) { try { - return $this->giftCardManagement->set($args['cart_id'], $args['code']); + return $this->giftCardManagement->set($args['cartId'], $args['code']); } catch (CouldNotSaveException $e) { throw new GraphQlInputException(__($e->getMessage())); } catch (NoSuchEntityException $e) { diff --git a/Model/Resolver/GiftCard/SetGiftCredit.php b/Model/Resolver/GiftCard/SetGiftCredit.php index 73e9513..7c8cd3e 100644 --- a/Model/Resolver/GiftCard/SetGiftCredit.php +++ b/Model/Resolver/GiftCard/SetGiftCredit.php @@ -42,7 +42,7 @@ class SetGiftCredit extends AbstractResolver protected function handleArgs(array $args) { try { - return $this->giftCardManagement->credit($args['cart_id'], $args['amount']); + return $this->giftCardManagement->credit($args['cartId'], $args['amount']); } catch (CouldNotSaveException $e) { throw new GraphQlInputException(__($e->getMessage())); } catch (NoSuchEntityException $e) { From 2afb19fa737c9b824a3621516de806a38afc70fb Mon Sep 17 00:00:00 2001 From: datvm Date: Mon, 23 Dec 2019 11:27:00 +0700 Subject: [PATCH 10/12] validate code pattern and qty when generating --- Model/Resolver/GiftPoolGenerate.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Model/Resolver/GiftPoolGenerate.php b/Model/Resolver/GiftPoolGenerate.php index 1d22ff5..cc508e2 100644 --- a/Model/Resolver/GiftPoolGenerate.php +++ b/Model/Resolver/GiftPoolGenerate.php @@ -69,6 +69,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('The module is disabled')); } + if ($args['pattern'] === '') { + throw new GraphQlInputException(__('pattern value must not be empty.')); + } + + if ($args['qty'] < 0) { + throw new GraphQlInputException(__('qty value must be greater than 0.')); + } + return $this->giftPoolManagement->generate($args['id'], $args['pattern'], $args['qty']); } } From 9fc78c2b0b5d22f2b6410508d73f49654be2bcdb Mon Sep 17 00:00:00 2001 From: datvm Date: Tue, 24 Dec 2019 11:58:03 +0700 Subject: [PATCH 11/12] [wip] add authorization by access token --- Helper/Auth.php | 89 ++++++++++++++++++++ Model/Resolver/AbstractResolver.php | 23 ++++- Model/Resolver/Delete/GiftCode.php | 8 ++ Model/Resolver/Delete/GiftPool.php | 8 ++ Model/Resolver/Delete/GiftTemplate.php | 8 ++ Model/Resolver/Get/GiftCode.php | 8 ++ Model/Resolver/GetList/GiftCode.php | 8 ++ Model/Resolver/GiftCard/AbstractResolver.php | 20 ++++- Model/Resolver/GiftPoolGenerate.php | 20 ++++- Model/Resolver/Save/GiftCode.php | 8 ++ Model/Resolver/Save/GiftPool.php | 8 ++ Model/Resolver/Save/GiftTemplate.php | 8 ++ etc/schema.graphqls | 13 +++ 13 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 Helper/Auth.php diff --git a/Helper/Auth.php b/Helper/Auth.php new file mode 100644 index 0000000..cd9f095 --- /dev/null +++ b/Helper/Auth.php @@ -0,0 +1,89 @@ +aclPolicy = $aclPolicy; + $this->tokenFactory = $tokenFactory; + $this->integrationService = $integrationService; + } + + /** + * @param string $accessToken + * + * @return string + */ + private function getAclRoleId($accessToken) + { + $token = $this->tokenFactory->create()->loadByToken($accessToken); + + return $this->integrationService->findByConsumerId($token->getConsumerId())->getId(); + } + + /** + * @param string $accessToken + * @param string $resource + * @param string $privilege + * + * @return bool + */ + public function isAllowed($accessToken, $resource, $privilege = null) + { + return $this->aclPolicy->isAllowed($this->getAclRoleId($accessToken), $resource, $privilege); + } +} diff --git a/Model/Resolver/AbstractResolver.php b/Model/Resolver/AbstractResolver.php index 8e11997..090aca9 100644 --- a/Model/Resolver/AbstractResolver.php +++ b/Model/Resolver/AbstractResolver.php @@ -28,6 +28,7 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Mageplaza\GiftCard\Helper\Data; +use Mageplaza\GiftCardGraphQl\Helper\Auth; use Mageplaza\GiftCardGraphQl\Model\Resolver\Filter\Query\Filter; /** @@ -36,6 +37,14 @@ */ abstract class AbstractResolver implements ResolverInterface { + /** + * @var string + */ + protected $_aclResource = ''; + + /** + * @var string + */ protected $_type = ''; /** @@ -48,18 +57,26 @@ abstract class AbstractResolver implements ResolverInterface */ private $helper; + /** + * @var Auth + */ + private $auth; + /** * AbstractResolver constructor. * * @param Filter $filter * @param Data $helper + * @param Auth $auth */ public function __construct( Filter $filter, - Data $helper + Data $helper, + Auth $auth ) { $this->filter = $filter; $this->helper = $helper; + $this->auth = $auth; } /** @@ -71,6 +88,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('The module is disabled')); } + if (!$this->auth->isAllowed($args['accessToken'], $this->_aclResource)) { + throw new GraphQlInputException(__("The consumer isn't authorized to access %1", $this->_aclResource)); + } + return $this->handleArgs($args); } diff --git a/Model/Resolver/Delete/GiftCode.php b/Model/Resolver/Delete/GiftCode.php index f08b9f8..9b357ef 100644 --- a/Model/Resolver/Delete/GiftCode.php +++ b/Model/Resolver/Delete/GiftCode.php @@ -29,5 +29,13 @@ */ class GiftCode extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::code'; + + /** + * @var string + */ protected $_type = 'mpGiftCode'; } diff --git a/Model/Resolver/Delete/GiftPool.php b/Model/Resolver/Delete/GiftPool.php index ab364fc..2c1058c 100644 --- a/Model/Resolver/Delete/GiftPool.php +++ b/Model/Resolver/Delete/GiftPool.php @@ -29,5 +29,13 @@ */ class GiftPool extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::pool'; + + /** + * @var string + */ protected $_type = 'mpGiftPool'; } diff --git a/Model/Resolver/Delete/GiftTemplate.php b/Model/Resolver/Delete/GiftTemplate.php index 6afac92..22aad13 100644 --- a/Model/Resolver/Delete/GiftTemplate.php +++ b/Model/Resolver/Delete/GiftTemplate.php @@ -29,5 +29,13 @@ */ class GiftTemplate extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::template'; + + /** + * @var string + */ protected $_type = 'mpGiftTemplate'; } diff --git a/Model/Resolver/Get/GiftCode.php b/Model/Resolver/Get/GiftCode.php index b52b6a3..7554d16 100644 --- a/Model/Resolver/Get/GiftCode.php +++ b/Model/Resolver/Get/GiftCode.php @@ -29,5 +29,13 @@ */ class GiftCode extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::code'; + + /** + * @var string + */ protected $_type = 'mpGiftCode'; } diff --git a/Model/Resolver/GetList/GiftCode.php b/Model/Resolver/GetList/GiftCode.php index c08c761..44a4947 100644 --- a/Model/Resolver/GetList/GiftCode.php +++ b/Model/Resolver/GetList/GiftCode.php @@ -29,5 +29,13 @@ */ class GiftCode extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::code'; + + /** + * @var string + */ protected $_type = 'mpGiftCode'; } diff --git a/Model/Resolver/GiftCard/AbstractResolver.php b/Model/Resolver/GiftCard/AbstractResolver.php index 6305f41..a8fba69 100644 --- a/Model/Resolver/GiftCard/AbstractResolver.php +++ b/Model/Resolver/GiftCard/AbstractResolver.php @@ -29,6 +29,7 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Mageplaza\GiftCard\Api\GiftCardManagementInterface; use Mageplaza\GiftCard\Helper\Data; +use Mageplaza\GiftCardGraphQl\Helper\Auth; /** * Class AbstractResolver @@ -36,6 +37,11 @@ */ abstract class AbstractResolver implements ResolverInterface { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::code'; + /** * @var GiftCardManagementInterface */ @@ -46,18 +52,26 @@ abstract class AbstractResolver implements ResolverInterface */ private $helper; + /** + * @var Auth + */ + private $auth; + /** * AbstractResolver constructor. * * @param GiftCardManagementInterface $giftCardManagement * @param Data $helper + * @param Auth $auth */ public function __construct( GiftCardManagementInterface $giftCardManagement, - Data $helper + Data $helper, + Auth $auth ) { $this->giftCardManagement = $giftCardManagement; $this->helper = $helper; + $this->auth = $auth; } /** @@ -69,6 +83,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('The module is disabled')); } + if (!$this->auth->isAllowed($args['accessToken'], $this->_aclResource)) { + throw new GraphQlInputException(__("The consumer isn't authorized to access %1", $this->_aclResource)); + } + return $this->handleArgs($args); } diff --git a/Model/Resolver/GiftPoolGenerate.php b/Model/Resolver/GiftPoolGenerate.php index cc508e2..126803c 100644 --- a/Model/Resolver/GiftPoolGenerate.php +++ b/Model/Resolver/GiftPoolGenerate.php @@ -29,6 +29,7 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Mageplaza\GiftCard\Api\GiftPoolManagementInterface; use Mageplaza\GiftCard\Helper\Data; +use Mageplaza\GiftCardGraphQl\Helper\Auth; /** * Class GiftPoolGenerate @@ -36,6 +37,11 @@ */ class GiftPoolGenerate implements ResolverInterface { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::pool'; + /** * @var GiftPoolManagementInterface */ @@ -46,18 +52,26 @@ class GiftPoolGenerate implements ResolverInterface */ private $helper; + /** + * @var Auth + */ + private $auth; + /** * AbstractResolver constructor. * * @param GiftPoolManagementInterface $giftPoolManagement * @param Data $helper + * @param Auth $auth */ public function __construct( GiftPoolManagementInterface $giftPoolManagement, - Data $helper + Data $helper, + Auth $auth ) { $this->giftPoolManagement = $giftPoolManagement; $this->helper = $helper; + $this->auth = $auth; } /** @@ -69,6 +83,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('The module is disabled')); } + if (!$this->auth->isAllowed($args['accessToken'], $this->_aclResource)) { + throw new GraphQlInputException(__("The consumer isn't authorized to access %1", $this->_aclResource)); + } + if ($args['pattern'] === '') { throw new GraphQlInputException(__('pattern value must not be empty.')); } diff --git a/Model/Resolver/Save/GiftCode.php b/Model/Resolver/Save/GiftCode.php index 78312ef..2a75765 100644 --- a/Model/Resolver/Save/GiftCode.php +++ b/Model/Resolver/Save/GiftCode.php @@ -29,5 +29,13 @@ */ class GiftCode extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::code'; + + /** + * @var string + */ protected $_type = 'mpGiftCode'; } diff --git a/Model/Resolver/Save/GiftPool.php b/Model/Resolver/Save/GiftPool.php index 9d3d053..bfdf8b3 100644 --- a/Model/Resolver/Save/GiftPool.php +++ b/Model/Resolver/Save/GiftPool.php @@ -29,5 +29,13 @@ */ class GiftPool extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::pool'; + + /** + * @var string + */ protected $_type = 'mpGiftPool'; } diff --git a/Model/Resolver/Save/GiftTemplate.php b/Model/Resolver/Save/GiftTemplate.php index 581590a..926b689 100644 --- a/Model/Resolver/Save/GiftTemplate.php +++ b/Model/Resolver/Save/GiftTemplate.php @@ -29,5 +29,13 @@ */ class GiftTemplate extends AbstractResolver { + /** + * @var string + */ + protected $_aclResource = 'Mageplaza_GiftCard::template'; + + /** + * @var string + */ protected $_type = 'mpGiftTemplate'; } diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 707127e..f8ce915 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -18,9 +18,11 @@ type Query { mpGiftCode ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), id: Int! @doc(description: "Specifies the gift code id to search for."), ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftCode") @doc(description: "Searches for an item that matches the id.") mpGiftCodeList ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), filter: GiftCodeFilterInput! @doc(description: "Identifies which fields to search for and return."), pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") @@ -45,41 +47,52 @@ type Query { type Mutation { mpGiftCodeSave ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), input: GiftCodeInput! @doc(description: "Specifies which fields to change. If 'giftcard_id' is presented, the gift code will be updated, otherwise create new gift code.") ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftCode") @doc(description: "Save gift code") mpGiftPoolSave ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), input: GiftPoolInput! @doc(description: "Specifies which fields to change. If 'pool_id' is presented, the gift pool will be updated, otherwise create new gift pool.") ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftPool") @doc(description: "Save gift pool") mpGiftTemplateSave ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), input: GiftTemplateInput! @doc(description: "Specifies which fields to change. If 'template_id' is presented, the gift template will be updated, otherwise create new gift template.") ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftTemplate") @doc(description: "Save gift template") mpGiftCodeDelete ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), id: Int! @doc(description: "Specifies the gift code id to search for and delete.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftCode") @doc(description: "Delete gift code") mpGiftPoolDelete ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), id: Int! @doc(description: "Specifies the gift pool id to search for and delete.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftPool") @doc(description: "Delete gift pool") mpGiftTemplateDelete ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), id: Int! @doc(description: "Specifies the gift template id to search for and delete.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftTemplate") @doc(description: "Delete gift template") mpGiftPoolGenerate ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), id: Int! @doc(description: "Specifies the gift template id to search for and generate."), pattern: String = "[4AN]-[4A]-[4N]" @doc(description: "Specifies the gift code pattern."), qty: Int = 1 @doc(description: "How many gift codes will be generated.") ): [String] @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPoolGenerate") @doc(description: "Generate gift code from gift pool") mpGiftCardSetCode ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), cartId: Int! @doc(description: "Specifies the quote id to search for and apply the gift code."), code: String! @doc(description: "Specifies what gift code will be applied.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCode") @doc(description: "Apply gift card code") mpGiftCardRemoveCode ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), cartId: Int! @doc(description: "Specifies the quote id to search for and remove the gift code."), code: String! @doc(description: "Specifies what gift code will be removed") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\RemoveGiftCode") @doc(description: "Remove gift card code") mpGiftCardSetCredit ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), cartId: Int! @doc(description: "Specifies the quote id to search for and set the gift credit."), amount: String! @doc(description: "Specifies how much gift credit will be applied.") ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCredit") @doc(description: "Apply gift credit amount") mpGiftCardRedeem ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), customerId: Int! @doc(description: "Specifies the customer id to search for and redeem the gift code."), code: String! @doc(description: "Specifies what gift code will be redeemed.") ): GiftCardRedeemDetail @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\Redeem") @doc(description: "Redeem gift card code for customer") From d09513ee9b7e4c47bf8d89abec72f549a6810822 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 26 Dec 2019 17:10:05 +0700 Subject: [PATCH 12/12] Clean code --- CHANGELOG | 1 + LICENSE | 33 +++ README.md | 4 +- USER-GUIDE.md | 55 ++++ composer.json | 23 ++ etc/di.xml | 64 ++--- etc/module.xml | 58 ++--- etc/schema.graphqls | 604 ++++++++++++++++++++++---------------------- i18n/en_US.csv | 7 + 9 files changed, 484 insertions(+), 365 deletions(-) create mode 100644 CHANGELOG create mode 100644 LICENSE create mode 100644 USER-GUIDE.md create mode 100644 composer.json create mode 100644 i18n/en_US.csv diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..6db0605 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1 @@ +CHANGELOG: https://www.mageplaza.com/releases/gift-card \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9e08325 --- /dev/null +++ b/LICENSE @@ -0,0 +1,33 @@ +Copyright © 2016-present Mageplaza Co. Ltd. + +This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services. + +By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products. + +The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time. + + 1. GRANT OF LICENSE: By purchasing a product of Mageplaza: + + 1. Customer will receive source code open 100%. + + 2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations. + + 3. You are allowed to customize our products to fit with your using purpose. + + 4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS + + 5. Installation and Use + + 6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom. + + 2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes. + + 3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone. + + 4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license. + + 5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License. + + 6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use. + +The latest License: https://www.mageplaza.com/LICENSE.txt \ No newline at end of file diff --git a/README.md b/README.md index d3f225c..5be56d5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# Gift Card GraphQl - +# Gift Card GraphQl + diff --git a/USER-GUIDE.md b/USER-GUIDE.md new file mode 100644 index 0000000..129411b --- /dev/null +++ b/USER-GUIDE.md @@ -0,0 +1,55 @@ +## Documentation + +- Installation guide: https://www.mageplaza.com/install-magento-2-extension/#solution-1-ready-to-paste +- User Guide: https://docs.mageplaza.com/gift-card/index.html +- Product page: https://www.mageplaza.com/magento-2-gift-card-extension/ +- FAQs: https://www.mageplaza.com/faqs/ +- Get Support: https://www.mageplaza.com/contact.html or support@mageplaza.com +- Changelog: https://www.mageplaza.com/releases/gift-card +- License agreement: https://www.mageplaza.com/LICENSE.txt + + +## How to install + +### Install ready-to-paste package (Recommended) + +- Installation guide: https://www.mageplaza.com/install-magento-2-extension/ + +## How to upgrade + +1. Backup + +Backup your Magento code, database before upgrading. + +2. Remove GiftCard folder + +In case of customization, you should backup the customized files and modify in newer version. +Now you remove `app/code/Mageplaza/GiftCard` folder. In this step, you can copy override GiftCard folder but this may cause of compilation issue. That why you should remove it. + +3. Upload new version +Upload this package to Magento root directory + +4. Run command line: + +``` +php bin/magento setup:upgrade +php bin/magento setup:static-content:deploy +``` + + +## FAQs + + +#### Q: I got error: `Mageplaza_Core has been already defined` +A: Read solution: https://github.com/mageplaza/module-core/issues/3 + + +#### Q: My site is down +A: Please follow this guide: https://www.mageplaza.com/blog/magento-site-down.html + + +## Support + +- FAQs: https://www.mageplaza.com/faqs/ +- https://mageplaza.freshdesk.com/ +- support@mageplaza.com diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ae376bd --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "mageplaza/module-gift-card-graphql", + "description": "Mageplaza Gift Card GraphQL Extension", + "type": "magento2-module", + "version": "1.0.0", + "license": "proprietary", + "authors": [ + { + "name": "Mageplaza", + "email": "support@mageplaza.com", + "homepage": "https://www.mageplaza.com", + "role": "Technical Support" + } + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Mageplaza\\GiftCardGraphQl\\": "" + } + } +} \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index 7a4e459..8d07025 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1,33 +1,33 @@ - - - - - - - Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument - Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument - Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument - - - + + + + + + + Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument + Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument + Mageplaza\GiftCardGraphQl\Model\Resolver\FilterArgument + + + \ No newline at end of file diff --git a/etc/module.xml b/etc/module.xml index 87a4b57..4b1b8df 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/etc/schema.graphqls b/etc/schema.graphqls index f8ce915..30ee5e9 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -1,303 +1,303 @@ -# 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 - -type Query { - mpGiftCode ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - id: Int! @doc(description: "Specifies the gift code id to search for."), - ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftCode") @doc(description: "Searches for an item that matches the id.") - mpGiftCodeList ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - filter: GiftCodeFilterInput! @doc(description: "Identifies which fields to search for and return."), - pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), - currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") - ): GiftCodeListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftCode") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") - mpGiftPool ( - id: Int! @doc(description: "Specifies the gift pool id to search for."), - ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftPool") @doc(description: "Searches for an item that matches the id.") - mpGiftPoolList ( - filter: GiftPoolFilterInput! @doc(description: "Identifies which fields to search for and return."), - pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), - currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") - ): GiftPoolListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftPool") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") - mpGiftTemplate ( - id: Int! @doc(description: "Specifies the gift template id to search for."), - ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftTemplate") @doc(description: "Searches for an item that matches the id.") - mpGiftTemplateList ( - filter: GiftTemplateFilterInput! @doc(description: "Identifies which fields to search for and return."), - pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), - currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") - ): GiftTemplateListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftTemplate") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") -} - -type Mutation { - mpGiftCodeSave ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - input: GiftCodeInput! @doc(description: "Specifies which fields to change. If 'giftcard_id' is presented, the gift code will be updated, otherwise create new gift code.") - ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftCode") @doc(description: "Save gift code") - mpGiftPoolSave ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - input: GiftPoolInput! @doc(description: "Specifies which fields to change. If 'pool_id' is presented, the gift pool will be updated, otherwise create new gift pool.") - ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftPool") @doc(description: "Save gift pool") - mpGiftTemplateSave ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - input: GiftTemplateInput! @doc(description: "Specifies which fields to change. If 'template_id' is presented, the gift template will be updated, otherwise create new gift template.") - ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftTemplate") @doc(description: "Save gift template") - mpGiftCodeDelete ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - id: Int! @doc(description: "Specifies the gift code id to search for and delete.") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftCode") @doc(description: "Delete gift code") - mpGiftPoolDelete ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - id: Int! @doc(description: "Specifies the gift pool id to search for and delete.") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftPool") @doc(description: "Delete gift pool") - mpGiftTemplateDelete ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - id: Int! @doc(description: "Specifies the gift template id to search for and delete.") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftTemplate") @doc(description: "Delete gift template") - mpGiftPoolGenerate ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - id: Int! @doc(description: "Specifies the gift template id to search for and generate."), - pattern: String = "[4AN]-[4A]-[4N]" @doc(description: "Specifies the gift code pattern."), - qty: Int = 1 @doc(description: "How many gift codes will be generated.") - ): [String] @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPoolGenerate") @doc(description: "Generate gift code from gift pool") - mpGiftCardSetCode ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - cartId: Int! @doc(description: "Specifies the quote id to search for and apply the gift code."), - code: String! @doc(description: "Specifies what gift code will be applied.") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCode") @doc(description: "Apply gift card code") - mpGiftCardRemoveCode ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - cartId: Int! @doc(description: "Specifies the quote id to search for and remove the gift code."), - code: String! @doc(description: "Specifies what gift code will be removed") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\RemoveGiftCode") @doc(description: "Remove gift card code") - mpGiftCardSetCredit ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - cartId: Int! @doc(description: "Specifies the quote id to search for and set the gift credit."), - amount: String! @doc(description: "Specifies how much gift credit will be applied.") - ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCredit") @doc(description: "Apply gift credit amount") - mpGiftCardRedeem ( - accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), - customerId: Int! @doc(description: "Specifies the customer id to search for and redeem the gift code."), - code: String! @doc(description: "Specifies what gift code will be redeemed.") - ): GiftCardRedeemDetail @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\Redeem") @doc(description: "Redeem gift card code for customer") -} - -input GiftCodeFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { - giftcard_id: FilterTypeInput - code: FilterTypeInput - pattern: FilterTypeInput - init_balance: FilterTypeInput - balance: FilterTypeInput - status: FilterTypeInput - can_redeem: FilterTypeInput - store_id: FilterTypeInput - pool_id: FilterTypeInput - template_id: FilterTypeInput - image: FilterTypeInput - template_fields: FilterTypeInput - customer_ids: FilterTypeInput - order_item_id: FilterTypeInput - order_increment_id: FilterTypeInput - delivery_method: FilterTypeInput - delivery_address: FilterTypeInput - is_sent: FilterTypeInput - delivery_date: FilterTypeInput - timezone: FilterTypeInput - extra_content: FilterTypeInput - expired_at: FilterTypeInput - created_at: FilterTypeInput -} - -input GiftPoolFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { - pool_id: FilterTypeInput - name: FilterTypeInput - status: FilterTypeInput - can_inherit: FilterTypeInput - pattern: FilterTypeInput - balance: FilterTypeInput - can_redeem: FilterTypeInput - store_id: FilterTypeInput - template_id: FilterTypeInput - image: FilterTypeInput - template_fields: FilterTypeInput - expired_at: FilterTypeInput - created_at: FilterTypeInput -} - -input GiftTemplateFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { - template_id: FilterTypeInput - name: FilterTypeInput - status: FilterTypeInput - can_upload: FilterTypeInput - title: FilterTypeInput - font_family: FilterTypeInput - background_image: FilterTypeInput - design: FilterTypeInput - note: FilterTypeInput - images: FilterTypeInput - created_at: FilterTypeInput -} - -input GiftCodeInput { - giftcard_id: Int @doc(description: "Gift card ID that is used to identify the gift card.") - pattern: String @doc(description: "Gift code pattern.") - init_balance: Float @doc(description: "Initial balance of the gift card.") - balance: Float @doc(description: "Current balance of the gift card.") - status: Int @doc(description: "Is the gift card enable?") - can_redeem: Int @doc(description: "Is the gift card redeemable?") - store_id: Int @doc(description: "Specifies which store the gift card is available at.") - pool_id: Int @doc(description: "Pool id that the gift code belongs to.") - template_id: Int @doc(description: "Template id that is used for the gift card.") - image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFieldsInput @doc(description: "Template fields.") - delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") - delivery_address: String @doc(description: "Delivery address that includes email or phone number.") - is_sent: Int @doc(description: "Is gift card sent to recipient?") - delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") - timezone: String @doc(description: "Timezone for the gift card delivery date.") - extra_content: String @doc(description: "Extra content.") - expired_at: String @doc(description: "The date that the gift code is expired.") -} - -input GiftPoolInput { - pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") - name: String @doc(description: "Gift pool name.") - status: Int @doc(description: "Gift card status.") - can_inherit: Int @doc(description: "Is the gift pool's properties applied for its gift cards?") - pattern: String @doc(description: "Gift code pattern.") - balance: Float @doc(description: "Balance of the gift cards that will bed generated.") - can_redeem: Int @doc(description: "Is the gift card redeemable?") - store_id: Int @doc(description: "Specifies which store the gift card is available at.") - template_id: Int @doc(description: "Template id that is used for the gift card.") - image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFieldsInput @doc(description: "Template fields.") - expired_at: String @doc(description: "The date that the gift code is expired.") -} - -input GiftTemplateInput { - template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") - name: String @doc(description: "Gift template name.") - status: Int @doc(description: "Gift template status.") - can_upload: Int @doc(description: "Can customers upload images when using this gift template?") - title: String @doc(description: "Gift card title.") - font_family: String @doc(description: "Font family for the content of the gift template.") - background_image: String @doc(description: "Background image") - design: String @doc(description: "CSS style") - note: String @doc(description: "Note that can be displayed on the gift template.") - images: String @doc(description: "Array contains relative path, label and position of images belonged to the gift template.") -} - -type GiftCodeListOutput { - total_count: Int @doc(description: "The number of items returned.") - items: [GiftCodeOutput] @doc(description: "An array of items that match the specified search criteria.") - page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") -} - -type GiftPoolListOutput { - total_count: Int @doc(description: "The number of items returned.") - items: [GiftPoolOutput] @doc(description: "An array of items that match the specified search criteria.") - page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") -} - -type GiftTemplateListOutput { - total_count: Int @doc(description: "The number of items returned.") - items: [GiftTemplateOutput] @doc(description: "An array of items that match the specified search criteria.") - page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") -} - -type GiftCodeOutput { - giftcard_id: Int @doc(description: "Gift card ID that is used to identify the gift card.") - code: String @doc(description: "Gift code") - pattern: String @doc(description: "Gift code pattern.") - init_balance: Float @doc(description: "Initial balance of the gift card.") - balance: Float @doc(description: "Current balance of the gift card.") - status: Int @doc(description: "Is the gift card enable?") - can_redeem: String @doc(description: "Is the gift card redeemable?") - store_id: Int @doc(description: "Specifies which store the gift card is available at.") - pool_id: Int @doc(description: "Pool id that the gift code belongs to.") - template_id: Int @doc(description: "Template id that is used for the gift card.") - image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFields @doc(description: "Template fields.") - customer_ids: String @doc(description: "Customers that redeemed the gift card") - order_item_id: Int @doc(description: "Specifies what gift card product generates the gift card.") - order_increment_id: Int @doc(description: "Specifies what order contains the gift card product.") - delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") - delivery_address: String @doc(description: "Delivery address that includes email or phone number.") - is_sent: Int @doc(description: "Is gift card sent to recipient?") - delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") - timezone: String @doc(description: "Timezone for the gift card delivery date.") - extra_content: String @doc(description: "Extra content.") - expired_at: String @doc(description: "The date that the gift code is expired.") - created_at: String @doc(description: "Timestamp indicating when the entity was created.") -} - -type GiftPoolOutput { - pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") - name: String @doc(description: "Gift pool name.") - status: Int @doc(description: "Gift card status.") - can_inherit: Int @doc(description: "Is the gift pool's properties applied for its gift cards?") - pattern: String @doc(description: "Gift code pattern.") - balance: Float @doc(description: "Balance of the gift cards that will bed generated.") - can_redeem: Int @doc(description: "Is the gift card redeemable?") - store_id: Int @doc(description: "Specifies which store the gift card is available at.") - template_id: Int @doc(description: "Template id that is used for the gift card.") - image: String @doc(description: "Relative image path.") - template_fields: GiftCardTemplateFields @doc(description: "Template fields.") - expired_at: String @doc(description: "The date that the gift code is expired.") - created_at: String @doc(description: "Timestamp indicating when the entity was created.") -} - -type GiftTemplateOutput { - template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") - name: String @doc(description: "Gift template name.") - status: Int @doc(description: "Gift template status.") - can_upload: String @doc(description: "Can customers upload images when using this gift template?") - title: String @doc(description: "Gift card title.") - font_family: String @doc(description: "Font family for the content of the gift template.") - background_image: String @doc(description: "Background image") - design: String @doc(description: "CSS style") - note: String @doc(description: "Note that can be displayed on the gift template.") - images: String @doc(description: "Array contains relative path, label and position of images belonged to the gift template.") - created_at: String @doc(description: "Timestamp indicating when the entity was created.") -} - -input GiftCardTemplateFieldsInput { - sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") - recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") - message: String @doc(description: "Message that is displayed on the gift card.") -} - -type GiftCardTemplateFields { - sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") - recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") - message: String @doc(description: "Message that is displayed on the gift card.") -} - -type GiftCardRedeemDetail { - customer_balance: String @doc(description: "Customer's balance after redeeming gift code.") -} - -type PageInfo { - pageSize: Int @doc(description: "How many items should show on the page.") - currentPage: Int @doc(description: "Specifies which page of results to return.") - hasNextPage: Boolean @doc(description: "Has next page.") - hasPreviousPage: Boolean @doc(description: "Has previous page.") - startPage: Int @doc(description: "Start page.") - endPage: Int @doc(description: "End page.") +# 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 + +type Query { + mpGiftCode ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + id: Int! @doc(description: "Specifies the gift code id to search for."), + ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftCode") @doc(description: "Searches for an item that matches the id.") + mpGiftCodeList ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + filter: GiftCodeFilterInput! @doc(description: "Identifies which fields to search for and return."), + pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") + ): GiftCodeListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftCode") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") + mpGiftPool ( + id: Int! @doc(description: "Specifies the gift pool id to search for."), + ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftPool") @doc(description: "Searches for an item that matches the id.") + mpGiftPoolList ( + filter: GiftPoolFilterInput! @doc(description: "Identifies which fields to search for and return."), + pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") + ): GiftPoolListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftPool") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") + mpGiftTemplate ( + id: Int! @doc(description: "Specifies the gift template id to search for."), + ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Get\\GiftTemplate") @doc(description: "Searches for an item that matches the id.") + mpGiftTemplateList ( + filter: GiftTemplateFilterInput! @doc(description: "Identifies which fields to search for and return."), + pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. The default value is 20."), + currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.") + ): GiftTemplateListOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GetList\\GiftTemplate") @doc(description: "Searches for items that match the criteria specified in the search and filter attributes.") +} + +type Mutation { + mpGiftCodeSave ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + input: GiftCodeInput! @doc(description: "Specifies which fields to change. If 'giftcard_id' is presented, the gift code will be updated, otherwise create new gift code.") + ): GiftCodeOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftCode") @doc(description: "Save gift code") + mpGiftPoolSave ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + input: GiftPoolInput! @doc(description: "Specifies which fields to change. If 'pool_id' is presented, the gift pool will be updated, otherwise create new gift pool.") + ): GiftPoolOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftPool") @doc(description: "Save gift pool") + mpGiftTemplateSave ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + input: GiftTemplateInput! @doc(description: "Specifies which fields to change. If 'template_id' is presented, the gift template will be updated, otherwise create new gift template.") + ): GiftTemplateOutput @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Save\\GiftTemplate") @doc(description: "Save gift template") + mpGiftCodeDelete ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + id: Int! @doc(description: "Specifies the gift code id to search for and delete.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftCode") @doc(description: "Delete gift code") + mpGiftPoolDelete ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + id: Int! @doc(description: "Specifies the gift pool id to search for and delete.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftPool") @doc(description: "Delete gift pool") + mpGiftTemplateDelete ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + id: Int! @doc(description: "Specifies the gift template id to search for and delete.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\Delete\\GiftTemplate") @doc(description: "Delete gift template") + mpGiftPoolGenerate ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + id: Int! @doc(description: "Specifies the gift template id to search for and generate."), + pattern: String = "[4AN]-[4A]-[4N]" @doc(description: "Specifies the gift code pattern."), + qty: Int = 1 @doc(description: "How many gift codes will be generated.") + ): [String] @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftPoolGenerate") @doc(description: "Generate gift code from gift pool") + mpGiftCardSetCode ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + cartId: Int! @doc(description: "Specifies the quote id to search for and apply the gift code."), + code: String! @doc(description: "Specifies what gift code will be applied.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCode") @doc(description: "Apply gift card code") + mpGiftCardRemoveCode ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + cartId: Int! @doc(description: "Specifies the quote id to search for and remove the gift code."), + code: String! @doc(description: "Specifies what gift code will be removed") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\RemoveGiftCode") @doc(description: "Remove gift card code") + mpGiftCardSetCredit ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + cartId: Int! @doc(description: "Specifies the quote id to search for and set the gift credit."), + amount: String! @doc(description: "Specifies how much gift credit will be applied.") + ): Boolean @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\SetGiftCredit") @doc(description: "Apply gift credit amount") + mpGiftCardRedeem ( + accessToken: String! @doc(description: "Oauth access token that is needed to make requests."), + customerId: Int! @doc(description: "Specifies the customer id to search for and redeem the gift code."), + code: String! @doc(description: "Specifies what gift code will be redeemed.") + ): GiftCardRedeemDetail @resolver(class: "Mageplaza\\GiftCardGraphQl\\Model\\Resolver\\GiftCard\\Redeem") @doc(description: "Redeem gift card code for customer") +} + +input GiftCodeFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + giftcard_id: FilterTypeInput + code: FilterTypeInput + pattern: FilterTypeInput + init_balance: FilterTypeInput + balance: FilterTypeInput + status: FilterTypeInput + can_redeem: FilterTypeInput + store_id: FilterTypeInput + pool_id: FilterTypeInput + template_id: FilterTypeInput + image: FilterTypeInput + template_fields: FilterTypeInput + customer_ids: FilterTypeInput + order_item_id: FilterTypeInput + order_increment_id: FilterTypeInput + delivery_method: FilterTypeInput + delivery_address: FilterTypeInput + is_sent: FilterTypeInput + delivery_date: FilterTypeInput + timezone: FilterTypeInput + extra_content: FilterTypeInput + expired_at: FilterTypeInput + created_at: FilterTypeInput +} + +input GiftPoolFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + pool_id: FilterTypeInput + name: FilterTypeInput + status: FilterTypeInput + can_inherit: FilterTypeInput + pattern: FilterTypeInput + balance: FilterTypeInput + can_redeem: FilterTypeInput + store_id: FilterTypeInput + template_id: FilterTypeInput + image: FilterTypeInput + template_fields: FilterTypeInput + expired_at: FilterTypeInput + created_at: FilterTypeInput +} + +input GiftTemplateFilterInput @doc(description: "Defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") { + template_id: FilterTypeInput + name: FilterTypeInput + status: FilterTypeInput + can_upload: FilterTypeInput + title: FilterTypeInput + font_family: FilterTypeInput + background_image: FilterTypeInput + design: FilterTypeInput + note: FilterTypeInput + images: FilterTypeInput + created_at: FilterTypeInput +} + +input GiftCodeInput { + giftcard_id: Int @doc(description: "Gift card ID that is used to identify the gift card.") + pattern: String @doc(description: "Gift code pattern.") + init_balance: Float @doc(description: "Initial balance of the gift card.") + balance: Float @doc(description: "Current balance of the gift card.") + status: Int @doc(description: "Is the gift card enable?") + can_redeem: Int @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + pool_id: Int @doc(description: "Pool id that the gift code belongs to.") + template_id: Int @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: GiftCardTemplateFieldsInput @doc(description: "Template fields.") + delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") + delivery_address: String @doc(description: "Delivery address that includes email or phone number.") + is_sent: Int @doc(description: "Is gift card sent to recipient?") + delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") + timezone: String @doc(description: "Timezone for the gift card delivery date.") + extra_content: String @doc(description: "Extra content.") + expired_at: String @doc(description: "The date that the gift code is expired.") +} + +input GiftPoolInput { + pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") + name: String @doc(description: "Gift pool name.") + status: Int @doc(description: "Gift card status.") + can_inherit: Int @doc(description: "Is the gift pool's properties applied for its gift cards?") + pattern: String @doc(description: "Gift code pattern.") + balance: Float @doc(description: "Balance of the gift cards that will bed generated.") + can_redeem: Int @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + template_id: Int @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: GiftCardTemplateFieldsInput @doc(description: "Template fields.") + expired_at: String @doc(description: "The date that the gift code is expired.") +} + +input GiftTemplateInput { + template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") + name: String @doc(description: "Gift template name.") + status: Int @doc(description: "Gift template status.") + can_upload: Int @doc(description: "Can customers upload images when using this gift template?") + title: String @doc(description: "Gift card title.") + font_family: String @doc(description: "Font family for the content of the gift template.") + background_image: String @doc(description: "Background image") + design: String @doc(description: "CSS style") + note: String @doc(description: "Note that can be displayed on the gift template.") + images: String @doc(description: "Array contains relative path, label and position of images belonged to the gift template.") +} + +type GiftCodeListOutput { + total_count: Int @doc(description: "The number of items returned.") + items: [GiftCodeOutput] @doc(description: "An array of items that match the specified search criteria.") + page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") +} + +type GiftPoolListOutput { + total_count: Int @doc(description: "The number of items returned.") + items: [GiftPoolOutput] @doc(description: "An array of items that match the specified search criteria.") + page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") +} + +type GiftTemplateListOutput { + total_count: Int @doc(description: "The number of items returned.") + items: [GiftTemplateOutput] @doc(description: "An array of items that match the specified search criteria.") + page_info: PageInfo @doc(description: "An object that includes the pageSize and currentPage values specified in the query.") +} + +type GiftCodeOutput { + giftcard_id: Int @doc(description: "Gift card ID that is used to identify the gift card.") + code: String @doc(description: "Gift code") + pattern: String @doc(description: "Gift code pattern.") + init_balance: Float @doc(description: "Initial balance of the gift card.") + balance: Float @doc(description: "Current balance of the gift card.") + status: Int @doc(description: "Is the gift card enable?") + can_redeem: String @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + pool_id: Int @doc(description: "Pool id that the gift code belongs to.") + template_id: Int @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: GiftCardTemplateFields @doc(description: "Template fields.") + customer_ids: String @doc(description: "Customers that redeemed the gift card") + order_item_id: Int @doc(description: "Specifies what gift card product generates the gift card.") + order_increment_id: Int @doc(description: "Specifies what order contains the gift card product.") + delivery_method: String @doc(description: "Delivery methods, values: 1 - Email, 2 - Text Message, 3 - Print At Home, 4 - Post Office.") + delivery_address: String @doc(description: "Delivery address that includes email or phone number.") + is_sent: Int @doc(description: "Is gift card sent to recipient?") + delivery_date: String @doc(description: "The date that the sender wants the gift card to be sent.") + timezone: String @doc(description: "Timezone for the gift card delivery date.") + extra_content: String @doc(description: "Extra content.") + expired_at: String @doc(description: "The date that the gift code is expired.") + created_at: String @doc(description: "Timestamp indicating when the entity was created.") +} + +type GiftPoolOutput { + pool_id: Int @doc(description: "Gift pool ID that is used to identify the gift pool.") + name: String @doc(description: "Gift pool name.") + status: Int @doc(description: "Gift card status.") + can_inherit: Int @doc(description: "Is the gift pool's properties applied for its gift cards?") + pattern: String @doc(description: "Gift code pattern.") + balance: Float @doc(description: "Balance of the gift cards that will bed generated.") + can_redeem: Int @doc(description: "Is the gift card redeemable?") + store_id: Int @doc(description: "Specifies which store the gift card is available at.") + template_id: Int @doc(description: "Template id that is used for the gift card.") + image: String @doc(description: "Relative image path.") + template_fields: GiftCardTemplateFields @doc(description: "Template fields.") + expired_at: String @doc(description: "The date that the gift code is expired.") + created_at: String @doc(description: "Timestamp indicating when the entity was created.") +} + +type GiftTemplateOutput { + template_id: Int @doc(description: "Gift template ID that is used to identify the gift template.") + name: String @doc(description: "Gift template name.") + status: Int @doc(description: "Gift template status.") + can_upload: String @doc(description: "Can customers upload images when using this gift template?") + title: String @doc(description: "Gift card title.") + font_family: String @doc(description: "Font family for the content of the gift template.") + background_image: String @doc(description: "Background image") + design: String @doc(description: "CSS style") + note: String @doc(description: "Note that can be displayed on the gift template.") + images: String @doc(description: "Array contains relative path, label and position of images belonged to the gift template.") + created_at: String @doc(description: "Timestamp indicating when the entity was created.") +} + +input GiftCardTemplateFieldsInput { + sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") + recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") + message: String @doc(description: "Message that is displayed on the gift card.") +} + +type GiftCardTemplateFields { + sender: String @doc(description: "Sender who gifts the gift card. This sender's name will be displayed on the gift card.") + recipient: String @doc(description: "Recipient who receives the gift card. This recipient's name will be displayed on the gift card.") + message: String @doc(description: "Message that is displayed on the gift card.") +} + +type GiftCardRedeemDetail { + customer_balance: String @doc(description: "Customer's balance after redeeming gift code.") +} + +type PageInfo { + pageSize: Int @doc(description: "How many items should show on the page.") + currentPage: Int @doc(description: "Specifies which page of results to return.") + hasNextPage: Boolean @doc(description: "Has next page.") + hasPreviousPage: Boolean @doc(description: "Has previous page.") + startPage: Int @doc(description: "Start page.") + endPage: Int @doc(description: "End page.") } \ No newline at end of file diff --git a/i18n/en_US.csv b/i18n/en_US.csv new file mode 100644 index 0000000..1b947db --- /dev/null +++ b/i18n/en_US.csv @@ -0,0 +1,7 @@ +"The module is disabled","The module is disabled" +"The consumer isn't authorized to access %1","The consumer isn't authorized to access %1" +"currentPage value must be greater than 0.","currentPage value must be greater than 0." +"pageSize value must be greater than 0.","pageSize value must be greater than 0." +"currentPage value %1 specified is greater than the %2 page(s) available.","currentPage value %1 specified is greater than the %2 page(s) available." +"pattern value must not be empty.","pattern value must not be empty." +"qty value must be greater than 0.","qty value must be greater than 0."