0

I have a Warning with "grade" in my Prestashop. I'm trying to display stars for comments on my products..

The function :

public function addGrade($id_product_comment, $grade)
{
    if (!Validate::isUnsignedId($id_product_comment))
        die(Tools::displayError());
    if ($grade < 0)
        $grade = 0;
    elseif ($grade > 10)
        $grade = 10;
    return (Db::getInstance()->Execute('
    INSERT INTO `'._DB_PREFIX_.'product_comment_grade`
    (`id_product_comment`, `id_product_comment_criterion`, `grade`) VALUES(
    '.(int)($id_product_comment).',
    '.(int)$this->id.',
    '.(int)($grade).')'));
}

Here is the tpl file :

<div id="moyenne" class="clearfix">
    {section loop=6 step=1 start=1 name=average}
        <span class="star" {if $bcomment.grade >= $smarty.section.average.index}style="background-position: 0 -32px;"{/if}></span>
    {/section}
</div>

Since i'm in PHP 5.6, i have this :

[29-Feb-2016 12:33:40 Europe/Paris] PHP Warning: Illegal string offset 'grade' in ...file.tpl

i've tried isset() but it's not working.. How can i fix it, please ?

Thanks for reply.

Shark34
  • 69
  • 1
  • 7
  • You question doesn't looks clear where is `$bcomment` data comes from in your tpl file, Have you checked printing `$bcomment` data – keviveks Feb 29 '16 at 12:12
  • Possible duplicate of [Illegal string offset Warning PHP](http://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php) – Jon Surrell Feb 29 '16 at 13:05
  • Thanks for reply. Yes, bcomment comes from this function : $lastnotes = self::getAverageGradeByProduct((int) $_GET['id_product']); if ($lastnotes) $smarty->assign('bcomment', $lastnotes); – Shark34 Feb 29 '16 at 13:06

1 Answers1

0

I got the same error in my code, the following code worked for me try this one

$smarty->assign(['bcomment', $lastnotes);