Magento - How can I add rating information to a review -
i'm manually creating reviews in magento , i'm trying find out how add rating information in? can add reviews no problem i'm struggling rating values (star values). have array looks this: array("price"=>80, "value"=>60, "quality"=>60);
how can add star system , summary rating?
thanks.
ok, have far: adds review:
$review->setentitypkvalue(23);//product id $review->setstatusid(1); $review->settitle("title"); $review->setdetail("detail"); $review->setentityid($review->getentityidbycode(mage_review_model_review::entity_product_code)); $review->setstoreid(mage::app()->getstore()->getid()); $review->setstatusid(1); //approved $review->setnickname("me"); $review->setreviewid($review->getid()); $review->setstores(array(mage::app()->getstore()->getid())); $review->save(); $review->aggregate();
this adds rating review <-i'm stuck here!
// test code add rating review $rating[0]['price'] = 80; $rating[0]['value'] = 100; $rating[0]['quality'] = 80; $product_id = 23; $review_id = 631; foreach ($rating $ratingid => $optionid) { // bit seems go wrong!: mage::getmodel('rating/rating') ->setratingid(1) ->setreviewid($review_id) ->addoptionvote($val, $product_id); }
thanks!
this worked me:
public function addreview($ratingarray) { $product_id = $ratingarray['product_id']; $storeid = $ratingarray['store_id']; $title = $ratingarray['title']; $customerid = $ratingarray['customer_id']; $nickname = $ratingarray['nickname']; $detail = $ratingarray['detail']; $review = mage::getmodel('review/review'); $review->setentitypkvalue($product_id); $review->setstatusid(1); $review->settitle($title); $review->setdetail($detail ); $review->setentityid($review->getentityidbycode(mage_review_model_review::entity_product_code)); $review->setstoreid($storeid); $review->setstatusid(1); //approved $review->setcustomerid($customerid); $review->setnickname($nickname); $review->setreviewid($review->getid()); $review->setstores(array($storeid)); $review->save(); $review->aggregate(); //return "success"; $rating_options = $ratingarray['options']; /*array( array(1,2,3,4), array(6,7,8), array(11,12) );*/ $row = count($rating_options); $rating_id = 1; foreach($rating_options $key1=>$val1) { foreach($val1 $key2=>$val2) { $_rating = mage::getmodel('rating/rating') ->setratingid($key1) ->setreviewid($review->getid()) ->addoptionvote($val2,$product_id ); } } return "success"; }
i calling => $options = array(1=>array(1,2,3,4),2=>array(6,7,8),3=>array(11,12)); $reviewarray = array('customer_id'=>'21','product_id'=>'176','store_id'=>'4','title'=>'review','nickname'=>'xyz','detail'=>'nice product life time warrenty', 'options'=>$options);
Comments
Post a Comment