Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpartington-cti committed Jun 29, 2017
2 parents 0a71384 + 7a66b4f commit dcef1e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
39 changes: 37 additions & 2 deletions Model/Component/ReviewRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
use Magento\Framework\ObjectManagerInterface;
use Magento\Review\Model\Rating;
use Magento\Review\Model\RatingFactory;
use Magento\Review\Model\Rating\Entity;
use Magento\Review\Model\Rating\EntityFactory;
use Magento\Store\Model\StoreRepository;
use Magento\Review\Model\Rating\Option;
use Magento\Review\Model\Rating\OptionFactory;

/**
* Class ReviewRating
* @package CtiDigital\Configurator\Model\Component
*
* @SuppressWarnings("CouplingBetweenObjects")
*/
class ReviewRating extends YamlComponentAbstract
{
const MAX_NUM_RATINGS = 5;
Expand All @@ -17,6 +25,8 @@ class ReviewRating extends YamlComponentAbstract

protected $name = 'Review Rating';

protected $entityId;

/**
* @var RatingFactory
*/
Expand All @@ -32,16 +42,23 @@ class ReviewRating extends YamlComponentAbstract
*/
protected $optionFactory;

/**
* @var EntityFactory
*/
protected $entityFactory;

public function __construct(
LoggingInterface $log,
ObjectManagerInterface $objectManager,
RatingFactory $ratingFactory,
StoreRepository $storeRepository,
OptionFactory $optionFactory
OptionFactory $optionFactory,
EntityFactory $entityFactory
) {
$this->ratingFactory = $ratingFactory;
$this->storeRepository = $storeRepository;
$this->optionFactory = $optionFactory;
$this->entityFactory = $entityFactory;
parent::__construct($log, $objectManager);
}

Expand Down Expand Up @@ -111,7 +128,8 @@ public function getReviewRating($reviewRatingCode)
public function updateOrCreateRating(Rating $rating, $ratingCode, $ratingData)
{
$rating->setRatingCode($ratingCode);
$rating->setEntityId(1);
$reviewEntityId = $this->getReviewEntityId();
$rating->setEntityId($reviewEntityId);
$isActive = 0;
if (isset($ratingData['is_active'])) {
$isActive = $ratingData['is_active'];
Expand Down Expand Up @@ -184,4 +202,21 @@ public function getStoresByCodes($storeCodes)

return $storesResponse;
}

/**
* Get the review entity ID
*
* @return int
*/
private function getReviewEntityId()
{
if ($this->entityId === null) {
/**
* @var Entity $entity
*/
$entity = $this->entityFactory->create();
$this->entityId = $entity->getIdByCode('product');
}
return $this->entityId;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"satooshi/php-coveralls": "^1.0",
"phpunit/phpunit": "4.1.0"
},
"version": "0.17.0-dev",
"version": "0.17.1-dev",
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
Expand Down

0 comments on commit dcef1e7

Please sign in to comment.