示例#1
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['ProductReview']['ID'])) {
         $instance = ActiveRecordModel::getInstanceByID('ProductReview', $record[$fields['ProductReview']['ID']], true);
     } else {
         if (isset($fields['Product']['ID'])) {
             $parent = ActiveRecordModel::getInstanceByID('Product', $record[$fields['Product']['ID']], true);
         } else {
             if (isset($fields['Product']['sku'])) {
                 $parent = Product::getInstanceBySku($record[$fields['Product']['sku']]);
             } else {
                 return;
             }
         }
     }
     if (empty($instance) && empty($parent)) {
         return;
     }
     if (empty($instance)) {
         $instance = ProductReview::getNewInstance($parent, User::getNewInstance(''));
         $instance->isEnabled->set(true);
     }
     return $instance;
 }
示例#2
0
 public function testDelete()
 {
     $type = ProductRatingType::getNewInstance(Category::getRootNode());
     $type->save();
     $type2 = ProductRatingType::getNewInstance(Category::getRootNode());
     $type2->save();
     for ($k = 0; $k <= 1; $k++) {
         $review = ProductReview::getNewInstance($this->product, $this->user);
         $review->save();
         $rating = ProductRating::getNewInstance($this->product, $type);
         $rating->rating->set(6 + $k);
         $rating->review->set($review);
         $rating->save();
         $rating = ProductRating::getNewInstance($this->product, $type2);
         $rating->rating->set(4 + $k);
         $rating->review->set($review);
         $rating->save();
     }
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 4);
     $this->assertEqual($this->product->ratingSum->get(), 22);
     $this->assertEqual($this->product->rating->get(), 5.5);
     // delete last review
     $review->delete();
     $this->product->reload();
     $this->assertEqual($this->product->ratingCount->get(), 2);
     $this->assertEqual($this->product->ratingSum->get(), 10);
     $this->assertEqual($this->product->rating->get(), 5);
     // check rating summaries
     $summary = ProductRatingSummary::getInstance($this->product, $type2);
     $this->assertEqual($summary->rating->get(), 4);
 }
 public function insert()
 {
     $input = Input::all();
     $item = ProductReview::create($input);
     return Response::json($item);
     //$validation = Validator::make($input, User::$rules);
     //if ($validation->passes()) {
     //    User::create($input);
     //    return Redirect::route('users.index');
     //}
 }
 public function process($data, $form)
 {
     $productID = $this->Controller->ID;
     $memberID = Member::currentUser()->ID;
     $review = new ProductReview($data);
     $review->ProductID = $productID;
     $review->MemberID = $memberID;
     $review->write();
     $starRatings = $data['StarRating'];
     $maxRating = $data['MaxRating'];
     foreach ($starRatings as $k => $v) {
         $starRating = new StarRating();
         $starRating->StarRatingCategory = $k;
         $starRating->Rating = $v;
         $starRating->MaxRating = $maxRating;
         $starRating->ProductReviewID = $review->ID;
         $starRating->write();
     }
     $this->Controller->redirectBack();
 }
示例#5
0
 public function rate()
 {
     $product = Product::getInstanceByID($this->request->get('id'), Product::LOAD_DATA);
     $ratingTypes = ProductRatingType::getProductRatingTypes($product);
     $validator = $this->buildRatingValidator($ratingTypes->toArray(), $product, true);
     $redirect = new ActionRedirectResponse('product', 'index', array('id' => $product->getID()));
     if ($validator->isValid()) {
         $msg = $this->translate('_msg_rating_added');
         if ($this->isAddingReview()) {
             $review = ProductReview::getNewInstance($product, $this->user);
             $review->loadRequestData($this->request);
             $review->ip->set($this->request->getIpLong());
             // approval status
             $approval = $this->config->get('APPROVE_REVIEWS');
             $review->isEnabled->set('APPROVE_REVIEWS_AUTO' == $approval || 'APPROVE_REVIEWS_USER' == $approval && !$this->user->isAnonymous());
             $review->save();
             $msg = $this->translate('_msg_review_added');
         }
         foreach ($ratingTypes as $type) {
             $rating = ProductRating::getNewInstance($product, $type, $this->user);
             $rating->rating->set($this->request->get('rating_' . $type->getID()));
             if (isset($review)) {
                 $rating->review->set($review);
             }
             $rating->ip->set($this->request->getIpLong());
             $rating->save();
         }
         if ($this->isAjax()) {
             $response = new JSONResponse(array('message' => $msg), 'success');
         } else {
             $this->setMessage($msg);
             $response = $redirect;
         }
         $response->setCookie('rating_' . $product->getID(), true, strtotime('+' . $this->config->get('RATING_SAME_IP_TIME') . ' hours'), $this->router->getBaseDirFromUrl());
         return $response;
     } else {
         if ($this->isAjax()) {
             return new JSONResponse(array('errors' => $validator->getErrorList()));
         } else {
             return $redirect;
         }
     }
 }