From the following script below, I dynamically add evaluations on the products, however I am not able to set the creation date from $review->setCreatedAt($data_avaliacao);
. I already researched the subject, I saw several types of suggestions, but none with success. Thanks in advance!
while($array = mysqli_fetch_assoc($result)){
if (($array['sugestao_nps'] != "") && ($array['sugestao_nps'] != NULL) && ($array['score_nps'] >= 7)) {
$product_sku = $array['SKU'];
$product_id = Mage::getModel("catalog/product")->getIdBySku($product_sku);
$nome_cliente = utf8_encode($array['nome_cliente']);
$data_avaliacao = strtotime($array['data_nps']." ".Mage::getModel('core/date')->gmtDate('H:i:s'));
echo $array['score_nps']." - ".$nome_cliente." - ".$product_id." - ".$array['order_id']." - ".$data_avaliacao." - ".utf8_encode($array['sugestao_nps'])."<br />";
if (($array['score_nps'] == 10) || ($array['score_nps'] == 9)) {
$rating_id = 3;
$rating_value = 15;
} else if(($array['score_nps'] == 8) || ($array['score_nps'] == 7)){
$rating_id = 3;
$rating_value = 14;
}
$review = Mage::getModel('review/review');
$review->setEntityPkValue($product_id);//product id
$review->setStatusId(1);
$review->setDetail(utf8_encode($array['sugestao_nps']));
$review->setEntityId(1);
$review->setStoreId(0);
$review->setTitle("");
$review->setStatusId(1); //approved
$review->setCustomerId(null);
$review->setNickname($nome_cliente);
$review->setCreatedAt($data_avaliacao);
$review->setReviewId($review->getId());
$review->setStores(array(Mage::app()->getStore()->getId()));
$review->save();
Mage::getModel('rating/rating')
->setRatingId($rating_id)
->setReviewId($review->getId())
->addOptionVote($rating_value,$product_id);
$review->aggregate();
}