-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scandipwa/scandipwa#4814 - Use translation for review titles
- Loading branch information
0 parents
commit bf135ef
Showing
6 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# ScandiPWA_ReviewGraphQl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ | ||
); |