0

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

1 Answer 1

1

created_atshould be in this format : YYYY-MM-DD HH:MM:SS

5
  • But it's in that format. From $array['data_nps'] I get the date in YYYY-MM-DD format and from Mage::getModel('core/date')->gmtDate('H:i:s') I get the time in the HH:MM:SS format. Commented Nov 7, 2018 at 15:12
  • When you var_dump($data_avaliacao) you get this format YYYY-MM-DD HH:MM:SS ? try it please
    – PЯINCƎ
    Commented Nov 7, 2018 at 15:17
  • Giving a var_dump($data_value); maintaining the current code, with the conversion to type time being: $data_avaliacao = strtotime($array['data_nps']." ".Mage::getModel('core/date')->gmtDate ('H:i:s')); I have the following return, for example: int(1508772326). Removing the conversion to the type time being the code $data_avaliacao = $array['data_nps']." ".Mage::getModel('core/date')->gmtDate('H:i:s'); I have the following return, for example: string(19) "2017-10-23 13:27:40" Commented Nov 7, 2018 at 15:30
  • Because the field in the database is of type timestamp, I do this conversion. Commented Nov 7, 2018 at 15:41
  • Of course, the attribute is of type timestamp
    – PЯINCƎ
    Commented Nov 7, 2018 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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