Magento - 如何在评论中添加评分信息

时间:2010-12-02 16:36:19

标签: magento rating review

我在Magento手动创建评论,我试图找出如何添加评分信息?我可以添加评论没问题,但我正在努力与评级值(星值)。 我有一个看起来像这样的数组:    array(“Price”=> 80,“Value”=> 60,“Quality”=> 60);

如何将其添加到星系统和摘要评级?

感谢。

好的,所以这就是我到目前为止所做的: 这增加了一个评论:

$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 :(得分: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";
}

我称之为=>     $ 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'=>'评论','昵称'=&gt ;'XYZ','detail'=>'带有终身保修的漂亮产品','选项'=> $选项);