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

时间:2014-06-25 16:27:10

标签: php magento magento-1.7

我试图将旧的magento网站的产品评论和评级导出并导入新的magento网站。我不知道如何在不使用扩展名的情况下做到这一点。

这就是我开始以编程方式创建评论和评级的原因。我可以通过以下代码段创建评论。

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

但我不知道如何以编程方式创建评分。我对它完全一片空白。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

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

有关更多教程,请参阅以下链接 http://forum.azmagento.com/how-to/add-product-ratings-programmatically-or-migrating-reviews-and-ratings-to-magento-61913.html