Exporting Magento 1 Product Reviews and Importing them to Magento 2

created January 11, 2020, last updated January 12, 2020.

closeThis post was last updated 1 year 3 months 6 days ago, some of the information contained here may no longer be actual and any referenced software versions may have been updated!

I am Migrating Magento 1.9 to 2.3 – yikes!

I wasn’t able to use the Magento 2 migration tool for products so one of the tasks on my TO DO list was product review migration. Looking around for (free) solutions the only stuff I came across was no longer free or didn’t work. $100 to import 500 reviews – I don’t think so.

If you are looking to do something similar here is a quick copy and paste of the php code I used for the Magento 1 export, and the Magento 2 import.

I am assuming you can plug this into your existing Magento php cli tools which already bootstrap the corresponding Magento1 or 2 core classes. For Magento 1 I first took a full product collection and parsed each product for review data. All the data is saved to a tab seperated CSV file which is then used for the Magento 2 product review import.

Magento Migration Product Review Migration
Magento Migration Product Review Migration

Magento 1.9 product review export to csv

echo $c("MAGE1 Migration - Export MAGE1 Product Reviews to CSV")->header. "\n\n";

$_storeID=0; // admin




foreach($_products as $_id=>$_product)
    $_sku = $_product->getSku();
    $_productId = $_product->getId();
    $_reviewcCollection = \Mage::getModel('review/review')->getCollection()
        ->addEntityFilter('product', $_productId)

        if (count($_reviewcCollection))


            foreach($_reviewcCollection as $_review) {

                $votes = $_review->getRatingVotes();
                $total = 0;

                foreach($votes as $vote)
                    $total += $vote->getPercent();

                $avgRating = $total / count($votes);

                $_reviewDetail=trim(preg_replace('/\s\s+/', '<br>', $_review['detail']));
                $_reviewTitle=trim(preg_replace('/\s\s+/', '<br>', $_review['title']));

                //var_dump($total, count($votes), $avg);
                    'createdat' => $_review->getCreatedAt(),
                    'review' => $_reviewDetail,
                    'summary' => $_reviewTitle,
                    'nickname' => $_review['nickname'],
                    'customer_id' => ($_review['customer_id'] ? $_review['customer_id'] : null),
                    'ratings' => implode('|', $_ratings),
                    'visibilty' => implode('|', $_reviewVisibleInStoreViews),

                echo '.';





echo "\n".$c($_count. ' product reviews exported for store view '. $_storeID)->info."\n";

$_now = new \DateTime(null, new \DateTimeZone('Europe/Berlin'));


if (file_exists($_reviewExportFilename)) {unlink($_reviewExportFilename);}

// -- csv seperator
$_seperator="\t"; // TAB
//$_seperator=','; // COMMA


$_fileHandle = fopen($_reviewExportFilename, 'w');

    // write UTF8-BOM
    //fwrite($_fileHandle, pack("CCC",0xef,0xbb,0xbf));

    // write header
    if ($_reviewExportHeader) {fwrite($_fileHandle, implode($_seperator, $_reviewExportHeader)."\r\n");}

    echo $c('Creating CSV export file '. $_reviewExportFilename)->info."\n";

    // write data
    foreach ($_reviewData as $_sku => $_reviews)
        foreach ($_reviews as $_review)
            fwrite($_fileHandle, $_sku.$_seperator.implode($_seperator, $_review)."\r\n");


echo $c('Product review export complete!')->success. "\n";

Magento 2 csv product import


	echo $c("MAGE2 Import Product Reviews from MAGE1 Migration CSV")->header. "\n\n";

	$_reviewDataCSV=file('/home/data/Mage1MigrateReviewsProducts_2020-01-11_admin.csv', FILE_IGNORE_NEW_LINES);

	echo $c("Importing from ". $_reviewDataCSVFile)->info. "\n";

	foreach ($_reviewDataCSV as $_key => $_data)
		if ($_key===0){ // build header


		foreach ($_dataArray as $_key => $_data)



            $_obj=new \PAJ\Library\Magento2\Reviews\AddReview(
					'reviewdata' => $_reviewData,
					'storeid' => '0'

				echo $c("Review ". $_count."/".$_total. " imported.")->success. "\n";


		catch (\Exception $e)
			// catch bad guys
			//throw new \Exception($e);
			echo $c("ERROR: ". $e->getMessage())->error. "\n";

		// 1 product test exit;

if (!$_silent) {

	echo 'Import complete.'. "\n";


class MagentoAddReview extends AbstractApp

     * @var \Magento\Review\Model\RatingFactory;
    private $_ratingFactory;
     * @var \Magento\Review\Model\ReviewFactory;
    private $_reviewFactory;

    public function run()
        // load a product

        // init vars

        $_store = $this->_storeManagerInterface->getStore($_storeID);


        //for Guest user $_customerId=Null;
        if (!$_customerId){$_customerId=Null;}

        // create review data
        $_reviewDetail=preg_replace('#<br\s*/?>#i', "\n", $_reviewData['review']);
        $_title=preg_replace('#<br\s*/?>#i', "\n", $_reviewData['summary']);

        // store visibility array, i.e. 1,2 for visibile in store view 1 and 2

        $_product = $this->_productRepository->get($_sku);

        $_reviewFactory = $this->getReviewFactory();
        $_ratingFactory = $this->getRatingFactory();

        foreach ($_ratings as $_key => $_rating)
            $_reviewFinalData['ratings'][$_key+1] = $_rating;

        $_reviewFinalData['nickname'] = $_customerNickName; //add user nickname
        $_reviewFinalData['title'] = $_title; //add title of the review
        $_reviewFinalData['detail'] = $_reviewDetail; //add details of the review
        $_reviewFinalData['customerid'] = $_customerId;

        $review = $_reviewFactory->create()->setData($_reviewFinalData);

            ->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED) //By default set approved

        foreach ($_reviewFinalData['ratings'] as $ratingId => $rating) {
                ->addOptionVote($rating, $_productId);

            'productid'=> $_productId

        return ['magento' => $_data];

     * Get Factories
    private function getRatingFactory()
        if (!$this->_ratingFactory) {
            $this->_ratingFactory = \Magento\Framework\App\ObjectManager::getInstance()
        return $this->_ratingFactory;
    private function getReviewFactory()
        if (!$this->_reviewFactory) {
            $this->_reviewFactory = \Magento\Framework\App\ObjectManager::getInstance()
        return $this->_reviewFactory;

The echo’s use the cool colours from https://github.com/kevinlebrun/colors.php The will probably throw an error for you, sorry!


This site uses Akismet to reduce spam. Learn how your comment data is processed.