Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created December 25, 2016 02:54
Show Gist options
  • Select an option

  • Save gelanivishal/792021f1be31c29122947e42e960fcc6 to your computer and use it in GitHub Desktop.

Select an option

Save gelanivishal/792021f1be31c29122947e42e960fcc6 to your computer and use it in GitHub Desktop.
M1: Import product reviews
<?php
include 'app/Mage.php';
Mage::app();
$customerid = '';
$product_id = '';
$file = fopen("review.csv","r");
$header = null;
while($row = fgetcsv($file))
{
if ($header === null) {
$header = $row;
continue;
}
$data = array_combine($header, $row);
$product_id = Mage::getModel('catalog/product')->getIdBySku($row['productid']);
if($product_id){
$_review = Mage::getModel('review/review')
->setCreatedAt($data['fulldate'])
->setEntityPkValue($product_id)
->setEntityId(1)
->setStatusId(1)
->setTitle($data['title'])
->setDetail($data['comments'])
->setStoreId(1)
->setStores(1)
->setCustomerId($customerid)
->setNickname($data['name'])
->save();
if($data['rating'])
{
Mage::getModel('rating/rating')
->setRatingId(3)
->setReviewId($_review->getId())
->setCustomerId($customerid)
->addOptionVote($data['rating'], $product_id);
Mage::getModel('rating/rating')
->setRatingId(2)
->setReviewId($_review->getId())
->setCustomerId($customerid)
->addOptionVote($data['rating'], $product_id);
Mage::getModel('rating/rating')
->setRatingId(1)
->setReviewId($_review->getId())
->setCustomerId($customerid)
->addOptionVote($data['rating'], $product_id);
$_review->aggregate();
}
Mage::log($product_id.' :: '.$row['productid'], null, 'import_review.log');
}
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment