dongyoufo5672 2015-09-25 11:21
浏览 77

在magento中导入产品评论CSV

I am working on importing a csv of product reviews to my magento.

enter image description here

The csv is in my magento shell folder. I created a product_review.php script inside my shell directory

<?php 
require '../app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
ini_set('max_execution_time', 84000);
ini_set('memory_limit', '5120M');
$fp = fopen('final_available_dup.csv', 'r');
//Mage::app()->setCurrentStore(4); //desired store id 
while($line = fgetcsv($fp)) {
 $review = Mage::getModel('review/review'); 
 $review->setEntityPkValue($line[0]);//previews1.csv
 $review->setCreatedAt($line[1]);//previews1.csv
 $review->setStatusId($line[2]); //approved
 $review->setTitle($line[3]);
 $review->setNickname($line[4]);  
 $review->setDetail($line[5]); 
 $review->setEntityId($line[6]);                                       
 $review->setStoreId(Mage::app()->getStore()->getId());                      
 //$review->setStatusId($line[5]);  
 $review->setCustomerId($line[7]);//null is for administrator 
 $review->setReviewsCount($line[8]);//null is for administrator
 $review->setReviewId($review->getId()); 
 $review->setStores(array(Mage::app()->getStore()->getId()));                     
 $review->save(); 
 $review->aggregate(); 
}

?>

and when i run the shell folder and run product_review.php a blank page came which i guess is the correct way.

But when i go into my back end and check i cannot see any reviews.I am not able to which product the review is getting updated.

enter image description here

I don't know is there anything more I should do?

  • 写回答

1条回答 默认 最新

  • duanjing7298 2016-04-14 07:42
    关注

    You can use following code for importing product reviews.

    My CSV is as following format :

    "created_at","Sku","status_id","title","detail","nickname","customer_id","option_id","entity_id"
    "2016-04-01 19:42:09","1991474","2","Top","Blij van!!","claes wassenaar","","1:4@3:15@2:9","24582"
    


    So make sure your edit your CSV path in following code and assign proper values to variables.

        require_once 'app/Mage.php';
        Mage::app();
    
        $fileLocation = "var/import/import_review.csv"; // Set your CSV path here
        $fp = fopen($fileLocation, 'r');
        $count = 1;
    
        while($data = fgetcsv($fp)){
            if($count > 1){
                //initiate required variables
                $_createdAt     = $data[0];
                $_sku           = $data[1];
                $_catalog       = Mage::getModel('catalog/product');
                $_productId     = $_catalog->getIdBySku($_sku);
                $_statusId      = $data[2];
                $_title         = $data[3];
                $_detail        = $data[4];
                $_customerId    = NULL;
                $_nickname      = $data[5];
    
                //load magento review model and assign values
                $review = Mage::getModel('review/review');
                $review->setCreatedAt($_createdAt); //created date and time
                $review->setEntityPkValue($_productId);//product id
                $review->setStatusId($_statusId); // status id
                $review->setTitle($_title); // review title
                $review->setDetail($_detail); // review detail
                $review->setEntityId(1); // leave it 1
                $review->setStoreId(Mage::app()->getStore()->getId()); // store id
                $review->setCustomerId($_customerId); //null is for administrator
                $review->setNickname($_nickname); //customer nickname
                $review->setReviewId($review->getId());//set current review id
                $review->setStores(array(Mage::app()->getStore()->getId()));//store id's
                $review->save();
                $review->aggregate();
    
                //set review ratings
                if($data[7]){
                    $arr_data = explode("@",$data[7]);
                    if(!empty($arr_data)) {
                        foreach($arr_data as $each_data) {
                            $arr_rating = explode(":",$each_data);
                            if($arr_rating[1] != 0) {
                                Mage::getModel('rating/rating')
                                ->setRatingId($arr_rating[0])
                                ->setReviewId($review->getId())
                                ->setCustomerId($_customerId)
                                ->addOptionVote($arr_rating[1], $_productId);
                            }
                        }
                    }
                    $review->aggregate();
                }
            }
           // if($count == 5){
           //       die("total $count reviews are imported!");
           //  }
            $count++;
        }
    
        echo "total $count reviews are imported!";
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c