2010-12-02 107 views
2

我正在Magento中手動創建評論,並試圖瞭解如何在評分信息中添加評分信息?我可以添加評論沒有問題,但我正在努力與評級值(星級值)。我有一個看起來像這樣的數組: array(「Price」=> 80,「Value」=> 60,「Quality」=> 60);Magento - 我如何在評論中添加評分信息

我怎樣才能將它添加到星系和概要評分?

謝謝。

好了,所以這是我到目前爲止有: 這增加了一個回顧:

$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 is some test code to add the rating review 
$rating[0]['Price']  = 80; 
$rating[0]['Value']  = 100; 
$rating[0]['Quality'] = 80; 
$product_id = 23; 
$review_id = 631; 
foreach ($rating as $ratingId => $optionId) { 
// This is the bit where it all seems to go wrong!: 
     Mage::getModel('rating/rating') 
     ->setRatingId(1) 
     ->setReviewId($review_id) 
     ->addOptionVote($val, $product_id); 
} 

謝謝!

+1

目前還不清楚「手動」是什麼意思。你是否正在編寫代碼來創建評論?並尋找你需要做什麼來添加評級值?發佈你所做的代碼,你會讓我更有可能得到答案。 – 2010-12-02 20:38:05

回答

1

這爲我工作:

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 as $key1=>$val1) 
    { 
     foreach($val1 as $key2=>$val2) 
     { 
      $_rating = Mage::getModel('rating/rating') 
      ->setRatingId($key1) 
      ->setReviewId($review->getId()) 
      ->addOptionVote($val2,$product_id); 
     } 

    } 
    return "Success"; 
} 

我打電話這個像=> $選項=陣列(1 =>陣列(1,2,3,4),2 =>陣列(6, 7,8),3 =>數組(11,12)); $ reviewarray = array''customer_id'=>'21','product_id'=>'176','store_id'=>'4','title'=>'Review','nickname'=>'XYZ' ,'detail'=>'Nice Life with Life Time Warrenty','options'=> $ options);