【问题标题】:Import product review CSV in magento在 magento 中导入产品评论 CSV
【发布时间】:2015-12-23 05:14:57
【问题描述】:

我正在将产品评论的 csv 文件导入我的 magento。

csv 在我的 magento shell 文件夹中。我在我的 shell 目录中创建了一个 product_review.php 脚本

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

?>

当我运行 shell 文件夹并运行 product_review.php 时,出现了一个空白页面,我猜这是正确的方法。

但是当我进入我的后端并检查时,我看不到任何评论。我无法查看评论正在更新的产品。

我不知道我还有什么需要做的吗?

【问题讨论】:

    标签: php shell magento csv


    【解决方案1】:

    您可以使用以下代码导入产品评论。

    我的 CSV 格式如下:

    "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"
    


    因此,请确保在以下代码中编辑 CSV 路径并为变量分配正确的值。

        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!";
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-09
      • 2017-08-31
      • 2011-04-20
      • 1970-01-01
      相关资源
      最近更新 更多