如何将产品评论导入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

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.

If you want to import via pure SQL, then you can use the below set of queries:

-- Edit values
SET @PRODUCT_ID         = 123;
SET @STORE_ID           = 1;
SET @CUSTOMER_ID        = NULL;
SET @REVIEW_TITLE       = 'Lorem Ipsum';
SET @REVIEW_DETAIL      = 'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...';
SET @REVIEW_RATING      = 5; -- Between 1 to 5
SET @REVIEW_NICKNAME    = 'John Doe';
SET @REVIEW_CREATED_AT  = '2019-07-15'; -- OR date in YY-mm-dd HH:ii:ss format

-- No need to Edit
SET @REVIEW_ENTITY_ID   = (SELECT entity_id FROM rating_entity WHERE entity_code = 'product'); -- 1: product, ...
SET @REVIEW_STATUS_ID   = (SELECT status_id FROM review_status WHERE status_code = 'Pending'); -- 1: Approved, 2: Pending, 3: Not Approved

INSERT INTO review SET created_at = @REVIEW_CREATED_AT, entity_id = @REVIEW_ENTITY_ID, entity_pk_value = @PRODUCT_ID, status_id = @REVIEW_STATUS_ID;
SET @REVIEW_ID = (SELECT LAST_INSERT_ID());
INSERT INTO review_detail SET review_id = @REVIEW_ID, store_id = @STORE_ID, title = @REVIEW_TITLE, detail = @REVIEW_DETAIL, nickname = @REVIEW_NICKNAME, customer_id = @CUSTOMER_ID;
INSERT INTO review_store SET review_id = @REVIEW_ID, store_id = 0;
INSERT INTO review_store SET review_id = @REVIEW_ID, store_id = @STORE_ID;
INSERT INTO rating_option_vote SET option_id = 5, remote_ip = '', remote_ip_long = 0, customer_id = @CUSTOMER_ID, entity_pk_value = @PRODUCT_ID, rating_id = @REVIEW_ENTITY_ID,
review_id = @REVIEW_ID, percent = 100, value = @REVIEW_RATING;

You can get detailed steps here:
https://blog.magepsycho.com/import-product-reviews-in-magento-via-sql/