Jump to content

Edit History

Najam Sajid

Najam Sajid

//This is my smarty template file i.e list.tpl

{* {include file='layouts/layout-full-width.tpl'} *}
{extends file='page.tpl'}

{block name='page_header_container'}
	<h1>
		{l s='Comments on product' mod='mymodcomments'}
		"{$product->name}"
	</h1>
{/block}
{block name='page_content'}
<div class="rte">
	{foreach from=$comments item=comment}
		<div class="mymodcomments-comment">
			<img src="http://www.gravatar.com/avatar/{$comment.email|trim|strtolower|md5}?s=45"
				class="pull-left img-thumbnail mymodcomments-avatar" />
			<div>{$comment.firstname} {$comment.lastname|substr:0:1}. <small>{$comment.date_add|substr:0:10}</small></div>
			<div class="star-rating"><i class="glyphicon glyphicon-star"></i>
				<strong>{l s='Grade:' mod='mymodcomments'}</strong>
			</div> <input value="{$comment.grade}" type="number" class="rating" min="0" max="5" step="1" data-size="xs" />
			<div><i class="glyphicon glyphicon-comment"></i> <strong>{l s='Comment' mod='mymodcomments'}
					#{$comment.id_mymod_comment}:</strong> {$comment.comment}</div>
		</div>
		<hr />
	{/foreach}
</div>

<ul class="pagination">
	{for $count=1 to $nb_pages}
		{assign var=params value=[
		        'module_action' => 'list',
		        'product_rewrite' => $product->link_rewrite,
		        'id_product' => $smarty.get.id_product,
		        'page' => $count
		    ]}
		{if $page eq $count}
			<li class="active current"><span><span>{$count}</span></span> </li>
		{else}
			<li><a href="{$link->getModuleLink('mymodcomments', 'comments', $params)}"><span>{$count}</span> </a></li>

		{/if}
	{/for}
</ul>
{/block}

This is my front controller  file:

//this is my controller code:
<?php
class MyModCommentsCommentsModuleFrontController extends ModuleFrontController
{
    public $product;
    public function setMedia()
        {
        parent::setMedia();
        $this->path = __PS_BASE_URI__.'modules/mymodcomments/';
        $this->context->controller->addCSS($this->path.'views/css/star-rating.css', 'all');
        $this->context->controller->addJS($this->path.'views/js/star-rating.js');
        $this->context->controller->addCSS($this->path.'views/css/mymodcomments.css', 'all');
        $this->context->controller->addJS($this->path.'views/js/mymodcomments.js');
    }
    public function initContent()
    {
        parent::initContent();
        $id_product = (int) Tools::getValue('id_product');
        $module_action = Tools::getValue('module_action');
        $actions_list = array('list' => 'initList');
        $this->product = new Product((int)$id_product, false, $this->context->cookie->id_lang);
        if ($id_product > 0 && isset($actions_list[$module_action])) {
            $method = $actions_list[$module_action];
            $this->$method();
        }

    }
    protected function initList()
    {
        $nb_comments = MyModComment::getProductNbComments((int)$this->product->id);
		$nb_per_page = 3;
		$nb_pages = ceil($nb_comments / $nb_per_page);
		$page = 1;
		if (Tools::getValue('page') != '')
		$page = (int)$_GET['page'];
		$limit_start = ($page - 1) * $nb_per_page;
		$limit_end = $nb_per_page;
        $comments = MyModComment::getProductComments((int)$this->product->id, $limit_start, $limit_end);
        //$comments = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'mymod_comment` WHERE `id_product` = '.(int)$this->product->id.' ORDER BY `date_add` DESC LIMIT '.(int)$limit_start.','.(int)$limit_end);
        $this->context->smarty->assign('comments', $comments);
        $this->context->smarty->assign('product', $this->product);
        $this->context->smarty->assign('page', $page);
		$this->context->smarty->assign('nb_pages', $nb_pages);
        $this->setTemplate('module:mymodcomments/views/templates/front/list.tpl');
    }
}
?>

Screenshotfrom2024-06-0914-07-42.thumb.png.801699f2a879aa76801c2cd78d88494e.png

Here are the codes from my front controller file and Smarty template file from my module.

These worked in PrestaShop 1.6 but are not functioning in PrestaShop 1.7.7.5. I have already made several modifications to adapt to PrestaShop 1.7, but I am still encountering errors. Can anyone help, please?

The error screenshot is attached.

Najam Sajid

Najam Sajid

//This is my smarty template file i.e list.tpl

{* {include file='layouts/layout-full-width.tpl'} *}
{extends file='page.tpl'}

{block name='page_header_container'}
	<h1>
		{l s='Comments on product' mod='mymodcomments'}
		"{$product->name}"
	</h1>
{/block}
{block name='page_content'}
<div class="rte">
	{foreach from=$comments item=comment}
		<div class="mymodcomments-comment">
			<img src="http://www.gravatar.com/avatar/{$comment.email|trim|strtolower|md5}?s=45"
				class="pull-left img-thumbnail mymodcomments-avatar" />
			<div>{$comment.firstname} {$comment.lastname|substr:0:1}. <small>{$comment.date_add|substr:0:10}</small></div>
			<div class="star-rating"><i class="glyphicon glyphicon-star"></i>
				<strong>{l s='Grade:' mod='mymodcomments'}</strong>
			</div> <input value="{$comment.grade}" type="number" class="rating" min="0" max="5" step="1" data-size="xs" />
			<div><i class="glyphicon glyphicon-comment"></i> <strong>{l s='Comment' mod='mymodcomments'}
					#{$comment.id_mymod_comment}:</strong> {$comment.comment}</div>
		</div>
		<hr />
	{/foreach}
</div>

<ul class="pagination">
	{for $count=1 to $nb_pages}
		{assign var=params value=[
		        'module_action' => 'list',
		        'product_rewrite' => $product->link_rewrite,
		        'id_product' => $smarty.get.id_product,
		        'page' => $count
		    ]}
		{if $page eq $count}
			<li class="active current"><span><span>{$count}</span></span> </li>
		{else}
			<li><a href="{$link->getModuleLink('mymodcomments', 'comments', $params)}"><span>{$count}</span> </a></li>

		{/if}
	{/for}
</ul>
{/block}

This is my front controller  file:

//this is my controller code:
<?php
class MyModCommentsCommentsModuleFrontController extends ModuleFrontController
{
    public $product;
    public function setMedia()
        {
        parent::setMedia();
        $this->path = __PS_BASE_URI__.'modules/mymodcomments/';
        $this->context->controller->addCSS($this->path.'views/css/star-rating.css', 'all');
        $this->context->controller->addJS($this->path.'views/js/star-rating.js');
        $this->context->controller->addCSS($this->path.'views/css/mymodcomments.css', 'all');
        $this->context->controller->addJS($this->path.'views/js/mymodcomments.js');
    }
    public function initContent()
    {
        parent::initContent();
        $id_product = (int) Tools::getValue('id_product');
        $module_action = Tools::getValue('module_action');
        $actions_list = array('list' => 'initList');
        $this->product = new Product((int)$id_product, false, $this->context->cookie->id_lang);
        if ($id_product > 0 && isset($actions_list[$module_action])) {
            $method = $actions_list[$module_action];
            $this->$method();
        }

    }
    protected function initList()
    {
        $nb_comments = MyModComment::getProductNbComments((int)$this->product->id);
		$nb_per_page = 3;
		$nb_pages = ceil($nb_comments / $nb_per_page);
		$page = 1;
		if (Tools::getValue('page') != '')
		$page = (int)$_GET['page'];
		$limit_start = ($page - 1) * $nb_per_page;
		$limit_end = $nb_per_page;
        $comments = MyModComment::getProductComments((int)$this->product->id, $limit_start, $limit_end);
        //$comments = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'mymod_comment` WHERE `id_product` = '.(int)$this->product->id.' ORDER BY `date_add` DESC LIMIT '.(int)$limit_start.','.(int)$limit_end);
        $this->context->smarty->assign('comments', $comments);
        $this->context->smarty->assign('product', $this->product);
        $this->context->smarty->assign('page', $page);
		$this->context->smarty->assign('nb_pages', $nb_pages);
        $this->setTemplate('module:mymodcomments/views/templates/front/list.tpl');
    }
}
?>

Screenshotfrom2024-06-0914-07-42.thumb.png.801699f2a879aa76801c2cd78d88494e.png

Here are the codes from my front controller file and Smarty template file from my module.

These worked in PrestaShop 1.6 but are not functioning in PrestaShop 1.7.7.5. I have already made several modifications to adapt to PrestaShop 1.7, but I am still encountering errors. Can anyone help, please?

The error screenshot is attached.

Najam Sajid

Najam Sajid

This is my front controller  file:

//this is my controller code:
<?php
class MyModCommentsCommentsModuleFrontController extends ModuleFrontController
{
    public $product;
    public function setMedia()
        {
        parent::setMedia();
        $this->path = __PS_BASE_URI__.'modules/mymodcomments/';
        $this->context->controller->addCSS($this->path.'views/css/star-rating.css', 'all');
        $this->context->controller->addJS($this->path.'views/js/star-rating.js');
        $this->context->controller->addCSS($this->path.'views/css/mymodcomments.css', 'all');
        $this->context->controller->addJS($this->path.'views/js/mymodcomments.js');
    }
    public function initContent()
    {
        parent::initContent();
        $id_product = (int) Tools::getValue('id_product');
        $module_action = Tools::getValue('module_action');
        $actions_list = array('list' => 'initList');
        $this->product = new Product((int)$id_product, false, $this->context->cookie->id_lang);
        if ($id_product > 0 && isset($actions_list[$module_action])) {
            $method = $actions_list[$module_action];
            $this->$method();
        }

    }
    protected function initList()
    {
        $nb_comments = MyModComment::getProductNbComments((int)$this->product->id);
		$nb_per_page = 3;
		$nb_pages = ceil($nb_comments / $nb_per_page);
		$page = 1;
		if (Tools::getValue('page') != '')
		$page = (int)$_GET['page'];
		$limit_start = ($page - 1) * $nb_per_page;
		$limit_end = $nb_per_page;
        $comments = MyModComment::getProductComments((int)$this->product->id, $limit_start, $limit_end);
        //$comments = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'mymod_comment` WHERE `id_product` = '.(int)$this->product->id.' ORDER BY `date_add` DESC LIMIT '.(int)$limit_start.','.(int)$limit_end);
        $this->context->smarty->assign('comments', $comments);
        $this->context->smarty->assign('product', $this->product);
        $this->context->smarty->assign('page', $page);
		$this->context->smarty->assign('nb_pages', $nb_pages);
        $this->setTemplate('module:mymodcomments/views/templates/front/list.tpl');
    }
}
?>

Screenshotfrom2024-06-0914-07-42.thumb.png.801699f2a879aa76801c2cd78d88494e.png

Here are the codes from my front controller file and Smarty template file from my module.

These worked in PrestaShop 1.6 but are not functioning in PrestaShop 1.7.7.5. I have already made several modifications to adapt to PrestaShop 1.7, but I am still encountering errors. Can anyone help, please?

The error screenshot is attached.

×
×
  • Create New...