Jump to content

[RESOLU] Module commentaire : afficher les différents critères en FO et BO


Recommended Posts

Bonjour,

 

Je suis en train de travailler le module de commentaires produits pour insérer :

 

Côté Back-office

 

1 - La date

2 - Le titre

3 - La note moyenne

4 - Le produit avec son lien

 

Pour tous ces points pas de soucis.

 

Mais voilà, j'aimerai voir la note pour les différents critères que ce soit en Front-office et Back-office.

En gros, garder la moyenne de la note mais en plus avoir le détail de chaque note.

 

Suis-je clair ?

 

Merci pour vos lumières

Edited by SWITCHBOARD (see edit history)
Link to comment
Share on other sites

J'avance un peu du côté Front-office

 

J'ai intégré les critères mais je bloque sur la variable à mettre pour les étoiles...

 

{$criterion.product_comment_criterion} ne fonctionne pas.

 

Voici mon bout de code pour productcomment.tpl

<div style="border-top:1px solid #EEEEEE;padding-top:10px" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
	{if $criterions|@count > 0}
		{foreach from=$criterions item='criterion'}
			<table>
				<tr>
				<td style="width:60px;padding-right:9px;font-weight:bold">{$criterion.name|escape:'html':'UTF-8'}</td>
				{section name="i" start=0 loop=5 step=1}
				<td class="star star_on">{$criterion.product_comment_criterion}</td>
				{/section}
				</tr>
			</table>
		{/foreach}
	{/if}
</div>

Si vous avez une idée.

 

Voici une capture

post-396139-0-70541500-1383227761_thumb.png

Link to comment
Share on other sites

Bonjour,

 

En utilisant la variable grade

 

ProductCommentCriterion.php

	/**
	 * Add grade to a criterion
	 *
	 * @return boolean succeed
	 */
	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).')'));
	}

productcomments.tpl

					<span>{l s='Grade' mod='productcomments'}&nbsp</span>
					<div class="star_content clearfix">
					{section name="i" start=0 loop=5 step=1}
						{if $comment.grade le $smarty.section.i.index}
							<div class="star"></div>
						{else}
							<div class="star star_on"></div>
						{/if}
Link to comment
Share on other sites

productcomments.php

	public function hookExtraProductComparison($params)
	{
		require_once(dirname(__FILE__).'/ProductComment.php');
		require_once(dirname(__FILE__).'/ProductCommentCriterion.php');

		$list_grades = array();
		$list_product_grades = array();
		$list_product_average = array();
		$list_product_comment = array();

		foreach ($params['list_ids_product'] as $id_product)
		{
			$grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
			$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
			$grade_total = 0;
			if (count($grades) > 0)
			{
				foreach ($criterions as $criterion)
				{
					if (isset($grades[$criterion['id_product_comment_criterion']]))
					{
					$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
					$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
					}
					else
						$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = 0;

					if (!array_key_exists($criterion['id_product_comment_criterion'], $list_grades))
						$list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
				}

				$list_product_average[$id_product] = $grade_total / count($criterions);
				$list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
			}
		}
Link to comment
Share on other sites

Merci Indesign de ton intérêt mais les bouts de code que tu me donne sont ceux déjà existant...

 

En fait, j'ai déjà réussi à intégrer la liste de tous les critères.

 

Il ne me reste plus qu'à trouver le code pour faire apparaître la note (étoiles) pour chaque critère.

 

Regarde l'image de mon post précédent, ce sera plus parlant.

 

Merci de ton aide

Link to comment
Share on other sites

Merci Indesign de ton intérêt mais les bouts de code que tu me donne sont ceux déjà existant...

Oui, je sais. C'était juste pour tenter de t'aider, de t'aiguiller...

 

Il ne me reste plus qu'à trouver le code pour faire apparaître la note (étoiles) pour chaque critère.

J'ai bien compris ton souhait depuis le 1er post  et j'ai vu l'image du 2e post ;)

 

• En utilisant, la boucle du 2e post, et la variable grades

            $grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id)

• Dans la BD ps_product_comments_grade

id_product_comment  id_product_comment_criterion  grade

Edited by indesign (see edit history)
Link to comment
Share on other sites

