예제 #1
0
파일: Review.php 프로젝트: kewaunited/xcart
 /**
  * Create new model
  *
  * @return void
  */
 protected function doActionCreate()
 {
     $data = $this->getRequestData();
     $review = new \XLite\Module\XC\Reviews\Model\Review();
     $review->map($data);
     $review->setProfile($this->getProfile());
     $review->setIp(ip2long($_SERVER['REMOTE_ADDR']) ?: 0);
     if (!$review->getEmail()) {
         $review->setEmail($this->getProfileField('email'));
     }
     if (!$review->getReviewerName()) {
         $review->setReviewerName($this->getProfileField('reviewerName'));
     }
     $status = false == \XLite\Core\Config::getInstance()->XC->Reviews->disablePendingReviews || !$review->getReview() ? \XLite\Module\XC\Reviews\Model\Review::STATUS_APPROVED : \XLite\Module\XC\Reviews\Model\Review::STATUS_PENDING;
     $review->setStatus($status);
     $product = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->find($this->getProductId());
     $review->setProduct($product);
     $product->addReviews($review);
     \XLite\Core\Database::getEM()->flush();
     $message = 'Thank your for sharing your opinion with us!';
     if (!$review->getReview()) {
         $message = 'Your product rating is saved. Thank you!';
     }
     $this->updateReviewIds($review);
     \XLite\Core\TopMessage::addInfo(static::t($message));
 }
예제 #2
0
 /**
  * Create new model
  *
  * @return void
  */
 protected function doActionCreate()
 {
     $data = \XLite\Core\Request::getInstance()->getData();
     $profile = $data['profile'] === '' ? false : $data['profile'];
     unset($data['profile']);
     $review = new \XLite\Module\XC\Reviews\Model\Review();
     $review->map($data);
     $review->setStatus(\XLite\Module\XC\Reviews\Model\Review::STATUS_APPROVED);
     if ($profile && intval($profile) > 0) {
         $this->updateProfile($review, intval($profile));
     } elseif (!empty($data['profile_text'])) {
         $review->setReviewerName($data['profile_text']);
     }
     $product = $this->getRequestProduct() ?: (\XLite\Core\Database::getRepo('XLite\\Model\\Product')->find($data['product_title']) ?: $this->findProductBySubstring($data['product_title_text']));
     if ($product) {
         $review->setProduct($product);
         $product->addReviews($review);
         \XLite\Core\Database::getEM()->flush();
         \XLite\Core\TopMessage::addInfo(static::t('Review has been created'));
     } else {
         \XLite\Core\TopMessage::addError(static::t('Review has not been created since product is not found', array('product' => $data['product_title'])));
     }
     $this->setReturnUrl();
     $this->setHardRedirect();
 }