Skip to content

Commit

Permalink
scandipwa/scandipwa#4814 - Use translation for review titles
Browse files Browse the repository at this point in the history
  • Loading branch information
IrinaZhadzinets committed May 26, 2022
0 parents commit bf135ef
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 0 deletions.
101 changes: 101 additions & 0 deletions Model/Resolver/ProductReviewRatingsMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* ScandiPWA - Progressive Web App for Magento
*
* Copyright © Scandiweb, Inc. All rights reserved.
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
* @package scandipwa/review-graphql
* @link https://github.com/scandipwa/review-graphql
*/

declare(strict_types=1);

namespace ScandiPWA\ReviewGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
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\Review\Model\ResourceModel\Rating\Collection as RatingCollection;
use Magento\Review\Model\ResourceModel\Rating\CollectionFactory as RatingCollectionFactory;
use Magento\Review\Model\Review;
use Magento\Review\Model\Review\Config as ReviewsConfig;
use Magento\Store\Api\Data\StoreInterface;
use Magento\ReviewGraphQl\Model\Resolver\ProductReviewRatingsMetadata as SourceProductReviewRatingsMetadata;

/**
* Class ProductReviewRatingsMetadata
* @package ScandiPWA\ReviewGraphQl\Model\Resolver
*/
class ProductReviewRatingsMetadata extends SourceProductReviewRatingsMetadata
{
/**
* @var RatingCollectionFactory
*/
protected RatingCollectionFactory $ratingCollectionFactory;

/**
* @var ReviewsConfig
*/
protected ReviewsConfig $reviewsConfig;

/**
* ProductReviewRatingsMetadata constructor.
* @param RatingCollectionFactory $ratingCollectionFactory
* @param ReviewsConfig $reviewsConfig
*/
public function __construct(
RatingCollectionFactory $ratingCollectionFactory,
ReviewsConfig $reviewsConfig
) {
$this->ratingCollectionFactory = $ratingCollectionFactory;
$this->reviewsConfig = $reviewsConfig;
}

/**
* Resolve product review ratings
*
* @param Field $field
* @param ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
*
* @return array[]|Value|mixed
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
if (false === $this->reviewsConfig->isEnabled()) {
return ['items' => []];
}

$items = [];
$storeID = $context->getExtensionAttributes()->getStore()->getId();

$ratingCollection = $this->ratingCollectionFactory->create();
$ratingCollection->addEntityFilter(Review::ENTITY_PRODUCT_CODE)
->addRatingPerStoreName($storeID)
->setStoreFilter($storeID)
->setActiveFilter(true)
->setPositionOrder()
->addOptionToItems();

foreach ($ratingCollection->getItems() as $item) {
$items[] = [
'id' => base64_encode($item->getData('rating_id')),
'name' => $item->getData('rating_code'),
'values' => $item->getData('options')
];
}

return ['items' => $items];
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ScandiPWA_ReviewGraphQl
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "scandipwa/review-graphql",
"description": "Review specific modifications for ScandiPWA",
"type": "magento2-module",
"license": [
"OSL-3.0"
],
"require": {
"magento/framework": "*",
"magento/module-review-graph-ql": "*"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"ScandiPWA\\ReviewGraphQl\\": ""
}
}
}
16 changes: 16 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* ScandiPWA - Progressive Web App for Magento
*
* Copyright © Scandiweb, Inc. All rights reserved.
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\ReviewGraphQl\Model\Resolver\ProductReviewRatingsMetadata"
type="ScandiPWA\ReviewGraphQl\Model\Resolver\ProductReviewRatingsMetadata" />
</config>
20 changes: 20 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<!--
/**
* ScandiPWA - Progressive Web App for Magento
*
* Copyright © Scandiweb, Inc. All rights reserved.
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="ScandiPWA_ReviewGraphQl">
<sequence>
<module name="Magento_ReviewGraphQl"/>
</sequence>
</module>
</config>
19 changes: 19 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* ScandiPWA - Progressive Web App for Magento
*
* Copyright © Scandiweb, Inc. All rights reserved.
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
* @package scandipwa/review-graphql
* @link https://github.com/scandipwa/review-graphql
*/

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'ScandiPWA_ReviewGraphQl',
__DIR__
);

0 comments on commit bf135ef

Please sign in to comment.