En regardant de plus près, notamment dans les variables retournés par smarty dans productcomments.tpl

		$this->context->smarty->assign(array(
			'logged' => (int)$this->context->customer->isLogged(true),
			'action_url' => '',
			'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, $this->context->cookie->id_customer),
			'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id),
			'averages' => $averages,
			'product_comment_path' => $this->_path,
			'averageTotal' => $averageTotal,
			'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
			'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
			'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'),
			'id_product_comment_form' => (int)Tools::getValue('id_product'),
			'secure_key' => $this->secure_key,
			'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
			'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
			'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')),
			'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments'),
			'productcomments_url_rewriting_activated' => Configuration::get('PS_REWRITING_SETTINGS', 0),
			'moderation_active' => (int)Configuration::get('PRODUCT_COMMENTS_MODERATE')
		));

La variable grade n'est pas prise en compte :

 

• soit il faut la rajouter comme dans  public function hookExtraProductComparison($params)
 

• ou utiliser une autre variable   'averages' => $averages, ou 'averageTotal' => $averageTotal,

 

productcomments-extra.tpl

		<span>{l s='Average grade' mod='productcomments'}&nbsp</span>
		<div class="star_content clearfix">
		{section name="i" start=0 loop=5 step=1}
			{if $averageTotal le $smarty.section.i.index}
				<div class="star"></div>
			{else}
				<div class="star star_on"></div>
			{/if}
		{/section}
		</div>


 

Link to comment
Share on other sites

Je dois être noeud-noeud... :(

Voici ma fonction hookProductTabContent

    public function hookProductTabContent($params)
    {
		$this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js');
		$this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js');
		$this->context->controller->addJS($this->_path.'js/productcomments.js');

		$id_guest = (!$id_customer = (int)$this->context->cookie->id_customer) ? (int)$this->context->cookie->id_guest : false;
		$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)$this->context->cookie->id_customer, true, (int)$id_guest);

		$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), $this->context->language->id);
		$averageTotal = 0;
		foreach ($averages as $average)
			$averageTotal += (float)($average);
		$averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0;

		$image = Product::getCover((int)Tools::getValue('id_product'));
		
				require_once(dirname(__FILE__).'/ProductCommentCriterion.php');

		$list_grades = array();
		$list_product_grades = array();
		$list_product_average = array();
		$list_product_comment = array();

		foreach ($params['list_ids_product'] as $id_product)
		{
			$grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
			$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
			$grade_total = 0;
			if (count($grades) > 0)
			{
				foreach ($criterions as $criterion)
				{
					if (isset($grades[$criterion['id_product_comment_criterion']]))
					{
					$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
					$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
					}
					else
						$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = 0;

					if (!array_key_exists($criterion['id_product_comment_criterion'], $list_grades))
						$list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
				}

				$list_product_average[$id_product] = $grade_total / count($criterions);
				$list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
			}
		}

		$this->context->smarty->assign(array(
			'logged' => (int)$this->context->customer->isLogged(true),
			'action_url' => '',
			'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, $this->context->cookie->id_customer),
			'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id),
			'averages' => $averages,
			'product_comment_path' => $this->_path,
			'averageTotal' => $averageTotal,
			'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
			'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
			'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'),
			'id_product_comment_form' => (int)Tools::getValue('id_product'),
			'secure_key' => $this->secure_key,
			'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
			'mediumSize' => Image::getSize('medium_default'),
			'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')),
			'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments'),
			'productcomments_url_rewriting_activated' => Configuration::get('PS_REWRITING_SETTINGS', 0),
			'grades' => $list_grades,
			'product_grades' => $list_product_grades,
			'list_ids_product' => $params['list_ids_product'],
			'list_product_average' => $list_product_average,
			'product_comments' => $list_product_comment
			));

		$this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')));

		return ($this->display(__FILE__, '/productcomments.tpl'));
	}

Et voici mon bout de code dans productcomments.tpl

							{foreach from=$criterions item='criterion'}
							
							<table>
								<tr>
								<td style="width:60px;padding-right:9px;font-weight:bold">{$criterion.name|escape:'html':'UTF-8'}</td>
									<div class="star_content clearfix">
									{section name="i" start=0 loop=5 step=1}
									<td class="star star_on">{$criterion.grade}</td>
									{/section}
									</div>
								</tr>
							</table>
							
							{/foreach}
Link to comment
Share on other sites

Je dois être noeud-noeud... :(

Je ne pense pas... plutôt le contraire.

 

• Changes le titre de ton post 

Afficher les différents critères en FO et BO > Module commentaire : afficher les différents critères en FO et BO

 

• Essayes de contacter DevNet  : il trouvera sûrement la solution ;)

Link to comment
Share on other sites

Bonjour Switchboard,

 

J'ai longuement cherché durant le week-end. ;)

J'ai trouvé une solution mais pas totalement satisfaisante.

La note de chaque critère étant fausse dès qu'il y a plusieurs commentaires.

 

 

Par contre, la solution est dans productcomments.php

	public function hookExtraProductComparison($params)
	{
		require_once(dirname(__FILE__).'/ProductComment.php');
		require_once(dirname(__FILE__).'/ProductCommentCriterion.php');

		$list_grades = array();
		$list_product_grades = array();
		$list_product_average = array();
		$list_product_comment = array();

		foreach ($params['list_ids_product'] as $id_product)
		{
			$grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
			$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
			$grade_total = 0;
			if (count($grades) > 0)
			{
				foreach ($criterions as $criterion)
				{
					if (isset($grades[$criterion['id_product_comment_criterion']]))
					{
					$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
					$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
					}
					else
						$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = 0;

					if (!array_key_exists($criterion['id_product_comment_criterion'], $list_grades))
						$list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
				}

				$list_product_average[$id_product] = $grade_total / count($criterions);
				$list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
			}
		}

		if (count($list_grades) < 1)
			return false;

		$this->context->smarty->assign(array('grades' => $list_grades,	'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'],
		'list_product_average' => $list_product_average, 'product_comments' => $list_product_comment));

		return $this->display(__FILE__, '/products-comparison.tpl');

return $this->display(__FILE__, '/products-comparison.tpl');

 

il faut l'intégrer dans la function

public function hookProductTabContent($params)
...
       return ($this->display(__FILE__, '/productcomments.tpl'));
    

 

Link to comment
Share on other sites

Peux-tu me mettre ton productcomments.php et ton productcomments.tpl, s'il te plaît car je n'y parvient pas... :wacko:

Désolé, je suis un peu débordé, pour l'instant. :(

Je n'ai pas fait la modification, mais comme le montre la capture d'écran, c'est possible déjà en natif dans PS pour le comparateur.

Ce soir, ou demain, je regarde en détail.

Link to comment
Share on other sites

Je "pense" que la fonction est correcte

    public function hookProductTabContent($params)
    {

		require_once(dirname(__FILE__).'/ProductComment.php');
		require_once(dirname(__FILE__).'/ProductCommentCriterion.php');


		$this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js');
		$this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js');
		$this->context->controller->addJS($this->_path.'js/productcomments.js');

		$id_guest = (!$id_customer = (int)$this->context->cookie->id_customer) ? (int)$this->context->cookie->id_guest : false;
		$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)$this->context->cookie->id_customer, true, (int)$id_guest);

		$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), $this->context->language->id);
		$averageTotal = 0;
		foreach ($averages as $average)
			$averageTotal += (float)($average);
		$averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0;

		$image = Product::getCover((int)Tools::getValue('id_product'));

		$list_grades = array();
		$list_product_grades = array();
		$list_product_average = array();
		$list_product_comment = array();

		//foreach ($params['list_ids_product'] as $id_product)
		//{
			
		if ($id_product = (int)Tools::getValue('id_product'))
			$this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
			$id_product = (int)$this->product->id;
			$grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
			$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
			$grade_total = 0;
			if (count($grades) > 0)
			{
				foreach ($criterions as $criterion)
				{
					if (isset($grades[$criterion['id_product_comment_criterion']]))
					{
					$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
					$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
					}
					else
						$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = 0;

					if (!array_key_exists($criterion['id_product_comment_criterion'], $list_grades))
						$list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
				}

				$list_product_average[$id_product] = $grade_total / count($criterions);
				$list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
			}
		//}

		if (count($list_grades) < 1)
			return false;
			
		$this->context->smarty->assign(array(
			'logged' => (int)$this->context->customer->isLogged(true),
			'action_url' => '',
			'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, $this->context->cookie->id_customer),
			'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id),
			'averages' => $averages,
			'product_comment_path' => $this->_path,
			'averageTotal' => $averageTotal,
			'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
			'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
			'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'),
			'id_product_comment_form' => (int)Tools::getValue('id_product'),
			'secure_key' => $this->secure_key,
			'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
			'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
			'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')),
			'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments'),
			'productcomments_url_rewriting_activated' => Configuration::get('PS_REWRITING_SETTINGS', 0),
			'moderation_active' => (int)Configuration::get('PRODUCT_COMMENTS_MODERATE'),
			'grades' => $list_grades,
			'product_grades' => $list_product_grades,
			//'list_ids_product' => $params['list_ids_product'],
			'list_product_average' => $list_product_average, 
			'product_comments' => $list_product_comment,
		));

		$this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')));

		return $this->display(__FILE__, '/productcomments.tpl');
		
	}

Les rajouts dans le TPL.

A modifier, ce n'est pas bon... Je suis vraiment trop en retard sur mon propre travail. :( 

			{foreach from=$grades item=grade key=grade_id}
			<tr>
				{cycle values='comparison_feature_odd,comparison_feature_even' assign='classname'}
				<td class="{$classname}">
					{$grade}
				</td>
			
					{assign var='tab_grade' value=$product_grades[$grade_id]}
					<td  width="{$width}%" class="{$classname} comparison_infos ajax_block_product" align="center">
					{if isset($tab_grade[$id_product]) AND $tab_grade[$id_product]}
						{section loop=6 step=1 start=1 name=average}
							<input class="auto-submit-star" disabled="disabled" type="radio" name="{$grade_id}_{$id_product}_{$smarty.section.average.index}" {if isset($tab_grade[$id_product]) AND $tab_grade[$id_product]|round neq 0 and $smarty.section.average.index eq $tab_grade[$id_product]|round}checked="checked"{/if} />
						{/section}
					{else}
						-
					{/if}
					</td>
			</tr>				
			{/foreach}
			
				{cycle values='comparison_feature_odd,comparison_feature_even' assign='classname'}
			<tr>
				<td  class="{$classname} comparison_infos">{l s='Average' mod='productcomments'}</td>
				<td  width="{$width}%" class="{$classname} comparison_infos" align="center" >
				{if isset($list_product_average[$id_product]) AND $list_product_average[$id_product]}
					{section loop=6 step=1 start=1 name=average}
						<input class="auto-submit-star" disabled="disabled" type="radio" name="average_{$id_product}" {if $list_product_average[$id_product]|round neq 0 and $smarty.section.average.index eq $list_product_average[$id_product]|round}checked="checked"{/if} />
					{/section}	
				{else}
					-
				{/if}
				</td>	
			</tr>
Link to comment
Share on other sites

Essaye d'afficher les erreurs :

 

A partir de PrestaShop v1.5.3
    1.    Ouvrez config/defines.inc.php
    2.    À la line 28 (ou proche) vous trouverez
define('_PS_MODE_DEV_', false);
    3.    Changez alors par
define('_PS_MODE_DEV_', true);

Link to comment
Share on other sites

Eurêka !!! Ça fonctionne !!! :D

Voici la fonction hookProductTabContent du fichier productcomments.php

    public function hookProductTabContent($params)
    {
	
		require_once(dirname(__FILE__).'/ProductComment.php');
		require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
		
		$id_product = Tools::getValue('id_product');
		$product_average = 0;
	 
		$grades = ProductComment::getGradeByProduct($id_product, $this->context->language->id);
		$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
		$grade_total = 0;
		
		if (count($grades) > 0)
		{
			foreach ($criterions as $criterion)
			{
				if (isset($grades[$criterion['id_product_comment_criterion']]))
				{
					$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
				}
			}
		 
			$product_average = $grade_total / count($criterions);
		}		

		$this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js');
		$this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js');
		$this->context->controller->addJS($this->_path.'js/productcomments.js');

		$id_guest = (!$id_customer = (int)$this->context->cookie->id_customer) ? (int)$this->context->cookie->id_guest : false;
		$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)$this->context->cookie->id_customer, true, (int)$id_guest);

		$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), $this->context->language->id);
		$averageTotal = 0;
		foreach ($averages as $average)
			$averageTotal += (float)($average);
		$averageTotal = $averages;

		$image = Product::getCover((int)Tools::getValue('id_product'));
		
		$this->context->smarty->assign(array(
			'logged' => (int)$this->context->customer->isLogged(true),
			'action_url' => '',
			'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, $this->context->cookie->id_customer),
			'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id),
			'averages' => $averages,
			'product_comment_path' => $this->_path,
			'averageTotal' => $averageTotal,
			'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
			'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
			'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'),
			'id_product_comment_form' => (int)Tools::getValue('id_product'),
			'secure_key' => $this->secure_key,
			'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
			'mediumSize' => Image::getSize('medium'),
			'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')),
			'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments'),
			'productcomments_url_rewriting_activated' => Configuration::get('PS_REWRITING_SETTINGS', 0),
			'average_total'=> (int)$product_average,
			'grades' => $grades
		));

		$this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')));
		
		return ($this->display(__FILE__, '/productcomments.tpl'));
	}

