예제 #1
0
 /**
  * Add vote
  *
  * @param \Magento\Review\Model\Rating\Option $option
  * @return $this
  */
 public function addVote($option)
 {
     $connection = $this->getConnection();
     $optionData = $this->loadDataById($option->getId());
     $data = ['option_id' => $option->getId(), 'review_id' => $option->getReviewId(), 'percent' => $optionData['value'] / 5 * 100, 'value' => $optionData['value']];
     if (!$option->getDoUpdate()) {
         $data['remote_ip'] = $this->_remoteAddress->getRemoteAddress();
         $data['remote_ip_long'] = $this->_remoteAddress->getRemoteAddress(true);
         $data['customer_id'] = $this->_customerSession->getCustomerId();
         $data['entity_pk_value'] = $option->getEntityPkValue();
         $data['rating_id'] = $option->getRatingId();
     }
     $connection->beginTransaction();
     try {
         if ($option->getDoUpdate()) {
             $condition = ['vote_id = ?' => $option->getVoteId(), 'review_id = ?' => $option->getReviewId()];
             $connection->update($this->_ratingVoteTable, $data, $condition);
             $this->aggregate($option);
         } else {
             $connection->insert($this->_ratingVoteTable, $data);
             $option->setVoteId($connection->lastInsertId($this->_ratingVoteTable));
             $this->aggregate($option);
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollback();
         throw new \Exception($e->getMessage());
     }
     return $this;
 }
예제 #2
0
파일: Detailed.php 프로젝트: aiesh/magento2
 /**
  * Indicator of whether or not a rating is selected
  *
  * @param Option $option
  * @param \Magento\Review\Model\Rating $rating
  * @return bool
  */
 public function isSelected($option, $rating)
 {
     if ($this->getIsIndependentMode()) {
         $ratings = $this->getRequest()->getParam('ratings');
         if (isset($ratings[$option->getRatingId()])) {
             return $option->getId() == $ratings[$option->getRatingId()];
         } elseif (!$this->_voteCollection) {
             return false;
         }
     }
     if ($this->_voteCollection) {
         foreach ($this->_voteCollection as $vote) {
             if ($option->getId() == $vote->getOptionId()) {
                 return true;
             }
         }
     }
     return false;
 }