【问题标题】:Magento - How can I add rating information to a reviewMagento - 如何在评论中添加评分信息
【发布时间】:2010-12-02 16:36:19
【问题描述】:

我在 Magento 中手动创建评论,并试图找出如何添加评分信息?我可以毫无问题地添加评论,但我在评分值(星级值)上苦苦挣扎。 我有一个看起来像这样的数组: array("价格"=>80, "价值"=>60, "质量"=>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();

这会为评论添加评分

// 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);
}

谢谢!

【问题讨论】:

  • 不清楚您所说的“手动”是什么意思。您是否正在编写代码来创建评论?并寻找您需要做些什么来添加评级值?发布您所做的代码,您将更有可能得到答案。
  • 嗨艾伦。感谢回复。是的,我正在编写代码来创建评论并添加评分值(价格、质量、价值等)。我已经编写了创建评论的代码,它只是没有添加评级。我现在不在办公桌前,所以我无法访问我编写的代码,但我会在明天可以发布的时候发布。谢谢
  • 好的,我现在已将代码添加到问题中。谢谢!

标签: magento rating review


【解决方案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'=>'Review','nickname'=>'XYZ', 'detail'=>'终身保修的好产品', 'options'=>$options);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多