Ejemplo n.º 1
0
 /**
  * Get collection of reviews
  *
  * @return ReviewCollection
  */
 public function getReviewsCollection()
 {
     if (null === $this->_reviewsCollection) {
         $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter($this->_storeManager->getStore()->getId())->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)->addEntityFilter('product', $this->getProduct()->getId())->setDateOrder();
     }
     return $this->_reviewsCollection;
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing product reviews:');
     $fixtureFile = 'Review/products_reviews.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $storeId = [$this->storeManager->getStoreId()];
         $review = $this->prepareReview($row);
         $this->createRating($row['rating_code'], $storeId);
         $productId = $this->getProductIdBySku($row['sku']);
         if (empty($productId)) {
             continue;
         }
         /** @var \Magento\Review\Model\Resource\Review\Collection $reviewCollection */
         $reviewCollection = $this->reviewCollectionFactory->create();
         $reviewCollection->addFilter('entity_pk_value', $productId)->addFilter('entity_id', $this->getReviewEntityId())->addFieldToFilter('detail.title', ['eq' => $row['title']]);
         if ($reviewCollection->getSize() > 0) {
             continue;
         }
         if (!empty($row['email']) && $this->getCustomerIdByEmail($row['email']) != null) {
             $review->setCustomerId($this->getCustomerIdByEmail($row['email']));
         }
         $review->save();
         $this->setReviewRating($review, $row);
         $this->logger->logInline('.');
     }
 }
Ejemplo n.º 3
0
 /**
  * Get size of reviews collection
  *
  * @return int
  */
 public function getCollectionSize()
 {
     $collection = $this->_reviewsColFactory->create()->addStoreFilter($this->_storeManager->getStore()->getId())->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)->addEntityFilter('product', $this->getProductId());
     return $collection->getSize();
 }