Et la div du template productcomments.tpl

					<div id="details_comment" style="border-top:1px solid #EEEEEE;padding-top:10px">
						{if $criterions|@count > 0}
								<table>
									<tr>
										<div>
										{foreach from=$criterions item=c name=criterion}  
											{foreach from=$grades item=grade} 
												{if $grade.id_product_comment == $comment.id_product_comment AND $grade.id_product_comment_criterion == $c.id_product_comment_criterion} 
													{assign var='grading' value=$grade.grade}
												{/if}
											{/foreach} 
											<div style="float: left;"> 
												<span style="width:60px;font-weight: normal;">{$c.name|escape:'html':'UTF-8'}</span>
												<div style="display: inline-block; margin: 0 0 0 7px;"> 
													{section loop=6 step=1 start=1 name=average} 
														<input style="float:right" class="auto-submit-star" disabled="disabled" type="radio" name="{$smarty.foreach.comments.iteration|escape:'html':'UTF-8'}_{$smarty.foreach.criterion.iteration}_{$smarty.section.average.index}" value="{$smarty.section.average.index}" {if $grading|round neq 0 and $smarty.section.average.index eq $grading|round}checked="checked"{/if} />   
													{/section}
												</div>
											</div>   
										{/foreach}
										</div>
									</tr>
							</table>
						{/if}
					</div>

Encore Merci à Indesign.

 

Ne reste plus qu'à implémenter une petite fonction JS pour afficher/cacher le détail des notes...

  • Like 2
Link to comment
Share on other sites

Bonsoir Switchboard,

 

Excellent. ;) 

 

Si tu t'intéresses au module de commentaire

https://github.com/PrestaShop/PrestaShop/pull/831

https://github.com/PrestaShop/PrestaShop/pull/830

https://github.com/PrestaShop/PrestaShop/pull/832

https://github.com/PrestaShop/PrestaShop/pull/845

Maybe, this can be improve by adding a link to the module for validate the new comment

Une idée pour implémenter ceci ? :huh:

 

PS : Lorsque le produit contient plusieurs commentaires, la note du dernier critère n'est pas bonne.

Commentaire :  2

Note moyenne : 2

Quality  : 2

Prix : 2    (il affiche 0)

Link to comment
Share on other sites

Bonjour Switchboad,

 

Ce que tu souhaites implémenter est le lien pour la modération ?

Oui, un lien, dans l'email envoyé,  vers le module product comments pour valider ou supprimer le nouveau commentaire.

 

Chez moi, lorsque le produit contient plusieurs commentaires, il n'y a pas d'erreur.

Merci, je vais regarder cela de plus près.

 

Je rajoute la capture

Lorsque le produit contient plusieurs commentaires, la note du dernier critère n'est pas bonne.

Commentaire :  2

Note moyenne : 2

Quality  : 2

Prix : 2    (il affiche 0)

Link to comment
Share on other sites

En ce qui concerne le lien cela va être compliqué vu que la modération est géré par un onclik...

Non, pas la validation ou la suppression du commentaire directement du lien.

"Juste" un lien, dans l'email envoyé, vers le BO, dans la configuration du module product comments, pour ensuite valider ou supprimer le nouveau commentaire. Plus clair maintenant ? :)

Link to comment
Share on other sites

Bonjour,

 

J'essaye d'implémenter la possibilité d'afficher ou non la div "details_comment".

 

J'ai ajouté ceci après la date du commentaire:

<a href="#" id="voir" style="float:right">voir plus</a>

Ce que j'ai fait et qui fonctionne:

- ajout de

id="details_comment-{$comment.id_product_comment}"

Cela ajoute correctement l'id du commentaire

 

Ce qui ne fonctionne pas (tout :wacko: ):

Dans productcomments.js

$(document).ready(function(){
$('#details_comment-'+id).hide();
$('a#voir').click(function(){
$('#details_comment-'+id).slideToggle(400);
return false;});
});

Visiblement mon petit code JS ne fonctionne pas

Link to comment
Share on other sites

Résolu

productcomments.js

function toggle_div(bouton, id) { // On déclare la fonction toggle_div qui prend en param le bouton et un id
  var div = document.getElementById(id); // On récupère le div ciblé grâce à l'id
  if(div.style.display=="none") { // Si le div est masqué...
    div.style.display = "block"; // ... on l'affiche...
    bouton.innerHTML = "Cacher"; // ... et on change le contenu du bouton.
  } else { // S'il est visible...
    div.style.display = "none"; // ... on le masque...
    bouton.innerHTML = "Voir"; // ... et on change le contenu du bouton.
  }
}

Dans productcomment.tpl

					<div style="margin-bottom:6px" class="comment_author_infos">
						<strong>{$comment.customer_name|escape:'html':'UTF-8'}</strong><br/>
						<em>{dateFormat date=$comment.date_add|escape:'html':'UTF-8' full=0}</em>
						<button style="float:right" type="button" onclick="toggle_div(this,'details_comment-{$comment.id_product_comment}');">Voir</button>
					</div>

Voiloù :D

  • Like 1
Link to comment
Share on other sites

Petites modifications concernant l'affichage ou non de la div.

 

Boutton => + ou -

Balise Title => changement dynamique

 

productcomments.js

function toggle_div(bouton, id) { // On déclare la fonction toggle_div qui prend en param le bouton et un id
  var div = document.getElementById(id); // On récupère le div ciblé grâce à l'id
  if(div.style.display=="none") { // Si le div est masqué...
    div.style.display = "block"; // ... on l'affiche...
    bouton.innerHTML = "-"; // ... et on change le contenu du bouton...
	bouton.title = "Cacher le d\351tail des notes"; // ... et on change le contenu du title.
  } else { // S'il est visible...
    div.style.display = "none"; // ... on le masque...
    bouton.innerHTML = "+"; // ... et on change le contenu du bouton...
	bouton.title = "Afficher le d\351tail des notes";// ... et on change le contenu du title.
  }
}

productcomments.tpl

<button title="Afficher le détail des notes" style="float:right" type="button" onclick="toggle_div(this,'details_comment-{$comment.id_product_comment}');">+</button>
Link to comment
Share on other sites

