-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19266 from sky-hub/api-product-reviews-55
API: Product Reviews #55
- Loading branch information
Showing
70 changed files
with
6,188 additions
and
526 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
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,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Review\Model\Aggregator; | ||
|
||
use Magento\Review\Model\ResourceModel\Review as ReviewResource; | ||
use Magento\ReviewApi\Api\Data\ReviewInterface; | ||
use Magento\ReviewApi\Model\AggregatorInterface; | ||
|
||
/** | ||
* Class Ratings | ||
*/ | ||
class Ratings implements AggregatorInterface | ||
{ | ||
/** | ||
* @var ReviewResource | ||
*/ | ||
private $reviewResource; | ||
|
||
/** | ||
* Aggregator constructor | ||
* | ||
* @param ReviewResource $reviewResource | ||
*/ | ||
public function __construct( | ||
ReviewResource $reviewResource | ||
) { | ||
$this->reviewResource = $reviewResource; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function aggregate(ReviewInterface $review): void | ||
{ | ||
$this->reviewResource->reAggregateReview($review->getReviewId(), $review->getRelatedEntityId()); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Review\Model\Aggregator; | ||
|
||
use Magento\Review\Model\ResourceModel\Review as ReviewResource; | ||
use Magento\ReviewApi\Api\Data\ReviewInterface; | ||
use Magento\ReviewApi\Model\AggregatorInterface; | ||
|
||
/** | ||
* Class Review | ||
*/ | ||
class Review implements AggregatorInterface | ||
{ | ||
/** | ||
* @var ReviewResource | ||
*/ | ||
private $reviewResource; | ||
|
||
/** | ||
* Aggregator constructor | ||
* | ||
* @param ReviewResource $reviewResource | ||
*/ | ||
public function __construct( | ||
ReviewResource $reviewResource | ||
) { | ||
$this->reviewResource = $reviewResource; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function aggregate(ReviewInterface $review): void | ||
{ | ||
$this->reviewResource->aggregate($review); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...iew/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ReviewCustomerFilter.php
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,32 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Review\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor; | ||
|
||
use Magento\Framework\Api\Filter; | ||
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
|
||
/** | ||
* Class ReviewCustomerFilter | ||
*/ | ||
class ReviewCustomerFilter implements CustomFilterInterface | ||
{ | ||
/** | ||
* Apply customer_id Filter to Review Collection | ||
* | ||
* @param Filter $filter | ||
* @param AbstractDb $collection | ||
* @return bool Whether the filter is applied | ||
*/ | ||
public function apply(Filter $filter, AbstractDb $collection) | ||
{ | ||
/** @var \Magento\Review\Model\ResourceModel\Review\Collection $collection */ | ||
$collection->addCustomerFilter($filter->getValue()); | ||
|
||
return true; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...o/Review/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ReviewSkuFilter.php
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,53 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Review\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource; | ||
use Magento\Framework\Api\Filter; | ||
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
|
||
/** | ||
* Class ReviewSkuFilter | ||
*/ | ||
class ReviewSkuFilter implements CustomFilterInterface | ||
{ | ||
/** | ||
* Product resource | ||
* | ||
* @var ProductResource | ||
*/ | ||
private $productResource; | ||
|
||
/** | ||
* ReviewSkuFilter constructor | ||
* | ||
* @param ProductResource $productResource | ||
*/ | ||
public function __construct( | ||
ProductResource $productResource | ||
) { | ||
$this->productResource = $productResource; | ||
} | ||
|
||
/** | ||
* Apply sku Filter to Review Collection | ||
* | ||
* @param Filter $filter | ||
* @param AbstractDb $collection | ||
* @return bool Whether the filter is applied | ||
*/ | ||
public function apply(Filter $filter, AbstractDb $collection) | ||
{ | ||
$productId = $this->productResource->getIdBySku($filter->getValue()); | ||
|
||
/** @var \Magento\Review\Model\ResourceModel\Review\Collection $collection */ | ||
$collection->addEntityFilter('product', $productId); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.