douchen9855 2012-09-04 00:42
浏览 87
已采纳

如何将产品评论导入Magento?

I found the script below and its been said that it works, but I"m just not sure where or how they got the file/script to work and was hoping someone could help me shed some light.

There are multiple ways to import things into Magento - through a custom xml data file or just through a php script and thats what this says it is but i'm curious as to where its pulling the data from that its supposedly importing?

 <?php
ini_set('memory_limit', '128M');

require_once 'path-to-Mage.php';
Mage::app();

Mage::app()->setCurrentStore(4); //desired store id
$review = Mage::getModel('review/review');
$review->setEntityPkValue(147);//product id
$review->setStatusId(1);
$review->setTitle("title"); 
$review->setDetail("detail");
$review->setEntityId(1);                                      
$review->setStoreId(Mage::app()->getStore()->getId());                     
$review->setStatusId(1); //approved
$review->setCustomerId(273);//null is for administrator
$review->setNickname("Me");
$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));                    
$review->save();
$review->aggregate();
?>

So if this is my php script where am I putting it? And can someone help me formulate the xml script I would use for importing?

Thanks in advance for any and all help

Meghan

  • 写回答

2条回答 默认 最新

  • dporu02280 2012-09-04 03:14
    关注

    What format are your reviews in currently that you wish to import?

    It seems you'd need to expand on this script, for example :open a file containing your reviews, cycle through them and use the above code inside this loop, replacing "title" and "detail" etc with the actual review information.

    Edited based on your comments below *****

    I'm assuming you have PHP and Magento coding experience - if not, perhaps you should look to get assistance from a developer.

    <?php 
    ini_set('memory_limit', '128M'); 
    
    require_once 'path-to-Mage.php'; 
    Mage::app(); 
    $fp = fopen($fileLocation, 'r');
    Mage::app()->setCurrentStore(4); //desired store id 
    while($line = fgetcsv($fp)) {
         $review = Mage::getModel('review/review'); 
     $review->setEntityPkValue($line[0]);//product id 
     $review->setStatusId($line[1]); 
     $review->setTitle($line[2]);  
     $review->setDetail($line[3]); 
     $review->setEntityId($line[4]);                                       
     $review->setStoreId(Mage::app()->getStore()->getId());                      
     $review->setStatusId($line[5]); //approved 
     $review->setCustomerId($line[6]);//null is for administrator 
     $review->setNickname($line[7]); 
     $review->setReviewId($review->getId()); 
     $review->setStores(array(Mage::app()->getStore()->getId()));                     
     $review->save(); 
     $review->aggregate(); 
    }
    
    ?>
    

    You'll obviously need to replace $fileLocation with the directory location and file name of your CSV file. Each row of your CSV will be read into an array $line. The columns will map to the element numbers in the array. e.g. $line[0] is the first column of the row. You'll need to alter the element references so that the data matches up to your CSV columns.

    This is enough for you to get going.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?