Un début de piste pour les critères et les notes BO (ce n'est pas finaliser : manque la boucle pour chaque critère)

 

En s'appuyant sur 

	private function _displayFormApplicationCriterion()
	{
		include_once(dirname(__FILE__).'/ProductCommentCriterion.php');

		$criterions = ProductCommentCriterion::getCriterions($this->context->language->id, false, true);
		$id_criterion = (int)Tools::getValue('updateCriterion');

		if ($id_criterion)
		{
			$criterion = new ProductCommentCriterion((int)$id_criterion);
			if ($criterion->id_product_comment_criterion_type == 2)
			{
				$categories = Category::getSimpleCategories($this->context->language->id);
				$criterion_categories = $criterion->getCategories();
			}
			else if ($criterion->id_product_comment_criterion_type == 3)
			{
				$criterion_products = $criterion->getProducts();
				$products = Product::getSimpleProducts($this->context->language->id);
			}
		}

		foreach ($criterions as $key => $foo)
			if ($foo['id_product_comment_criterion_type'] == 1)
				unset($criterions[$key]);

		if (count($criterions))
		{
	private function _displayFormDelete()
	{

		include_once(dirname(__FILE__).'/ProductCommentCriterion.php');

		$criterions = ProductCommentCriterion::getCriterions($this->context->language->id, false, true);
		$id_criterion = (int)Tools::getValue('updateCriterion');
		

				require_once(dirname(__FILE__).'/ProductComment.php');
				$comments = ProductComment::getAll();
				if (count($comments))
				{
					$this->_html .= '
					<fieldset class="width2">
					<form action="'.Tools::safeOutput($this->_baseUrl).'" method="post" name="delete_comment_form">
					<input type="hidden" name="delete_id_product_comment[]" id="delete_id_product_comment" />
					<input type="hidden" name="delete_action" id="delete_action" />
					<br /><table class="table" border="0" cellspacing="0" cellpadding="0">
					<thead>
					<tr>
						<th><input class="noborder" type="checkbox" name="delete_id_product_comment[]" onclick="checkDelBoxes(this.form, \'delete_id_product_comment[]\', this.checked)" /></th>
						<th style="width:150px;">'.$this->l('Author').'</th>
						<th style="width:150px;">'.$this->l('Title').'</th>
						<th style="width:550px;">'.$this->l('Comment').'</th>
						<th style="width:150px;">'.$this->l('Date add').'</th>
						<th style="width:150px;">'.$this->l('Criterion').'</th>
						<th style="width:150px;">'.$this->l('grade').'</th>
						<th style="width:150px;">'.$this->l('Product name').'</th>
						<th style="width:30px;">'.$this->l('Actions').'</th>
					</tr>
					</thead>
					<tbody>';
					foreach ($comments as $comment)
 						foreach ($criterions as $criterion)
						{
						$this->_html .= '<tr>
						<td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="delete_id_product_comment[]" /></td>
						<td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td>
						<td>'.htmlspecialchars($comment['title'], ENT_COMPAT, 'UTF-8').'</td>
						<td>'.htmlspecialchars($comment['content'], ENT_COMPAT, 'UTF-8').'</td>
						<td>'.htmlspecialchars($comment['date_add'], ENT_COMPAT, 'UTF-8').'</td>
						<td>'.htmlspecialchars($criterion['name'], ENT_COMPAT, 'UTF-8').'</td>
						<td>'.htmlspecialchars($comment['grade'], ENT_COMPAT, 'UTF-8').'</td>
						<td>'.$comment['id_product'].' - '.htmlspecialchars($comment['name'], ENT_COMPAT, 'UTF-8').'</td>
						<td><a href="javascript:;" onclick="delComment(\''.(int)($comment['id_product_comment']).'\',\''.$this->l('Are you sure?').'\');"><img src="'.$this->_path.'img/delete.png" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a></td>
						</tr>';
						$this->_html .= '
						<tr>
							<td colspan="3" style="font-weight:bold;text-align:right">'.$this->l('Selection:').'</td>
							<td><a href="javascript:;" onclick="delComment(0);"><img src="'.$this->_path.'img/delete.png" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a></td>
						</tr>
						</tbody>
					</table>
					</form>';
				}
				}
				else
					$this->_html .= $this->l('No comments to manage at this time.');

		$this->_html .= '</fieldset><br />';
	}

post-459329-0-07066000-1383822755_thumb.png

Edited by indesign (see edit history)
Link to comment
Share on other sites

  • 2 months later...

 

Lorsque le produit contient plusieurs commentaires, la note du dernier critère n'est pas bonne.

Commentaire :  2

Note moyenne : 2

Quality  : 2

Prix : 2    (il affiche 0)

 

Salut,

 

Je me permets de relancer ce sujet car j'ai essayé la manipulation mais je m’arrête au même problème qu'Indesign...

 

Qui aurait une solution ?

Je suis en 1.5.6.1

Edited by m.anton11 (see edit history)
Link to comment
Share on other sites

Eurêka !!! Ça fonctionne !!! :D

Voici la fonction hookProductTabContent du fichier productcomments.php

    public function hookProductTabContent($params)
    {
	
		require_once(dirname(__FILE__).'/ProductComment.php');
		require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
		
		$id_product = Tools::getValue('id_product');
		$product_average = 0;
	 
		$grades = ProductComment::getGradeByProduct($id_product, $this->context->language->id);
		$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
		$grade_total = 0;
		
		if (count($grades) > 0)
		{
			foreach ($criterions as $criterion)
			{
				if (isset($grades[$criterion['id_product_comment_criterion']]))
				{
					$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
				}
			}
		 
			$product_average = $grade_total / count($criterions);
		}		

		$this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js');
		$this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js');
		$this->context->controller->addJS($this->_path.'js/productcomments.js');

		$id_guest = (!$id_customer = (int)$this->context->cookie->id_customer) ? (int)$this->context->cookie->id_guest : false;
		$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)$this->context->cookie->id_customer, true, (int)$id_guest);

		$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), $this->context->language->id);
		$averageTotal = 0;
		foreach ($averages as $average)
			$averageTotal += (float)($average);
		$averageTotal = $averages;

		$image = Product::getCover((int)Tools::getValue('id_product'));
		
		$this->context->smarty->assign(array(
			'logged' => (int)$this->context->customer->isLogged(true),
			'action_url' => '',
			'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, $this->context->cookie->id_customer),
			'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id),
			'averages' => $averages,
			'product_comment_path' => $this->_path,
			'averageTotal' => $averageTotal,
			'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
			'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
			'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'),
			'id_product_comment_form' => (int)Tools::getValue('id_product'),
			'secure_key' => $this->secure_key,
			'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
			'mediumSize' => Image::getSize('medium'),
			'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')),
			'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments'),
			'productcomments_url_rewriting_activated' => Configuration::get('PS_REWRITING_SETTINGS', 0),
			'average_total'=> (int)$product_average,
			'grades' => $grades
		));

		$this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')));
		
		return ($this->display(__FILE__, '/productcomments.tpl'));
	}

