Пример #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;
 }
Пример #2
0
 /**
  * Create mocks for collection and its factory
  */
 private function initCollectionMocks()
 {
     $this->collection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['addStoreFilter', 'addStatusFilter', 'addEntityFilter', 'getSize', '__wakeup'])->getMock();
     $this->collection->expects(static::any())->method('addStoreFilter')->willReturnSelf();
     $this->collection->expects(static::any())->method('addStatusFilter')->with(Review::STATUS_APPROVED)->willReturnSelf();
     $this->collection->expects(static::any())->method('addEntityFilter')->willReturnSelf();
     $this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create', '__wakeup'])->getMock();
     $this->collectionFactory->expects(static::once())->method('create')->willReturn($this->collection);
 }
 /**
  * Export reviews for website.
  *
  * @param \Magento\Store\Model\Website $website
  */
 public function _exportReviewsForWebsite(\Magento\Store\Model\Website $website)
 {
     $limit = $this->helper->getWebsiteConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
     $emailReviews = $this->_getReviewsToExport($website, $limit);
     $this->reviewIds = [];
     if ($emailReviews->getSize()) {
         $reviews = $this->mageReviewCollection->create()->addFieldToFilter('main_table.review_id', ['in' => $emailReviews->getColumnValues('review_id')])->addFieldToFilter('customer_id', ['notnull' => 'true']);
         $reviews->getSelect()->joinLeft(['c' => $this->coreResource->getTableName('customer_entity')], 'c.entity_id = customer_id', ['email', 'store_id']);
         foreach ($reviews as $mageReview) {
             try {
                 $product = $this->productFactory->create()->getCollection()->addIdFilter($mageReview->getEntityPkValue())->setStoreId($mageReview->getStoreId())->addAttributeToSelect(['product_url', 'name', 'store_id', 'small_image'])->setPage(1, 1)->getFirstItem();
                 $connectorReview = $this->connectorReviewFactory->create()->setReviewData($mageReview)->setProduct($product);
                 $votesCollection = $this->vote->getResourceCollection()->setReviewFilter($mageReview->getReviewId());
                 $votesCollection->getSelect()->join(['rating' => 'rating'], 'rating.rating_id = main_table.rating_id', ['rating_code' => 'rating.rating_code']);
                 foreach ($votesCollection as $ratingItem) {
                     $rating = $this->ratingFactory->create()->setRating($ratingItem);
                     $connectorReview->createRating($ratingItem->getRatingCode(), $rating);
                 }
                 $this->reviews[$website->getId()][] = $connectorReview;
                 $this->reviewIds[] = $mageReview->getReviewId();
             } catch (\Exception $e) {
                 $this->helper->debug((string) $e, []);
             }
         }
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             $storeId = [$this->storeManager->getDefaultStoreView()->getStoreId()];
             $review = $this->prepareReview($row);
             $this->createRating($row['rating_code'], $storeId);
             $productId = $this->getProductIdBySku($row['sku']);
             if (empty($productId)) {
                 continue;
             }
             /** @var \Magento\Review\Model\ResourceModel\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);
         }
     }
 }
Пример #5
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();
 }