2010-12-02 17 views
2

Magentoで手動でレビューを作成していますが、どのように評価情報を追加するかを検討しようとしていますか?私はレビューを問題なく追加できますが、私は評価値(スター値)に苦しんでいます。 配列は以下のようになります。 配列( "Price" => 80、 "Value" => 60、 "Quality" => 60);Magento - 評価に評価情報を追加するには

スターシステムとサマリー評価にどのように追加できますか?

ありがとうございました。

[OK]を、ので、これは私がこれまで持っているものです: このレビューを追加します。

$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(); 

これは< -I'mが、ここで立ち往生レビューのための評価を追加します!

// 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

「マニュアル」とは何を意味するのかは不明です。あなたはレビューを作成するコードを書いていますか?評価値を追加するために必要なことを探していますか?あなたが行っているコードを投稿すると、答えが得られる可能性が高くなります。 –

+0

こんにちはアラン。返信いただきありがとうございます。はい、私はレビューを作成し、評価値(価格、品質、価値など)を追加するコードを書いています。私はレビューを作成するコードを書いていますが、それは評価を追加しません。私は今私の机から離れているので、私が書いたコードに到達することができませんが、私は明日それを投稿します。ありがとう – sulman

+0

私は今質問に自分のコードを追加しました。ありがとう! – sulman

答えて

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)); => 'レビュー'、 'ニックネーム' => 'XYZ' =$ reviewarray = array( 'customer_id' => '21'、 'product_id' => '176'、 'store_id' => '4' 、 'detail' => '生涯保証付きニース製品'、 'options' => $ options);

関連する問題