I have task with reviews import using csv.I have csv of all reviews so i need to import reviews in our site i written code for import reviews programatically.
i crearted one file in magento root directory (reviewsimport.php) in that file i written the below code
<?php
// Invoke the Magento environment
require_once 'app/Mage.php';
Mage::app();
$fp = fopen("latestreviews.csv", 'r');
$count = 1;
while ($line = fgetcsv($fp)) {
$product_id = Mage::getModel("catalog/product")->getIdBySku($line[2]);
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($line[3]);
$review = Mage::getModel('review/review');
$review->setEntityPkValue($product_id); //product id
$review->setStatusId(1);
$review->setTitle($line[2]);
$review->setDetail($line[1]);
$review->setEntityId(1);
$review->setStoreId(Mage::app()->getStore()->getId());
$review->setStatusId(1); //approved
$review->setCustomerId($customer->getId()); //null is for administrator
$review->setNickname($customer->getName());
// $review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));
// print_r($review->getData());
$review->save();
$review->aggregate();
$rating_options = array(
1 => array(1, 2, 3, 4, 5), // <== Look at your database table `rating_option` for these vals
);
// Now save the ratings
foreach ($rating_options as $rating_id => $option_ids):
$_rating = Mage::getModel('rating/rating')
->setRatingId($rating_id)
->setReviewId($review->getId())
->addOptionVote($option_ids[$line[0] - 1], $product_id);
//print_r($_rating->getData());
endforeach;
echo $count;
$count++;
}
?>
csv formate like this ::
rate, reviewdes, sku, email
5 description 123456 n.pavan37@gmail.com
next i created csv file for rating besed on code it is also placed under magento root directory reviews.csv
example csv with one line
then run file in to browser.......keep :)
Thank you for sharing excellent information. Your website is very cool. Fully useful your blog post... Online Shopping Sites In Gujarat
ReplyDeleteVery useful! You helped me with something that I had a problem with for a long time. Great blog!
ReplyDeleteHi i'm new to magento......Full module please.. where i have to locate the file.?
ReplyDelete