dream0776 2014-06-25 16:27
浏览 15

如何在magento中以编程方式创建产品评论评级?

I'm trying to export and import product reviews&ratings from old magento site to new magento site. I don't know how to do this without using an extension.

That's why I start with creating review and rating programatically. I'm able to create review by the following code snippet.

<?php
ini_set('memory_limit', '128M');
require_once 'app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(1); //desired store id
$review = Mage::getModel('review/review');
$review->setEntityPkValue(1);//product id
$review->setStatusId(1);
$review->setTitle("mytitle");
$review->setDetail("mydetail");
$review->setEntityId(1);                                      
$review->setStoreId(Mage::app()->getStore()->getId());      //storeview              
$review->setStatusId(1); //approved
$review->setCustomerId(1);
$review->setNickname("Menickname");
$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));
$review->save();
$review->aggregate();
?>

But I don't know how to create rating programmatically. I'm totally blank about it. Can anyone help on this?

  • 写回答

1条回答 默认 最新

  • drjltlm156790 2014-06-27 09:27
    关注
    //Add ratings for each of the 3 rating options (Price, Quality, Value) 
    foreach($rating_options as $rating_id => $option_id):    
    echo "Rating ID: {$rating_id} - ";    
    echo "Review ID: " . $_review->getId() . " - ";    
    echo "Product ID: " . $_product->getId() . " - ";    
    echo "Option ID: " . $option_id . " - ";    
    try {        
        $_rating = Mage::getModel('rating/rating')
            ->setRatingId($rating_id)            
            ->setReviewId($_review->getId())            
            ->setCustomerId($_customer->getId())            
            ->addOptionVote($option_id,$_product->getId());    
        } catch (Exception $e) {        
            die(var_dump($e));    
        }
      endforeach;
      $_review->save();
      $_review->aggregate();  
    

    for more tutorial please see the following link http://forum.azmagento.com/how-to/add-product-ratings-programmatically-or-migrating-reviews-and-ratings-to-magento-61913.html

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度