1

I'm trying to create product review programmatically, using the below code

<?php
ini_set('memory_limit', '128M');
require_once 'app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(1); //desired store id
$review = Mage::getModel('review/review');
$review->setEntityPkValue(1);//product id
$review->setStatusId(1);
$review->setTitle("mytitle");
$review->setDetail("mydetail");
$review->setEntityId(1);                                      
$review->setStoreId(Mage::app()->getStore()->getId());      //storeview              
$review->setStatusId(1); //approved
$review->setCustomerId(1);
$review->setNickname("Menickname");
$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));
$review->save();
$review->aggregate();
?>

When I set customer Id $review->setCustomerId(1) like this, it creates review for the product by customer with id=1 and when I use this $review->setCustomerId(), it creates review for the product by Guest. But I could not make review by administrator, I tried the below

$review->setCustomerId(null)

This also set review by Guest. How to create review for product by administrator?

2

@SIBHI S, I founded of your issue. Replace the following code as

ini_set('memory_limit', '128M');
require_once '../app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(1); //desired store id
$review = Mage::getModel('review/review');
$review->setEntityPkValue(1);//product id
$review->setStatusId(1);
$review->setTitle("mytitle");
$review->setDetail("mydetail");
$review->setEntityId(1);                                      
$review->setStoreId(0);      //storeview              
$review->setStatusId(1); //approved
$review->setCustomerId(null);
$review->setNickname("Menickname");
$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));
$review->save();
$review->aggregate();

I hope this is resolved your issue.

  • Is it means,For administrator store should be 0? – SIBHI S Jun 27 '14 at 8:47
  • yes. when administrator create a review, its store id store as 0. – Supravat Mondal Jun 27 '14 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.