Et la div du template productcomments.tpl

					<div id="details_comment" style="border-top:1px solid #EEEEEE;padding-top:10px">
						{if $criterions|@count > 0}
								<table>
									<tr>
										<div>
										{foreach from=$criterions item=c name=criterion}  
											{foreach from=$grades item=grade} 
												{if $grade.id_product_comment == $comment.id_product_comment AND $grade.id_product_comment_criterion == $c.id_product_comment_criterion} 
													{assign var='grading' value=$grade.grade}
												{/if}
											{/foreach} 
											<div style="float: left;"> 
												<span style="width:60px;font-weight: normal;">{$c.name|escape:'html':'UTF-8'}</span>
												<div style="display: inline-block; margin: 0 0 0 7px;"> 
													{section loop=6 step=1 start=1 name=average} 
														<input style="float:right" class="auto-submit-star" disabled="disabled" type="radio" name="{$smarty.foreach.comments.iteration|escape:'html':'UTF-8'}_{$smarty.foreach.criterion.iteration}_{$smarty.section.average.index}" value="{$smarty.section.average.index}" {if $grading|round neq 0 and $smarty.section.average.index eq $grading|round}checked="checked"{/if} />   
													{/section}
												</div>
											</div>   
										{/foreach}
										</div>
									</tr>
							</table>
						{/if}
					</div>

Encore Merci à Indesign.

 

Ne reste plus qu'à implémenter une petite fonction JS pour afficher/cacher le détail des notes...

 

Bonjour,

 

C'est exactement cette modification que je cherche. Cependant, en remplacant les bouts de code données ci dessus dans les 2 fichiers concernés, je ne vois apparaitre aucune modification.

J'ai vérifié le code source de la page, la <div id="details_comment"> n'apparait même pas.

 

Avez vous une idée de ce qu'il pourrait s'agir ?

 

Je suis en version 1.5.4.1.

 

Merci beaucoup !

Link to comment
Share on other sites

Avez-vous :

- Supprimé le contenu des répertoires (sauf index.php) :

- cache/smarty/cache & compile

- themes/votre_theme/cache

- Forcé la compilation des templates

- Désactivé le cache dans BO/Performances

- Supprimé class_index.php du répertoire cache

- Vidé le cache de votre navigateur

Link to comment
Share on other sites

Avez-vous :

- Supprimé le contenu des répertoires (sauf index.php) :

- cache/smarty/cache & compile

- themes/votre_theme/cache

- Forcé la compilation des templates

- Désactivé le cache dans BO/Performances

- Supprimé class_index.php du répertoire cache

- Vidé le cache de votre navigateur

 

J'ai effectué toutes ces modifications mais rien n'est pris en compte...

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Bonjour à tous,

 

Je suis en pleine préparation de migration vers PS 1.6 et la modification apportée fonctionne en partie...

 

Un bug s'est glissé au niveau des différentes notes...

 

post-396139-0-81978300-1400150620_thumb.png

 

O peut voir sur l'image que les différentes notes ne sont correctes...

 

Si vous avez des idées, je suis preneur.

 

Merci à tous

 

PS : Dès que j'aurai réglé le problème je posterai le zip pour PS 1.6

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 1 year later...
  • 7 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...