cancel
Showing results for 
Search instead for 
Did you mean: 

How to Bulk import Product Reviews in Magento 1.9?

How to Bulk import Product Reviews in Magento 1.9?

I have a list of reviews with email id, how can I bulk import Product Reviews into Magento?

12 REPLIES 12

Re: How to Bulk import Product Reviews in Magento 1.9?

Hi @Aveeva,

You can import product reviews using custom script.

You can edit the following scripts per your csv file.

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

?>
</CODE>

I hope it will help you.

Re: How to Bulk import Product Reviews in Magento 1.9?

@Vimal Kumar  I am okay with code, but i have confusion with excel format, can i  get excel format??

Re: How to Bulk import Product Reviews in Magento 1.9?

@Aveeva,

Yes you can use excel format as well but in this case you need excel reader library file to read it and can change code accordingly..

But you can also save as excel file into csv file format.

Re: How to Bulk import Product Reviews in Magento 1.9?

Reviews working now, how can i enable ratings also?

Re: How to Bulk import Product Reviews in Magento 1.9?

Good to know that reviews are working fine.

You can enable ratings from admin panel:

Admin -> Catalogs ->Reviews and Ratings -> Manage Ratings ->Add/Edit Ratings.

I hope it will help you!

Re: How to Bulk import Product Reviews in Magento 1.9?

I need ratings also import by programmatically.

Re: How to Bulk import Product Reviews in Magento 1.9?

You need to loop through all the voting options and create a rating for each option selected and like it back to your review.

<code>
foreach ($rating as $ratingId => $optionId) {
Mage::getModel('rating/rating')
->setRatingId($ratingId)
->setReviewId($review->getId())
->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
->addOptionVote($optionId, $product->getId());
}
</code>

To get all the ratings you can use the rating's resource collection:

<code>
$ratingCollection = Mage::getModel('rating/rating')
->getResourceCollection()
->addEntityFilter('product')
->setPositionOrder()
->addRatingPerStoreName(Mage::app()->getStore()->getId())
->setStoreFilter(Mage::app()->getStore()->getId())
->load()
->addOptionToItems();
</code>

Then for each rating object you can call getOptions() to get each possible option for each rating.

For more info you can refer following link:
https://magento.stackexchange.com/questions/25018/how-to-create-product-rating-programmatically

Re: How to Bulk import Product Reviews in Magento 1.9?

@Aveeva

Did it work for you?

Re: How to Bulk import Product Reviews in Magento 1.9?

The below code okay with review how can i add rating values in CSV?

 

<?php
require_once 'app/Mage.php';  // Load Mage
Mage::app(); // Init Mage
ini_set('memory_limit', '128M'); 

$fp = fopen('reviews.csv', 'r');
Mage::app()->setCurrentStore(1); //desired store id
while($line = fgetcsv($fp)) {
$review = Mage::getModel('review/review');
$review->setEntityPkValue($line[0]);//product id  //a

$review->setStatusId($line[1]); //b

$review->setTitle($line[2]); //c

$review->setDetail($line[3]); //d

$review->setEntityId($line[4]); //e

$review->setStoreId(Mage::app()->getStore()->getId());

$review->setStatusId($line[5]); //approved //f

$review->setCustomerId($line[6]);//null is for administrator //g

$review->setNickname($line[7]); //h

$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));
$review->save();
$review->aggregate();
}
?>