diff --git a/Model/Resolver/CreateReview.php b/Model/Resolver/CreateReview.php index 6ab50d9..0453fb1 100644 --- a/Model/Resolver/CreateReview.php +++ b/Model/Resolver/CreateReview.php @@ -23,7 +23,6 @@ namespace Mageplaza\BetterProductReviewsGraphQl\Model\Resolver; -use Exception; use Magento\Catalog\Model\Product; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\Exception\LocalizedException; @@ -31,17 +30,20 @@ use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Magento\Review\Model\Rating; +use Magento\Review\Model\Rating\Option; use Magento\Review\Model\RatingFactory; use Magento\Review\Model\Review; use Magento\Review\Model\ReviewFactory; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Item; use Magento\Sales\Model\OrderFactory; +use Magento\Store\Model\StoreManagerInterface; use Mageplaza\BetterProductReviews\Helper\Data; +use Mageplaza\BetterProductReviews\Model\Config\Source\BuyerType; use Mageplaza\BetterProductReviews\Model\Config\Source\System\CustomerRestriction; /** @@ -80,6 +82,11 @@ class CreateReview implements ResolverInterface */ protected $_orderFactory; + /** + * @var StoreManagerInterface + */ + protected $storeManager; + /** * CreateReview constructor. * @@ -87,6 +94,7 @@ class CreateReview implements ResolverInterface * @param Product $productModel * @param CustomerRepositoryInterface $customerRepositoryInterface * @param Data $helperData + * @param StoreManagerInterface $storeManager * @param OrderFactory $orderFactory * @param ReviewFactory $reviewFactory */ @@ -95,6 +103,7 @@ public function __construct( Product $productModel, CustomerRepositoryInterface $customerRepositoryInterface, Data $helperData, + StoreManagerInterface $storeManager, OrderFactory $orderFactory, ReviewFactory $reviewFactory ) { @@ -102,21 +111,13 @@ public function __construct( $this->_review = $reviewFactory; $this->_product = $productModel; $this->_orderFactory = $orderFactory; + $this->storeManager = $storeManager; $this->_helperData = $helperData; $this->_customerRepositoryInterface = $customerRepositoryInterface; } /** - * Fetches the data from persistence models and format it according to the GraphQL schema. - * - * @param Field $field - * @param ContextInterface $context - * @param ResolveInfo $info - * @param array|null $value - * @param array|null $args - * - * @return mixed|Value - * @throws Exception + * @inheritdoc */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { @@ -131,21 +132,29 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('The Product does not exit.')); } - $storeId = isset($data['store_id']) ? $data['store_id'] : 1; - $customerId = $this->isUserGuest($context->getUserId(), $productId); - $avgValue = isset($data['avg_value']) ? (int) $data['avg_value'] : 5; + $storeId = $this->storeManager->getStore()->getId(); + $customerId = $context->getUserId() ?: null; + $avgValue = (int) $data['avg_value']; + + if ($this->isUserGuest($customerId, $productId) === false) { + $noticeMessage = $this->_helperData->getWriteReviewConfig('notice_message') ?? __('The current customer isn\'t authorized.'); + throw new GraphQlAuthorizationException($noticeMessage); + } - if ($customerId === false || $avgValue > 5 || $avgValue <= 0) { - throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.')); + if ($avgValue > 5 || $avgValue <= 0) { + throw new GraphQlAuthorizationException(__('The avg_value value must be between 0 and 5.')); } - $status = isset($data['status_id']) ? $data['status_id'] : Review::STATUS_PENDING; - $ratings = $this->getRatingCollection($storeId); - $object = $this->_review->create()->setData($data); - $object->unsetData('review_id'); + $status = isset($data['status_id']) ? $data['status_id'] : Review::STATUS_PENDING; + $data['mp_bpr_verified_buyer'] = $this->checkIsBuyer($customerId, $productId) + ? BuyerType::VERIFIED_BUYER : BuyerType::NOT_VERIFIED_BUYER; + $ratings = $this->getRatingCollection($storeId); + /** @var \Magento\Review\Model\Review $reviewModel */ + $reviewModel = $this->_review->create()->setData($data); + $reviewModel->unsetData('review_id'); - if ($object->validate()) { - $object->setEntityId($object->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE)) + if ($reviewModel->validate()) { + $reviewModel->setEntityId($reviewModel->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE)) ->setEntityPkValue($productId) ->setStatusId($status) ->setCustomerId($customerId) @@ -153,18 +162,20 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value ->setStores([$storeId]) ->save(); foreach ($ratings as $ratingId => $rating) { + /** @var Rating $rating */ foreach ($rating->getOptions() as $option) { + /** @var Option $option */ if ((int) $option->getValue() === $avgValue) { $this->_rating->create() ->setRatingId($ratingId) - ->setReviewId($object->getId()) + ->setReviewId($reviewModel->getId()) ->setCustomerId($customerId) ->addOptionVote($option->getId(), $productId); } } } - $object->aggregate(); - $collection = $object->getCollection(); + $reviewModel->aggregate(); + $collection = $reviewModel->getCollection(); $collection->getSelect()->join( ['mp_detail' => $collection->getTable('review_detail')], 'main_table.review_id = mp_detail.review_id', @@ -173,7 +184,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value ['mp_vote' => $collection->getTable('rating_option_vote')], 'main_table.review_id = mp_vote.review_id', ['avg_value' => 'mp_vote.value'] - )->where('main_table.review_id = ?', $object->getId())->group('main_table.review_id'); + )->where('main_table.review_id = ?', $reviewModel->getId()) + ->group('main_table.review_id') + ->limit(1); return $collection->getFirstItem(); } @@ -184,10 +197,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value /** * @param $storeId * - * @return mixed - * @throws LocalizedException + * @return AbstractCollection */ - public function getRatingCollection($storeId) + public function getRatingCollection($storeId): AbstractCollection { return $this->_rating->create()->getResourceCollection()->addEntityFilter( 'product' @@ -201,24 +213,24 @@ public function getRatingCollection($storeId) } /** - * @param $currentUserId + * @param string $currentUserId * @param $productId * - * @return bool|null + * @return bool * @throws LocalizedException */ - public function isUserGuest($currentUserId, $productId) + public function isUserGuest($currentUserId, $productId): bool { if ($this->_helperData->isEnabled() && $this->isEnableWrite($currentUserId, $productId)) { - $mpGroupArray = explode(',', $this->_helperData->getWriteReviewConfig('customer_group')); + $allowCustomerGroup = explode(',', $this->_helperData->getWriteReviewConfig('customer_group')); try { $customerGroup = $this->_customerRepositoryInterface->getById($currentUserId)->getGroupId(); } catch (NoSuchEntityException $exception) { $customerGroup = '0'; } - if (in_array($customerGroup, $mpGroupArray, true)) { - return $currentUserId ?: null; + if (in_array($customerGroup, $allowCustomerGroup, true)) { + return true; } } @@ -231,14 +243,8 @@ public function isUserGuest($currentUserId, $productId) * * @return bool */ - public function isEnableWrite($customerId, $productId) + protected function checkIsBuyer($customerId, $productId): bool { - if ((int) $this->_helperData->getWriteReviewConfig('enabled') !== CustomerRestriction::PURCHASERS_ONLY) { - return (bool) $this->_helperData->getWriteReviewConfig('enabled'); - } - - $result = false; - if ($customerId) { $orders = $this->_orderFactory->create()->getCollection() ->addFieldToFilter('customer_id', $customerId) @@ -249,14 +255,28 @@ public function isEnableWrite($customerId, $productId) */ foreach ($order->getAllVisibleItems() as $item) { /** @var Item $item */ - if ($productId == $item->getProductId()) { - $result = true; - break; + if ($productId === (int) $item->getProductId()) { + return true; } } } } - return $result; + return false; + } + + /** + * @param $customerId + * @param $productId + * + * @return bool + */ + public function isEnableWrite($customerId, $productId): bool + { + if ((int) $this->_helperData->getWriteReviewConfig('enabled') !== CustomerRestriction::PURCHASERS_ONLY) { + return (bool) $this->_helperData->getWriteReviewConfig('enabled'); + } + + return $this->checkIsBuyer($customerId, $productId); } } diff --git a/Model/Resolver/Filter/DataProvider/Review.php b/Model/Resolver/Filter/DataProvider/Review.php index ea1cf69..f79ea93 100644 --- a/Model/Resolver/Filter/DataProvider/Review.php +++ b/Model/Resolver/Filter/DataProvider/Review.php @@ -23,13 +23,13 @@ namespace Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\DataProvider; -use Magento\Catalog\Api\Data\ProductSearchResultsInterfaceFactory; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaInterface; -use Magento\Framework\Api\SearchResultsInterface; use Mageplaza\BetterProductReviews\Helper\Data; -use Mageplaza\BetterProductReviews\Model\ResourceModel\Review\CollectionFactory; use Mageplaza\Blog\Model\ResourceModel\Post\Collection; +use Mageplaza\BetterProductReviews\Model\ResourceModel\Review\CollectionFactory; +use Magento\Catalog\Api\Data\ProductSearchResultsInterfaceFactory; +use Magento\Framework\Api\SearchResultsInterface; /** * Product field data provider, used for GraphQL resolver processing. diff --git a/Model/Resolver/Filter/Query/Filter.php b/Model/Resolver/Filter/Query/Filter.php index 5dafa59..40b2062 100644 --- a/Model/Resolver/Filter/Query/Filter.php +++ b/Model/Resolver/Filter/Query/Filter.php @@ -24,11 +24,11 @@ namespace Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\Query; use Magento\Framework\Api\SearchCriteriaInterface; -use Magento\Review\Model\Review as ReviewModel; use Mageplaza\BetterProductReviews\Helper\Data; -use Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\DataProvider\Review; use Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\SearchResult; use Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\SearchResultFactory; +use Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\DataProvider\Review; +use Magento\Review\Model\Review as ReviewModel; /** * Retrieve filtered product data based off given search criteria in a format that GraphQL can interpret. diff --git a/Model/Resolver/Filter/SearchResult.php b/Model/Resolver/Filter/SearchResult.php index 2d6f28d..76e3e8f 100644 --- a/Model/Resolver/Filter/SearchResult.php +++ b/Model/Resolver/Filter/SearchResult.php @@ -46,7 +46,7 @@ class SearchResult */ public function __construct(int $totalCount, array $itemsSearchResult) { - $this->totalCount = $totalCount; + $this->totalCount = $totalCount; $this->itemsSearchResult = $itemsSearchResult; } @@ -55,7 +55,7 @@ public function __construct(int $totalCount, array $itemsSearchResult) * * @return int */ - public function getTotalCount(): int + public function getTotalCount() : int { return $this->totalCount; } @@ -65,7 +65,7 @@ public function getTotalCount(): int * * @return array */ - public function getItemsSearchResult(): array + public function getItemsSearchResult() : array { return $this->itemsSearchResult; } diff --git a/Model/Resolver/Filter/SearchResultFactory.php b/Model/Resolver/Filter/SearchResultFactory.php index 4d27aab..3e457f0 100644 --- a/Model/Resolver/Filter/SearchResultFactory.php +++ b/Model/Resolver/Filter/SearchResultFactory.php @@ -48,10 +48,9 @@ public function __construct(ObjectManagerInterface $objectManager) * * @param int $totalCount * @param array $itemsSearchResult - * * @return SearchResult */ - public function create(int $totalCount, array $itemsSearchResult): SearchResult + public function create(int $totalCount, array $itemsSearchResult) : SearchResult { return $this->objectManager->create( SearchResult::class, diff --git a/Model/Resolver/Review/Product.php b/Model/Resolver/Review/Product.php index 4eb9f0b..59d0904 100644 --- a/Model/Resolver/Review/Product.php +++ b/Model/Resolver/Review/Product.php @@ -27,6 +27,7 @@ use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\SearchResultFactory; /** * Class Topic @@ -39,15 +40,23 @@ class Product implements ResolverInterface */ protected $_product; + /** + * @var SearchResultFactory + */ + protected $searchResultFactory; + /** * Product constructor. * * @param ProductModel $product + * @param SearchResultFactory $searchResultFactory */ public function __construct( - ProductModel $product + ProductModel $product, + SearchResultFactory $searchResultFactory ) { - $this->_product = $product; + $this->_product = $product; + $this->searchResultFactory = $searchResultFactory; } /** @@ -55,8 +64,14 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - $productId = $value['entity_pk_value']; + $productId = $value['entity_pk_value']; + $product = $this->_product->load($productId); + $listArray = []; + $listArray[$productId] = $product->getData(); + $listArray[$productId]['model'] = $product; + + $searchResult = $this->searchResultFactory->create(1, $listArray); - return $this->_product->load($productId); + return $searchResult->getItemsSearchResult()[$productId]; } } diff --git a/Model/Resolver/Review/Review.php b/Model/Resolver/Review/Review.php new file mode 100644 index 0000000..fdfda8a --- /dev/null +++ b/Model/Resolver/Review/Review.php @@ -0,0 +1,122 @@ +_product = $product; + $this->reviewCollection = $reviewCollection; + $this->_helperData = $_helperData; + $this->filterQuery = $filterQuery; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + $productId = $value['entity_id']; + $searchCriteria = $this->searchCriteriaBuilder->build('reviews', $args); + $searchCriteria->setCurrentPage(1); + $searchCriteria->setPageSize(10); + + $collection = $this->getReviewCollection(); + $collection->addFieldToFilter('main_table.entity_pk_value', $productId); + + $searchResult = $this->filterQuery->getResult($searchCriteria, $collection); + + return [ + 'total_count' => $searchResult->getTotalCount(), + 'items' => $searchResult->getItemsSearchResult() + ]; + } + + /** + * @return Collection + */ + protected function getReviewCollection(): Collection + { + $collection = $this->reviewCollection->create()->addReviewDetailTable()->addAverageVotingTable(); + if ($this->_helperData->getReviewListingConfig('store_owner_answer')) { + $collection->addReviewReplyTable(); + } + + return $collection; + } +} diff --git a/Model/Resolver/Reviews.php b/Model/Resolver/Reviews.php index 174de66..e385890 100644 --- a/Model/Resolver/Reviews.php +++ b/Model/Resolver/Reviews.php @@ -29,10 +29,10 @@ use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -use Mageplaza\BetterProductReviews\Helper\Data; use Mageplaza\BetterProductReviews\Model\ResourceModel\Review\Collection; use Mageplaza\BetterProductReviews\Model\ResourceModel\Review\CollectionFactory; use Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\Filter\Query\Filter; +use Mageplaza\BetterProductReviews\Helper\Data; /** * Class Reviews @@ -171,7 +171,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value * @return Collection * @throws GraphQlInputException */ - protected function getViewReview($args) + protected function getViewReview($args) : Collection { if (!isset($args['reviewId'])) { throw new GraphQlInputException(__('reviewId value is not null')); @@ -188,7 +188,7 @@ protected function getViewReview($args) * @return Collection * @throws GraphQlInputException */ - protected function getByProductId($args) + protected function getByProductId($args) : Collection { if (!isset($args['productId'])) { throw new GraphQlInputException(__('productId value is not null')); @@ -211,7 +211,7 @@ protected function getByProductId($args) * @return Collection * @throws GraphQlInputException */ - protected function getByProductSku($args) + protected function getByProductSku($args) : Collection { if (!isset($args['productSku'])) { throw new GraphQlInputException(__('Action value is not null')); @@ -234,7 +234,7 @@ protected function getByProductSku($args) * @return Collection * @throws GraphQlInputException */ - protected function getByCustomerId($args) + protected function getByCustomerId($args) : Collection { if (!isset($args['customerId'])) { throw new GraphQlInputException(__('customerId value is not null')); @@ -254,7 +254,7 @@ protected function getByCustomerId($args) /** * @return Collection */ - protected function getReviewCollection() + protected function getReviewCollection() : Collection { $collection = $this->reviewCollection->create()->addReviewDetailTable()->addAverageVotingTable(); if ($this->_helperData->getReviewListingConfig('store_owner_answer')) { diff --git a/composer.json b/composer.json index 4183ea8..2b36c36 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mageplaza/module-better-product-reviews-graphql", "description": "Magento 2 Better Product Reviews GraphQl Extension", "type": "magento2-module", - "version": "1.0.0", + "version": "1.0.1", "license": "proprietary", "authors": [ { diff --git a/etc/di.xml b/etc/di.xml index b86fd02..b101b8b 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -1,33 +1,33 @@ - - - - - - - - \Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\FilterArgument - - - - - + + + + + + + + Mageplaza\BetterProductReviewsGraphQl\Model\Resolver\FilterArgument + + + + + diff --git a/etc/module.xml b/etc/module.xml index 53a7f43..3416cfe 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,30 +1,30 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/etc/schema.graphqls b/etc/schema.graphqls index af9f4c6..6c030e3 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -1,125 +1,130 @@ -# 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_BetterProductReviewsGraphQl -# @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) -# @license https://www.mageplaza.com/LICENSE.txt - -type Query { - mpBprGetReview( - action: String! @doc(description: "Action in query.") - filter: ReviewsFilterInput @doc(description: "Identifies which product attributes to search for and return.") - reviewId: Int @doc(description: "Review ID use in the filter. Apply when action is get_view_review.") - productId: Int @doc(description: "Product ID use in the filter. Apply when action is get_by_productId.") - productSku: String @doc(description: "Product Sku use in the filter. Apply when action is get_by_productSku.") - customerId: Int @doc(description: "Customer ID use in the filter. Apply when action is get_by_customerId.") - pageSize: Int = 10 @doc(description: "How many items should show on the page.") - currentPage: Int = 1 @doc(description: "Allows to using paging it start with 1.") - ):ReviewsOutput @resolver(class: "\\Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\Reviews") @doc(description: "The mpBprGetReview query searches for review that match the criteria specified in the filter.") -} - -type Mutation { - mpBprCreateReview ( - input: ReviewInput! - productId: Int! @doc(description: "Product ID used to add reviews.") - ): NewReview @resolver(class: "\\Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\CreateReview") @doc(description:"Create a new Review") -} - -input ReviewsFilterInput { - created_at: FilterTypeInput @doc(description: "Timestamp indicating when the post was created."), - entity_id: FilterTypeInput @doc(description: "The Entity ID."), - status_id: FilterTypeInput @doc(description: "Status code."), - detail_id: FilterTypeInput @doc(description: "Review detail ID."), - title: FilterTypeInput @doc(description: "Review title."), - nickname: FilterTypeInput @doc(description: "User nickname"), - mp_bpr_helpful: FilterTypeInput @doc(description: "Mageplaza BPR Helpful.") -} -input ReviewInput { - title: String! @doc(description: "Review title."), - detail: String! @doc(description: "Review detail."), - nickname: String! @doc(description: "User nickname."), - mp_bpr_images: String @doc(description: "Mageplaza BPR Review Images (Json)."), - mp_bpr_recommended_product: String @doc(description: "Mageplaza BPR Recommended Product."), - mp_bpr_verified_buyer: String @doc(description: "Mageplaza BPR Verified Buyer."), - mp_bpr_helpful: Int @doc(description: "Mageplaza BPR Helpful."), - avg_value: String! @doc(description: "Average summaried rating.") -} - - -type ReviewsOutput { - total_count: Int @doc(description: "The number of posts returned."), - items: [Review] @doc(description: "An array of post that match the specified search criteria.") - pageInfo: PageInfo @doc(description: "An object that includes the page_info and currentPage values specified in the query.") -} - -type PageInfo { - pageSize: Int @doc(description: "How many items should show on the page.") - currentPage: Int @doc(description: "Allow page number to start with 1.") - hasNextPage: Boolean @doc(description: "Is next page") - hasPreviousPage: Boolean @doc(description: "Is previous page") - startPage: Int @doc(description: "Start page") - endPage: Int @doc(description: "End page") -} - -type Review { - review_id: Int @doc(description: "An ID that uniquely identifies the review."), - created_at: String @doc(description: "Timestamp indicating when the category was created."), - entity_id: Int @doc(description: "Review entity ID."), - entity_pk_value: Int @doc(description: "An ID that identifies the product."), - status_id: Int @doc(description: "An ID that identifies the status."), - detail_id: Int @doc(description: "An ID that identifies the review detail."), - title: String @doc(description: "The title of the review."), - detail: String @doc(description: "The detail of the review."), - nickname: String @doc(description: "The nickname of the reviewer."), - customer_id: Int @doc(description: "An ID that identifies the customer."), - mp_bpr_images: String @doc(description: "Mageplaza BPR Review Images (Json)."), - mp_bpr_recommended_product: String @doc(description: "Mageplaza BPR Recommended Product."), - mp_bpr_verified_buyer: String @doc(description: "Mageplaza BPR Verified Buyer."), - mp_bpr_helpful: Int @doc(description: "Mageplaza BPR Helpful."), - reply_enabled: Int @doc(description: "Mageplaza reply is enabled."), - reply_nickname: String @doc(description: "The nickname of the admin."), - reply_content: String @doc(description: "The content of the reply."), - reply_created_at: String @doc(description: "The timestamp indicating when the reply is created."), - avg_value: String @doc(description: "The avg rating of the review."), - products: Product @resolver(class: "Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\Review\\Product") @doc(description: "The products assigned to a review.") -} - -type NewReview { - review_id: Int @doc(description: "An ID that uniquely identifies the review."), - created_at: String @doc(description: "Timestamp indicating when the category was created."), - entity_id: Int @doc(description: "Review entity ID."), - entity_pk_value: Int @doc(description: "An ID that identifies the product."), - status_id: Int @doc(description: "An ID that identifies the status."), - detail_id: Int @doc(description: "An ID that identifies the review detail."), - title: String @doc(description: "The title of the review."), - detail: String @doc(description: "The detail of the review."), - nickname: String @doc(description: "The nickname of the reviewer."), - customer_id: Int @doc(description: "An ID that identifies the customer."), - mp_bpr_images: String @doc(description: "Mageplaza BPR Review Images (Json)."), - mp_bpr_recommended_product: String @doc(description: "Mageplaza BPR Recommended Product."), - mp_bpr_verified_buyer: String @doc(description: "Mageplaza BPR Verified Buyer."), - mp_bpr_helpful: Int @doc(description: "Mageplaza BPR Helpful."), - avg_value: String @doc(description: "The avg rating of the review.") -} - -type Product { - entity_id: Int @doc(description: "The ID number assigned to the product."), - attribute_set_id: Int @doc(description: "The attribute set assigned to the product."), - type_id: String @doc(description: "Represent simple, virtual, downloadable, grouped or configirable product type."), - sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer."), - has_options: Int @doc(description: "Indicate whether a product option is available."), - required_options: Int @doc(description: "Indicate whether a product option is required."), - created_at: String @doc(description: "Timestamp indicating when the product was created."), - updated_at: String @doc(description: "Timestamp indicating when the product was updated.") -} +# 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_BetterProductReviewsGraphQl +# @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) +# @license https://www.mageplaza.com/LICENSE.txt + +type Query { + mpBprGetReview( + action: String! @doc(description: "Action in query.") + filter: ReviewsFilterInput @doc(description: "Identifies which product attributes to search for and return.") + reviewId: Int @doc(description: "Review ID use in the filter. Apply when action is get_view_review.") + productId: Int @doc(description: "Product ID use in the filter. Apply when action is get_by_productId.") + productSku: String @doc(description: "Product Sku use in the filter. Apply when action is get_by_productSku.") + customerId: Int @doc(description: "Customer ID use in the filter. Apply when action is get_by_customerId.") + pageSize: Int = 10 @doc(description: "How many items should show on the page.") + currentPage: Int = 1 @doc(description: "Allows to using paging it start with 1.") + ):ReviewsOutput @resolver(class: "\\Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\Reviews") @doc(description: "The mpBprGetReview query searches for review that match the criteria specified in the filter.") +} + +type Mutation { + mpBprCreateReview ( + input: ReviewInput! + productId: Int! @doc(description: "Product ID used to add reviews.") + ): NewReview @resolver(class: "\\Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\CreateReview") @doc(description:"Create a new Review") +} + +input ReviewsFilterInput { + created_at: FilterTypeInput @doc(description: "Timestamp indicating when the review was created."), + entity_id: FilterTypeInput @doc(description: "The Entity ID."), + status_id: FilterTypeInput @doc(description: "Status code."), + detail_id: FilterTypeInput @doc(description: "Review detail ID."), + title: FilterTypeInput @doc(description: "Review title."), + nickname: FilterTypeInput @doc(description: "User nickname"), + mp_bpr_helpful: FilterTypeInput @doc(description: "Mageplaza BPR Helpful.") +} +input ReviewInput { + title: String! @doc(description: "Review title."), + detail: String! @doc(description: "Review detail."), + nickname: String! @doc(description: "User nickname."), + mp_bpr_images: String @doc(description: "Mageplaza BPR Review Images (Json)."), + mp_bpr_recommended_product: String @doc(description: "Mageplaza BPR Recommended Product."), + mp_bpr_helpful: Int @doc(description: "Mageplaza BPR Helpful."), + avg_value: String! @doc(description: "Average summaried rating.") +} + + +type ReviewsOutput { + total_count: Int @doc(description: "The number of reviews returned."), + items: [Review] @doc(description: "An array of revie that match the specified search criteria.") + pageInfo: PageInfo @doc(description: "An object that includes the page_info and currentPage values specified in the query.") +} + +type ReviewsOutputNoPage { + total_count: Int @doc(description: "The number of reviews returned."), + items: [Review] @doc(description: "An array of review that match the specified search criteria.") +} + +type PageInfo { + pageSize: Int @doc(description: "How many items should show on the page.") + currentPage: Int @doc(description: "Allow page number to start with 1.") + hasNextPage: Boolean @doc(description: "Is next page") + hasPreviousPage: Boolean @doc(description: "Is previous page") + startPage: Int @doc(description: "Start page") + endPage: Int @doc(description: "End page") +} + +type Review { + review_id: Int @doc(description: "An ID that uniquely identifies the review."), + created_at: String @doc(description: "Timestamp indicating when the category was created."), + entity_id: Int @doc(description: "Review entity ID."), + entity_pk_value: Int @doc(description: "An ID that identifies the product."), + status_id: Int @doc(description: "An ID that identifies the status."), + detail_id: Int @doc(description: "An ID that identifies the review detail."), + title: String @doc(description: "The title of the review."), + detail: String @doc(description: "The detail of the review."), + nickname: String @doc(description: "The nickname of the reviewer."), + customer_id: Int @doc(description: "An ID that identifies the customer."), + mp_bpr_images: String @doc(description: "Mageplaza BPR Review Images (Json)."), + mp_bpr_recommended_product: String @doc(description: "Mageplaza BPR Recommended Product."), + mp_bpr_verified_buyer: String @doc(description: "Mageplaza BPR Verified Buyer."), + mp_bpr_helpful: Int @doc(description: "Mageplaza BPR Helpful."), + reply_enabled: Int @doc(description: "Mageplaza reply is enabled."), + reply_nickname: String @doc(description: "The nickname of the admin."), + reply_content: String @doc(description: "The content of the reply."), + reply_created_at: String @doc(description: "The timestamp indicating when the reply is created."), + avg_value: String @doc(description: "The avg rating of the review."), + products: Product @resolver(class: "Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\Review\\Product") @doc(description: "The products assigned to a review.") +} + +type NewReview { + review_id: Int @doc(description: "An ID that uniquely identifies the review."), + created_at: String @doc(description: "Timestamp indicating when the category was created."), + entity_id: Int @doc(description: "Review entity ID."), + entity_pk_value: Int @doc(description: "An ID that identifies the product."), + status_id: Int @doc(description: "An ID that identifies the status."), + detail_id: Int @doc(description: "An ID that identifies the review detail."), + title: String @doc(description: "The title of the review."), + detail: String @doc(description: "The detail of the review."), + nickname: String @doc(description: "The nickname of the reviewer."), + customer_id: Int @doc(description: "An ID that identifies the customer."), + mp_bpr_images: String @doc(description: "Mageplaza BPR Review Images (Json)."), + mp_bpr_recommended_product: String @doc(description: "Mageplaza BPR Recommended Product."), + mp_bpr_verified_buyer: String @doc(description: "Mageplaza BPR Verified Buyer."), + mp_bpr_helpful: Int @doc(description: "Mageplaza BPR Helpful."), + avg_value: String @doc(description: "The avg rating of the review.") +} + +type Product { + entity_id: Int @doc(description: "The ID number assigned to the product."), + attribute_set_id: Int @doc(description: "The attribute set assigned to the product."), + type_id: String @doc(description: "Represent simple, virtual, downloadable, grouped or configirable product type."), + sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer."), + has_options: Int @doc(description: "Indicate whether a product option is available."), + required_options: Int @doc(description: "Indicate whether a product option is required."), + created_at: String @doc(description: "Timestamp indicating when the product was created."), + updated_at: String @doc(description: "Timestamp indicating when the product was updated."), + review: ReviewsOutputNoPage @resolver(class: "Mageplaza\\BetterProductReviewsGraphQl\\Model\\Resolver\\Review\\Review") @doc(description: "The reviews assigned to a product.") +}