[-] MO : productComments fixed
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8220 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -32,37 +32,37 @@ if (!defined('_PS_VERSION_'))
|
||||
class ProductComment extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
|
||||
/** @var integer Product's id */
|
||||
public $id_product;
|
||||
|
||||
|
||||
/** @var integer Customer's id */
|
||||
public $id_customer;
|
||||
|
||||
/** @var integer Guest's id */
|
||||
public $id_guest;
|
||||
|
||||
|
||||
|
||||
|
||||
/** @var integer Customer name */
|
||||
public $customer_name;
|
||||
|
||||
|
||||
/** @var string Title */
|
||||
public $title;
|
||||
|
||||
|
||||
/** @var string Content */
|
||||
public $content;
|
||||
|
||||
|
||||
/** @var integer Grade */
|
||||
public $grade;
|
||||
|
||||
|
||||
/** @var boolean Validate */
|
||||
public $validate = 0;
|
||||
|
||||
|
||||
public $deleted = 0;
|
||||
|
||||
|
||||
/** @var string Object creation date */
|
||||
public $date_add;
|
||||
|
||||
|
||||
protected $fieldsRequired = array('id_product', 'id_customer', 'content');
|
||||
protected $fieldsSize = array('content' => 65535);
|
||||
protected $fieldsValidate = array('id_product' => 'isUnsignedId', 'id_customer' => 'isUnsignedId', 'content' => 'isMessage',
|
||||
@@ -86,7 +86,7 @@ class ProductComment extends ObjectModel
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
return ($fields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get comments by IdProduct
|
||||
*
|
||||
@@ -103,13 +103,13 @@ class ProductComment extends ObjectModel
|
||||
$p = 1;
|
||||
if ($n != null AND $n <= 0)
|
||||
$n = 5;
|
||||
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT pc.`id_product_comment`,
|
||||
(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment` AND pcu.`usefulness` = 1) as total_useful,
|
||||
SELECT pc.`id_product_comment`,
|
||||
(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment` AND pcu.`usefulness` = 1) as total_useful,
|
||||
(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment`) as total_advice, '.
|
||||
($id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcuc WHERE pcuc.`id_product_comment` = pc.`id_product_comment` AND pcuc.id_customer = '.(int)$id_customer.') as customer_advice, ' : '').
|
||||
($id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_report` pcrc WHERE pcrc.`id_product_comment` = pc.`id_product_comment` AND pcrc.id_customer = '.(int)$id_customer.') as customer_report, ' : '').'
|
||||
((int)$id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcuc WHERE pcuc.`id_product_comment` = pc.`id_product_comment` AND pcuc.id_customer = '.(int)$id_customer.') as customer_advice, ' : '').
|
||||
((int)$id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_report` pcrc WHERE pcrc.`id_product_comment` = pc.`id_product_comment` AND pcrc.id_customer = '.(int)$id_customer.') as customer_report, ' : '').'
|
||||
IF(c.id_customer, CONCAT(c.`firstname`, \' \', LEFT(c.`lastname`, 1)), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pc.title
|
||||
FROM `'._DB_PREFIX_.'product_comment` pc
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = pc.`id_customer`
|
||||
@@ -117,7 +117,7 @@ class ProductComment extends ObjectModel
|
||||
ORDER BY pc.`date_add` DESC
|
||||
'.($n ? 'LIMIT '.(int)(($p - 1) * $n).', '.(int)($n) : ''));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return customer's comment
|
||||
*
|
||||
@@ -126,19 +126,19 @@ class ProductComment extends ObjectModel
|
||||
public static function getByCustomer($id_product, $id_customer, $last = false, $id_guest = false)
|
||||
{
|
||||
$results = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'product_comment` pc
|
||||
WHERE pc.`id_product` = '.(int)($id_product).' AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)($id_customer) : 'pc.`id_guest` = '.(int)($id_guest)).'
|
||||
ORDER BY pc.`date_add` DESC '
|
||||
.($last ? 'LIMIT 1' : '')
|
||||
);
|
||||
|
||||
if ($last)
|
||||
|
||||
if ($last)
|
||||
return array_shift($results);
|
||||
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Grade By product
|
||||
*
|
||||
@@ -151,6 +151,7 @@ class ProductComment extends ObjectModel
|
||||
die(Tools::displayError());
|
||||
$validate = Configuration::get('PRODUCT_COMMENTS_MODERATE');
|
||||
|
||||
|
||||
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT pc.`id_product_comment`, pcg.`grade`, pccl.`name`, pcc.`id_product_comment_criterion`
|
||||
FROM `'._DB_PREFIX_.'product_comment` pc
|
||||
@@ -162,6 +163,23 @@ class ProductComment extends ObjectModel
|
||||
($validate == '1' ? ' AND pc.`validate` = 1' : '')));
|
||||
}
|
||||
|
||||
public static function getAverageGrade($id_product)
|
||||
{
|
||||
$validate = Configuration::get('PRODUCT_COMMENTS_MODERATE');
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT SUM(pc.`grade`) /
|
||||
(SELECT COUNT(pc.`grade`)
|
||||
FROM `'._DB_PREFIX_.'product_comment` pc
|
||||
WHERE pc.`id_product` = '.(int)($id_product).'
|
||||
AND pc.`deleted` = 0'.
|
||||
($validate == '1' ? ' AND pc.`validate` = 1' : '').') AS grade
|
||||
FROM `'._DB_PREFIX_.'product_comment` pc
|
||||
WHERE pc.`id_product` = '.(int)($id_product).'
|
||||
AND pc.`deleted` = 0'.
|
||||
($validate == '1' ? ' AND pc.`validate` = 1' : ''));
|
||||
}
|
||||
|
||||
public static function getAveragesByProduct($id_product, $id_lang)
|
||||
{
|
||||
/* Get all grades */
|
||||
@@ -232,12 +250,12 @@ class ProductComment extends ObjectModel
|
||||
return (Db::getInstance()->ExecuteS('
|
||||
SELECT pc.`id_product_comment`, pc.`id_product`, IF(c.id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product_comment` pc
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = pc.`id_customer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = pc.`id_product` AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Context::getContext()->shop->sqlLang('pl').')
|
||||
WHERE pc.`validate` = '.(int)($validate).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = pc.`id_customer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = pc.`id_product` AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Context::getContext()->shop->sqlLang('pl').')
|
||||
WHERE pc.`validate` = '.(int)($validate).'
|
||||
ORDER BY pc.`date_add` DESC'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate a comment
|
||||
*
|
||||
@@ -252,7 +270,7 @@ class ProductComment extends ObjectModel
|
||||
`validate` = '.(int)($validate).'
|
||||
WHERE `id_product_comment` = '.(int)($this->id)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete Grades
|
||||
*
|
||||
@@ -266,7 +284,7 @@ class ProductComment extends ObjectModel
|
||||
DELETE FROM `'._DB_PREFIX_.'product_comment_grade`
|
||||
WHERE `id_product_comment` = '.(int)($id_product_comment)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete Reports
|
||||
*
|
||||
@@ -280,7 +298,7 @@ class ProductComment extends ObjectModel
|
||||
DELETE FROM `'._DB_PREFIX_.'product_comment_report`
|
||||
WHERE `id_product_comment` = '.(int)($id_product_comment)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete usefulness
|
||||
*
|
||||
@@ -295,7 +313,7 @@ class ProductComment extends ObjectModel
|
||||
DELETE FROM `'._DB_PREFIX_.'product_comment_usefulness`
|
||||
WHERE `id_product_comment` = '.(int)($id_product_comment)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Report comment
|
||||
*
|
||||
@@ -305,9 +323,9 @@ class ProductComment extends ObjectModel
|
||||
{
|
||||
return (Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'product_comment_report` (`id_product_comment`, `id_customer`)
|
||||
VALUES ('.(int)$id_product_comment.', '.$id_customer.')'));
|
||||
VALUES ('.(int)$id_product_comment.', '.(int)$id_customer.')'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Comment already report
|
||||
*
|
||||
@@ -316,12 +334,12 @@ class ProductComment extends ObjectModel
|
||||
public static function isAlreadyReport($id_product_comment, $id_customer)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product_comment_report`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product_comment_report`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_product_comment` = '.(int)($id_product_comment));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set comment usefulness
|
||||
*
|
||||
@@ -333,7 +351,7 @@ class ProductComment extends ObjectModel
|
||||
INSERT INTO `'._DB_PREFIX_.'product_comment_usefulness` (`id_product_comment`, `usefulness`, `id_customer`)
|
||||
VALUES ('.(int)$id_product_comment.', '.(int)$usefulness.', '.(int)$id_customer.')'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usefulness already set
|
||||
*
|
||||
@@ -342,12 +360,12 @@ class ProductComment extends ObjectModel
|
||||
public static function isAlreadyUsefulness($id_product_comment, $id_customer)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product_comment_usefulness`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product_comment_usefulness`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_product_comment` = '.(int)($id_product_comment));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get reported comments
|
||||
*
|
||||
@@ -356,13 +374,13 @@ class ProductComment extends ObjectModel
|
||||
public static function getReportedComments()
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT DISTINCT(pc.`id_product_comment`), pc.`id_product`, IF(c.id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product_comment_report` pcr
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_comment` pc
|
||||
ON pcr.id_product_comment = pc.id_product_comment
|
||||
SELECT DISTINCT(pc.`id_product_comment`), pc.`id_product`, IF(c.id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product_comment_report` pcr
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_comment` pc
|
||||
ON pcr.id_product_comment = pc.id_product_comment
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = pc.`id_customer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = pc.`id_product` AND pl.`id_lang` = '.(int)Context::getContext()->language->id.' AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Context::getContext()->shop->sqlLang('pl').')
|
||||
ORDER BY pc.`date_add` DESC');
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<module>
|
||||
<name>productcomments</name>
|
||||
<displayName><![CDATA[Product Comments]]></displayName>
|
||||
<version><![CDATA[2.1]]></version>
|
||||
<description><![CDATA[Allow users to post comment about a product.]]></description>
|
||||
<version><![CDATA[2.2]]></version>
|
||||
<description><![CDATA[Allows users to post reviews.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[front_office_features]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
|
||||
@@ -4,16 +4,16 @@ global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_7c3b0e9898b88deee7ea75aafd2e37e2'] = 'Note moyenne';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_a71a0229e164fecdcde3c4e0f40473fa'] = 'Lire les avis utilisateurs';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_4ce7fa08d440a1e0fb369b1273e52ac3'] = 'Donner votre avis';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_7966126831926ad29c528b239d69f855'] = 'Donner son avis';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_b78a3223503896721cca1303f776159b'] = 'Titre';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_0be8406951cdfda82f00f79328cf4efc'] = 'Commentaire';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_a2ed44743411cf8b80e397448fce104c'] = 'Votre nom';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_e699583427bd276f34244d23e6072a41'] = 'Tous les champs sont obligatoires';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_70397c4b252a5168c5ec003931cea215'] = 'Champs requis';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_94966d90747b97d1f0f206c98a8b1ac3'] = 'Envoyer';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_e81c4e4f2b7b93b481e13a8553c2ae1b'] = 'ou';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments-extra_ea4788705e6873b424c65e91c2846b19'] = 'Annuler';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_b91c4e8b229a399a3bc911d352524a9b'] = 'Commentaires produits';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_0c21532dfd3476791e5aab1aa7fa7405'] = 'Autorise les utilisateurs à poster des commentaires sur les produits';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_9918811c511f3481c085e46c07ab5da8'] = 'Permet aux client de commenter les produits';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_f4d1ea475eaa85102e2b4e6d95da84bd'] = 'Confirmation';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_c888438d14855d7d96a2724ee9c306bd'] = 'Configuration mise à jour';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_1bb54e382f7dbdb260f0aa6b42bb624b'] = 'Critère supprimé';
|
||||
@@ -59,14 +59,6 @@ $_MODULE['<{productcomments}prestashop>productcomments_af1b98adf7f686b84cd0b443e
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_b718adec73e04ce3ec720dd11a06a308'] = 'ID';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_b9aefa40a54680bb258f9f9569290fae'] = 'Nom du produit';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_99121ab27aaa7472cfada9071c5ba434'] = 'Nom de la catégorie';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_fd4b5401d4d3c7d32d158bfc1e552f3b'] = 'Merci de saisir votre nom';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_7b2f2ea0f690ef3c2fc9bba0e4bfbc4c'] = 'Commentaire invalide.';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_f88dc17737f7fdd4464b2eb922a8f133'] = 'Une erreur est survenue lors de l\'ajout du commentaire.';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_7fa4a3510dafd0eac6435c19861b2bb7'] = 'Commentaire ajouté avec succès.';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_f8694a9aae2eb045920f613cfa7f1235'] = 'En attente d\'une validation modérateur';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_6bf852d9850445291f5e9d4740ac7b50'] = 'Un texte est nécessaire pour publier un commentaire.';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_6d28f2900adb9e500868166f6d04da92'] = 'Vous devez attendre';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_ba8d7ae5dcadfba739f28a777378f208'] = 'secondes avant de poster un nouveau commentaire.';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_4494d00c901c9e22ff3b953177205cea'] = 'Etes vous sur de vouloir signaler ce commentaire?';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_4b3b9db8c9784468094acde0f8bf7071'] = 'Note';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_663fc7093256cda156e571631ddb295e'] = 'personne(s) sur';
|
||||
@@ -75,6 +67,14 @@ $_MODULE['<{productcomments}prestashop>productcomments_39630ad6ee79b8653ea89194c
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_a6105c0a611b41b08f1209506350279e'] = 'oui';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_7fa3b767c460b54a2be4d49030b349c7'] = 'non';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_28b3b1e564a00f572c5d4e21da986d49'] = 'Reporter un abus';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_7966126831926ad29c528b239d69f855'] = 'Donner votre avos';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_b78a3223503896721cca1303f776159b'] = 'Titre';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_a2ed44743411cf8b80e397448fce104c'] = 'Votre nom:';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_70397c4b252a5168c5ec003931cea215'] = 'Champs requis';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_94966d90747b97d1f0f206c98a8b1ac3'] = 'Envoyer';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_e81c4e4f2b7b93b481e13a8553c2ae1b'] = 'ou';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_ea4788705e6873b424c65e91c2846b19'] = 'Annuler';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_fbe2625bf3673be380d043a4bf873f28'] = 'Soyez premier à donner votre avis';
|
||||
$_MODULE['<{productcomments}prestashop>productcomments_08621d00a3a801b9159a11b8bbd69f89'] = 'Aucun commentaire n\'a été publié pour le moment.';
|
||||
$_MODULE['<{productcomments}prestashop>products-comparison_8413c683b4b27cc3f4dbd4c90329d8ba'] = 'Commentaires';
|
||||
$_MODULE['<{productcomments}prestashop>products-comparison_b1897515d548a960afe49ecf66a29021'] = 'Moyenne';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -27,7 +27,11 @@
|
||||
|
||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'/../../init.php');
|
||||
include(dirname(__FILE__).'/ProductComment.php');
|
||||
require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
|
||||
include_once(dirname(__FILE__).'/ProductComment.php');
|
||||
include_once(dirname(__FILE__).'/productcomments.php');
|
||||
|
||||
$productCom = new productcomments();
|
||||
|
||||
if (Tools::getValue('action') AND Tools::getValue('id_product_comment') AND Context::getContext()->cookie->id_customer)
|
||||
{
|
||||
@@ -42,6 +46,85 @@ if (Tools::getValue('action') AND Tools::getValue('id_product_comment') AND Cont
|
||||
die('0');
|
||||
}
|
||||
}
|
||||
elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productCom->secure_key)
|
||||
{
|
||||
$review = Tools::jsonDecode(Tools::getValue('review'));
|
||||
$id_product = 0;
|
||||
$content = null;
|
||||
$title = null;
|
||||
$grades = array();
|
||||
foreach ($review as $entry)
|
||||
{
|
||||
if ($entry->key == "id_product")
|
||||
$id_product = $entry->value;
|
||||
elseif ($entry->key == "title")
|
||||
$title = $entry->value;
|
||||
elseif ($entry->key == "content")
|
||||
$content = $entry->value;
|
||||
elseif (preg_match("/grade/", $entry->key))
|
||||
{
|
||||
$id = array(split("_", $entry->key));
|
||||
$grades[] = array('id' => $id['0']['0'], 'grade' => $entry->value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($title == "" OR $content == "" OR !$id_product OR count($grades) == 0)
|
||||
die('0');
|
||||
|
||||
$allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
|
||||
if (Context::getContext()->customer->id AND (!Context::getContext()->customer->is_guest OR $allow_guests))
|
||||
{
|
||||
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
|
||||
$customerComment = ProductComment::getByCustomer((int)($id_product), Context::getContext()->cookie->id_customer, true, (int)$id_guest);
|
||||
|
||||
if (!$customerComment OR ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) < time()))
|
||||
{
|
||||
$errors = array();
|
||||
$customer_name = false;
|
||||
if ($id_guest AND (!$customer_name = Context::getContext()->customer->firstname . " " . Context::getContext()->customer->lastname))
|
||||
$errors[] = $productCom->l('Please fill your name');
|
||||
if (!sizeof($errors) AND $content)
|
||||
{
|
||||
$comment = new ProductComment();
|
||||
$comment->content = strip_tags($content);
|
||||
$comment->id_product = (int)$id_product;
|
||||
$comment->id_customer = (int)Context::getContext()->cookie->id_customer;
|
||||
$comment->id_guest = (int)$id_guest;
|
||||
$comment->customer_name = pSQL($customer_name);
|
||||
$comment->title = pSQL($title);
|
||||
$comment->grade = 0;
|
||||
$comment->validate = 0;
|
||||
|
||||
if (!$comment->content)
|
||||
$errors[] = $productCom->l('Invalid comment text posted.');
|
||||
else
|
||||
{
|
||||
$tgrade = 0;
|
||||
$comment->save();
|
||||
foreach ($grades as $grade)
|
||||
{
|
||||
$tgrade += $grade['grade'];
|
||||
$productCommentCriterion = new ProductCommentCriterion((int)Tools::getValue('id_product_comment_criterion_'.$grade['id']));
|
||||
if ($productCommentCriterion->id)
|
||||
$productCommentCriterion->addGrade($comment->id, $grade['grade']);
|
||||
}
|
||||
|
||||
if ((count($grades) - 1) >= 0)
|
||||
$comment->grade = (int)($tgrade / ((int)count($grades)));
|
||||
|
||||
if (!$comment->save())
|
||||
$errors[] = $productCom->l('An error occurred while saving your comment.');
|
||||
else
|
||||
Context::getContext()->smarty->assign('confirmation', $productCom->l('Comment posted.').((int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')) ? ' '.$productCom->l('Awaiting moderator validation.') : ''));
|
||||
}
|
||||
}
|
||||
else
|
||||
$errors[] = $productCom->l('Comment text is required.');
|
||||
}
|
||||
else
|
||||
$errors[] = $productCom->l('You should wait').' '.Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME').' '.$productCom->l('seconds before posting a new comment');
|
||||
}
|
||||
}
|
||||
|
||||
die('1');
|
||||
|
||||
|
||||
@@ -53,6 +53,27 @@
|
||||
$('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
|
||||
$('a[href="#idTab5"]').addClass('selected');
|
||||
{literal}}{/literal});
|
||||
{literal}
|
||||
$('#submitMessage').click(function(){
|
||||
var datas = [];
|
||||
$('#fancybox-content').find('input, textarea, select').each(function(index){
|
||||
var o = {}
|
||||
o.key = $(this).attr('name');
|
||||
o.value = $(this).val();
|
||||
datas.push(o);
|
||||
});
|
||||
console.log(datas);
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}productcomments-ajax.php",{literal}
|
||||
post: "POST",
|
||||
data: {action: 'sendComment', secure_key: '{/literal}{$secure_key}{literal}', review: JSON.stringify(datas)},{/literal}{literal}
|
||||
dataType: "json",
|
||||
success: function(result){
|
||||
$.fancybox.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
{/literal}
|
||||
{literal}}{/literal});
|
||||
</script>
|
||||
|
||||
@@ -72,14 +93,12 @@
|
||||
<div class="comments_advices">
|
||||
<a href="#idTab5">{l s='Read user reviews' mod='productcomments'} ({$nbComments})</a><br/>
|
||||
{if ($too_early == false AND ($logged OR $allow_guests))}
|
||||
<a id="new_comment_btn" href="#new_comment_form">{l s='Give your advice' mod='productcomments'}</a>
|
||||
<a id="new_comment_btn" href="#new_comment_form">{l s='Write your review' mod='productcomments'}</a>
|
||||
{/if}
|
||||
</div>
|
||||
<div style="display: none;">
|
||||
<div id="new_comment_form">
|
||||
<form action="{$action_url}" method="post" id="sendComment">
|
||||
<h2 class="title">{l s='Give your advice' mod='productcomments'}</h2>
|
||||
|
||||
<h2 class="title">{l s='Write your review' mod='productcomments'}</h2>
|
||||
<div class="product clearfix">
|
||||
<img src="{$link->getImageLink($product->link_rewrite, $productcomment_cover, 'home')}" height="{$homeSize.height}" width="{$homeSize.width}" alt="{$product->name|escape:html:'UTF-8'}" />
|
||||
<div class="product_desc">
|
||||
@@ -89,7 +108,7 @@
|
||||
</div>
|
||||
|
||||
<div class="new_comment_form_content">
|
||||
<p class="intro_form">{l s='Give your advice' mod='productcomments'}</p>
|
||||
<p class="intro_form">{l s='Write your review' mod='productcomments'}</p>
|
||||
{if $criterions|@count > 0}
|
||||
<div class="grade_content clearfix">
|
||||
{section loop=$criterions name=i start=0 step=1}
|
||||
@@ -110,26 +129,27 @@
|
||||
<div class="form_contenair">
|
||||
<p class="text">
|
||||
<label for="comment_title">{l s='Title' mod='productcomments'} <sup>*</sup>:</label>
|
||||
<input name="title" type="text" value=""/>
|
||||
<input id="commentTitle" name="title" type="text" value=""/>
|
||||
</p>
|
||||
<p class="textarea">
|
||||
<label for="content">{l s='Comment' mod='productcomments'} <sup>*</sup>:</label>
|
||||
<textarea name="content"></textarea>
|
||||
<textarea id="commentContent" name="content"></textarea>
|
||||
</p>
|
||||
{if $allow_guests == true && $logged == 0}
|
||||
<p class="text">
|
||||
<label>{l s='Your name:' mod='productcomments'} <sup>*</sup>:</label>
|
||||
<input name="customer_name" type="text" value=""/>
|
||||
<input id="commentCustomerName" name="customer_name" type="text" value=""/>
|
||||
</p>
|
||||
{/if}
|
||||
<p class="submit">
|
||||
<span class="txt_required">* {l s='All ths fields are mandatory' mod='productcomments'}</span>
|
||||
<button name="submitMessage" type="submit">{l s='Send' mod='productcomments'}</button>
|
||||
<span class="txt_required">* {l s='Required fields' mod='productcomments'}</span>
|
||||
<input id="id_product_comment_send" name="id_product" type="hidden" value='{$id_product_comment_form}'></input>
|
||||
<button id="submitMessage" name="submitMessage" type="submit">{l s='Send' mod='productcomments'}</button>
|
||||
{l s='or' mod='productcomments'} <a href="#" onclick="$.fancybox.close();">{l s='Cancel' mod='productcomments'}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div><!-- /end new_comment_form_content -->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /Module ProductComments -->
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -34,10 +34,10 @@ class ProductComments extends Module
|
||||
|
||||
private $_html = '';
|
||||
private $_postErrors = array();
|
||||
|
||||
|
||||
private $_productCommentsCriterionTypes = array();
|
||||
private $_baseUrl;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'productcomments';
|
||||
@@ -45,11 +45,12 @@ class ProductComments extends Module
|
||||
$this->version = '2.2';
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
$this->secure_key = Tools::encrypt($this->name);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Product Comments');
|
||||
$this->description = $this->l('Allow users to post comment about a product.');
|
||||
$this->description = $this->l('Allows users to post reviews.');
|
||||
}
|
||||
|
||||
public function install()
|
||||
@@ -58,30 +59,50 @@ class ProductComments extends Module
|
||||
return false;
|
||||
elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
|
||||
return false;
|
||||
$sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
|
||||
$sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
|
||||
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
|
||||
|
||||
foreach ($sql AS $query)
|
||||
if (!Db::getInstance()->Execute(trim($query)))
|
||||
return false;
|
||||
if (parent::install() == false OR $this->registerHook('productTab') == false
|
||||
OR $this->registerHook('extraProductComparison') == false OR $this->registerHook('productTabContent') == false
|
||||
OR $this->registerHook('header') == false OR $this->registerHook('productOutOfStock') == false OR !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30)
|
||||
OR !Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0)
|
||||
OR !Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1))
|
||||
return false;
|
||||
if (parent::install() == false
|
||||
OR !$this->registerHook('productTab')
|
||||
OR !$this->registerHook('extraProductComparison') OR !$this->registerHook('productTabContent')
|
||||
OR !$this->registerHook('header') OR !$this->registerHook('productOutOfStock')
|
||||
OR !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30)
|
||||
OR !Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0)
|
||||
OR !Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function uninstall()
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
if (!parent::uninstall() OR !Configuration::deleteByName('PRODUCT_COMMENTS_MODERATE') OR !Configuration::deleteByName('PRODUCT_COMMENTS_ALLOW_GUESTS') OR !Configuration::deleteByName('PRODUCT_COMMENTS_MINIMAL_TIME'))
|
||||
return false;
|
||||
if (!parent::uninstall() OR !$this->deleteTables()
|
||||
OR !Configuration::deleteByName('PRODUCT_COMMENTS_MODERATE')
|
||||
OR !Configuration::deleteByName('PRODUCT_COMMENTS_ALLOW_GUESTS') OR !Configuration::deleteByName('PRODUCT_COMMENTS_MINIMAL_TIME')
|
||||
OR !$this->unregisterHook('extraProductComparison') OR !$this->unregisterHook('productOutOfStock') OR !$this->unregisterHook('productTabContent')
|
||||
OR !$this->unregisterHook('header') OR !$this->unregisterHook('productTab'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function deleteTables()
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
|
||||
DROP TABLE IF EXISTS
|
||||
`'._DB_PREFIX_.'product_comment`,
|
||||
`'._DB_PREFIX_.'product_comment_criterion`,
|
||||
`'._DB_PREFIX_.'product_comment_criterion_product`,
|
||||
`'._DB_PREFIX_.'product_comment_criterion_lang`,
|
||||
`'._DB_PREFIX_.'product_comment_criterion_category`,
|
||||
`'._DB_PREFIX_.'product_comment_grade`,
|
||||
`'._DB_PREFIX_.'product_comment_usefulness`,
|
||||
`'._DB_PREFIX_.'product_comment_report`');
|
||||
}
|
||||
|
||||
protected function _postProcess()
|
||||
{
|
||||
{
|
||||
if (Tools::isSubmit('submitModerate'))
|
||||
{
|
||||
Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', (int)Tools::getValue('moderate'));
|
||||
@@ -97,12 +118,12 @@ class ProductComments extends Module
|
||||
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Criterion deleted').'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
include_once(dirname(__FILE__).'/ProductCommentCriterion.php');
|
||||
|
||||
$this->_setBaseUrl();
|
||||
|
||||
$this->_setBaseUrl();
|
||||
$this->_productCommentsCriterionTypes = ProductCommentCriterion::getTypes();
|
||||
$this->_html = '<h2>'.$this->displayName.'</h2>';
|
||||
$this->_postProcess();
|
||||
@@ -110,10 +131,10 @@ class ProductComments extends Module
|
||||
$this->_checkReportedComment();
|
||||
$this->_checkCriterion();
|
||||
$this->_updateApplicationCriterion();
|
||||
|
||||
|
||||
return $this->_html.$this->_displayForm();
|
||||
}
|
||||
|
||||
|
||||
private function _setBaseUrl()
|
||||
{
|
||||
$this->_baseUrl = 'index.php?';
|
||||
@@ -122,7 +143,7 @@ class ProductComments extends Module
|
||||
$this->_baseUrl .= $k.'='.$value.'&';
|
||||
$this->_baseUrl = rtrim($this->_baseUrl, '&');
|
||||
}
|
||||
|
||||
|
||||
private function _checkModerateComment()
|
||||
{
|
||||
$action = Tools::getValue('action');
|
||||
@@ -130,7 +151,7 @@ class ProductComments extends Module
|
||||
(int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')))
|
||||
{
|
||||
$product_comments = Tools::getValue('id_product_comment');
|
||||
|
||||
|
||||
if (sizeof($product_comments))
|
||||
{
|
||||
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||
@@ -161,14 +182,14 @@ class ProductComments extends Module
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _checkReportedComment()
|
||||
{
|
||||
$action = Tools::getValue('action');
|
||||
if (empty($action) === false)
|
||||
{
|
||||
$product_comments = Tools::getValue('id_product_comment');
|
||||
|
||||
|
||||
if (sizeof($product_comments))
|
||||
{
|
||||
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||
@@ -202,7 +223,7 @@ class ProductComments extends Module
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _checkCriterion()
|
||||
{
|
||||
$action_criterion = Tools::getValue('criterion_action');
|
||||
@@ -215,7 +236,7 @@ class ProductComments extends Module
|
||||
$productCommentCriterion = new ProductCommentCriterion((int)$id_criterion);
|
||||
foreach ($languages AS $lang)
|
||||
$productCommentCriterion->name[(int)$lang['id_lang']] = Tools::getValue('criterion_'.(int)$lang['id_lang']);
|
||||
|
||||
|
||||
// Check default language criterion name
|
||||
$defaultLanguage = new Language((int)(Configuration::get('PS_LANG_DEFAULT')));
|
||||
if (!Tools::getValue('criterion_'.$defaultLanguage->id))
|
||||
@@ -223,10 +244,10 @@ class ProductComments extends Module
|
||||
$this->_html .= '<div class="error"><img src="../img/admin/error2.png" />'.$this->l('The field <b>Name</b> is required at least in').' '.$defaultLanguage->name.'</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$productCommentCriterion->id_product_comment_criterion_type = (int)Tools::getValue('criterion_type');
|
||||
$productCommentCriterion->active = (int)Tools::getValue('criterion_active');
|
||||
|
||||
|
||||
if ($productCommentCriterion->save())
|
||||
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.(Tools::getValue('editCriterion') ? $this->l('Criterion updated') : $this->l('Criterion added')).'</div>';
|
||||
}
|
||||
@@ -249,13 +270,13 @@ class ProductComments extends Module
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _updateApplicationCriterion()
|
||||
{
|
||||
if (Tools::isSubmit('submitApplicationCriterion'))
|
||||
{
|
||||
include_once(dirname(__FILE__).'/ProductCommentCriterion.php');
|
||||
|
||||
|
||||
$id_criterion = (int)Tools::getValue('id_criterion');
|
||||
$productCommentCriterion = new ProductCommentCriterion((int)$id_criterion);
|
||||
if ($productCommentCriterion->id)
|
||||
@@ -277,11 +298,11 @@ class ProductComments extends Module
|
||||
$productCommentCriterion->addProduct((int)$product);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _displayForm()
|
||||
{
|
||||
$this->_displayFormModerate();
|
||||
@@ -371,7 +392,7 @@ class ProductComments extends Module
|
||||
}
|
||||
$this->_html .= '</fieldset><br />';
|
||||
}
|
||||
|
||||
|
||||
private function _displayFormReported()
|
||||
{
|
||||
$this->_html .= '<fieldset class="width2">
|
||||
@@ -419,12 +440,12 @@ class ProductComments extends Module
|
||||
$this->_html .= $this->l('No reported comment at this time.');
|
||||
$this->_html .= '</fieldset><br />';
|
||||
}
|
||||
|
||||
|
||||
private function _displayFormConfigurationCriterion()
|
||||
{
|
||||
$langs = Language::getLanguages(false);
|
||||
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
|
||||
$id_criterion = (int)Tools::getValue('editCriterion');
|
||||
$criterion = new ProductCommentCriterion((int)$id_criterion);
|
||||
$languageIds = 'criterion';
|
||||
@@ -479,7 +500,7 @@ class ProductComments extends Module
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
|
||||
foreach ($criterions AS $criterion)
|
||||
{
|
||||
$this->_html .= '<tr>
|
||||
@@ -500,7 +521,7 @@ class ProductComments extends Module
|
||||
|
||||
$criterions = ProductCommentCriterion::getCriterions(Context::getContext()->language->id, false, true);
|
||||
$id_criterion = (int)Tools::getValue('updateCriterion');
|
||||
|
||||
|
||||
if ($id_criterion)
|
||||
{
|
||||
$criterion = new ProductCommentCriterion((int)$id_criterion);
|
||||
@@ -519,7 +540,7 @@ class ProductComments extends Module
|
||||
foreach ($criterions AS $key => $foo)
|
||||
if ($foo['id_product_comment_criterion_type'] == 1)
|
||||
unset($criterions[$key]);
|
||||
|
||||
|
||||
if (sizeof($criterions))
|
||||
{
|
||||
$this->_html .= '
|
||||
@@ -553,8 +574,8 @@ class ProductComments extends Module
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
if ($criterion->id_product_comment_criterion_type == 3)
|
||||
|
||||
if ($criterion->id_product_comment_criterion_type == 3)
|
||||
foreach ($products AS $product)
|
||||
$this->_html .='<tr><td><input class="noborder" type="checkbox" value="'.(int)$product['id_product'].'" name="id_product[]" '.(in_array($product['id_product'], $criterion_products) ? 'checked="checked"' : '').' /></td>
|
||||
<td>'.(int)$product['id_product'].'</td><td>'.$product['name'].'</td></tr>';
|
||||
@@ -570,16 +591,16 @@ class ProductComments extends Module
|
||||
</div>
|
||||
</form>';
|
||||
}
|
||||
|
||||
|
||||
$this->_html .= '</fieldset>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function hookProductTab($params)
|
||||
{
|
||||
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||
require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
|
||||
|
||||
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
|
||||
'comments' => ProductComment::getByProduct((int)($_GET['id_product'])),
|
||||
@@ -588,108 +609,52 @@ class ProductComments extends Module
|
||||
|
||||
return ($this->display(__FILE__, '/tab.tpl'));
|
||||
}
|
||||
|
||||
public function hookProductOutOfStock($params)
|
||||
{
|
||||
|
||||
public function hookproductOutOfStock($params)
|
||||
{
|
||||
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||
require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
|
||||
|
||||
|
||||
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
|
||||
$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)Context::getContext()->cookie->id_customer, true, (int)$id_guest);
|
||||
|
||||
$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id);
|
||||
|
||||
$averageTotal = 0;
|
||||
foreach ($averages AS $average)
|
||||
$averageTotal += (float)($average);
|
||||
$averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0;
|
||||
|
||||
$average = ProductComment::getAverageGrade((int)Tools::getValue('id_product'));
|
||||
|
||||
$image = Product::getCover((int)($_GET['id_product']));
|
||||
|
||||
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'id_product_comment_form' => (int)Tools::getValue('id_product'),
|
||||
'secure_key' => $this->secure_key,
|
||||
'logged' => (int)Context::getContext()->customer->isLogged(true),
|
||||
'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
|
||||
'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
|
||||
'mediumSize' => Image::getSize('medium'),
|
||||
'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id),
|
||||
'action_url' => '',
|
||||
'averageTotal' => (int)$averageTotal,
|
||||
'averageTotal' => (int)$average['grade'],
|
||||
'too_early' => ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
|
||||
'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product'])))
|
||||
));
|
||||
|
||||
|
||||
return ($this->display(__FILE__, '/productcomments-extra.tpl'));
|
||||
}
|
||||
|
||||
private function _frontOfficePostProcess()
|
||||
{
|
||||
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||
require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
|
||||
|
||||
$allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
|
||||
if (Tools::isSubmit('submitMessage') AND Context::getContext()->customer->id AND (!Context::getContext()->customer->is_guest OR $allow_guests))
|
||||
{
|
||||
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
|
||||
$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), Context::getContext()->cookie->id_customer, true, (int)$id_guest);
|
||||
|
||||
if (!$customerComment OR ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) < time()))
|
||||
{
|
||||
$errors = array();
|
||||
$customer_name = false;
|
||||
if ($id_guest AND (!$customer_name = Tools::getValue('customer_name')))
|
||||
$errors[] = $this->l('Please fill your name');
|
||||
if (!sizeof($errors) AND Tools::getValue('content'))
|
||||
{
|
||||
$comment = new ProductComment();
|
||||
$comment->content = strip_tags(Tools::getValue('content'));
|
||||
$comment->id_product = (int)$_GET['id_product'];
|
||||
$comment->id_customer = (int)Context::getContext()->cookie->id_customer;
|
||||
$comment->id_guest = (int)$id_guest;
|
||||
$comment->customer_name = pSQL($customer_name);
|
||||
$comment->title = pSQL(Tools::getValue('title'));
|
||||
$comment->grade = 0;
|
||||
$comment->validate = 0;
|
||||
|
||||
if (!$comment->content)
|
||||
$errors[] = $this->l('Invalid comment text posted.');
|
||||
else
|
||||
{
|
||||
$comment->save();
|
||||
for ($i = 1, $grade = 0; isset($_POST[$i.'_grade']) === true; ++$i)
|
||||
{
|
||||
$cgrade = (int)Tools::getValue($i.'_grade');
|
||||
$grade += $cgrade;
|
||||
$productCommentCriterion = new ProductCommentCriterion((int)Tools::getValue('id_product_comment_criterion_'.$i));
|
||||
if ($productCommentCriterion->id)
|
||||
$productCommentCriterion->addGrade($comment->id, $cgrade);
|
||||
}
|
||||
if (($i - 1) > 0)
|
||||
$comment->grade = ($grade / ($i - 1));
|
||||
if (!$comment->save())
|
||||
$errors[] = $this->l('An error occurred while saving your comment.');
|
||||
else
|
||||
Context::getContext()->smarty->assign('confirmation', $this->l('Comment posted.').((int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')) ? ' '.$this->l('Awaiting moderator validation.') : ''));
|
||||
}
|
||||
}
|
||||
else
|
||||
$errors[] = $this->l('Comment text is required.');
|
||||
}
|
||||
else
|
||||
$errors[] = $this->l('You should wait').' '.Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME').' '.$this->l('seconds before posting a new comment');
|
||||
}
|
||||
}
|
||||
|
||||
public function hookProductTabContent($params)
|
||||
{
|
||||
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
|
||||
$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)Context::getContext()->cookie->id_customer, true, (int)$id_guest);
|
||||
|
||||
|
||||
$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id);
|
||||
$averageTotal = 0;
|
||||
foreach ($averages AS $average)
|
||||
$averageTotal += (float)($average);
|
||||
$averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0;
|
||||
|
||||
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'logged' => (int)Context::getContext()->customer->isLogged(true),
|
||||
'action_url' => '',
|
||||
@@ -703,7 +668,19 @@ class ProductComments extends Module
|
||||
'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')));
|
||||
|
||||
$this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')));
|
||||
|
||||
|
||||
$image = Product::getCover((int)($_GET['id_product']));
|
||||
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'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)($_GET['id_product'])))
|
||||
));
|
||||
|
||||
|
||||
|
||||
return ($this->display(__FILE__, '/productcomments.tpl'));
|
||||
}
|
||||
|
||||
@@ -712,14 +689,14 @@ class ProductComments extends Module
|
||||
$this->context->controller->addCSS($this->_path.'productcomments.css', 'all');
|
||||
$this->_frontOfficePostProcess();
|
||||
}
|
||||
|
||||
|
||||
public function hookExtraProductComparison($params)
|
||||
{
|
||||
$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, Context::getContext()->language->id);
|
||||
@@ -728,25 +705,25 @@ class ProductComments extends Module
|
||||
if (sizeof($grades) > 0)
|
||||
{
|
||||
foreach ($criterions AS $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']]);
|
||||
|
||||
|
||||
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 / sizeof($criterion);
|
||||
$list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof($list_grades) < 1)
|
||||
}
|
||||
|
||||
if (sizeof($list_grades) < 1)
|
||||
return false;
|
||||
|
||||
Context::getContext()->smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'],
|
||||
|
||||
Context::getContext()->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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,25 @@
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<script type="text/javascript" src="{$module_dir}js/jquery.rating.pack.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function(){literal}{{/literal} $('input[@type=radio].star').rating(); {literal}}{/literal});
|
||||
$(function(){literal}{{/literal}
|
||||
$('.auto-submit-star').rating({literal}{{/literal}
|
||||
callback: function(value, link){literal}{{/literal}
|
||||
{literal}}{/literal}
|
||||
{literal}}{/literal});
|
||||
{literal}}{/literal});
|
||||
|
||||
{literal}
|
||||
$('document').ready(function(){
|
||||
|
||||
$('#new_comment_tab_btn').fancybox({
|
||||
'hideOnContentClick': false,
|
||||
'onClosed': function(){
|
||||
},
|
||||
});
|
||||
|
||||
$('button[id^=comment_useful_yes_]').click(function(){
|
||||
|
||||
var idProductComment = $(this).attr('id').replace('comment_useful_yes_', '');
|
||||
@@ -79,6 +95,25 @@
|
||||
});
|
||||
}
|
||||
});
|
||||
$('#submitNewMessage').click(function(){
|
||||
var datas = [];
|
||||
$('#fancybox-content').find('input, textarea, select').each(function(index){
|
||||
var o = {}
|
||||
o.key = $(this).attr('name');
|
||||
o.value = $(this).val();
|
||||
datas.push(o);
|
||||
});
|
||||
console.log(datas);
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}productcomments-ajax.php",{literal}
|
||||
post: "POST",
|
||||
data: {action: 'sendComment', secure_key: '{/literal}{$secure_key}{literal}', review: JSON.stringify(datas)},
|
||||
dataType: "json",
|
||||
success: function(result){
|
||||
$.fancybox.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
{/literal}
|
||||
</script>
|
||||
@@ -126,7 +161,70 @@
|
||||
{/if}
|
||||
{/foreach}
|
||||
{else}
|
||||
{if ($too_early == false AND ($logged OR $allow_guests))}
|
||||
|
||||
<div style="display: none;">
|
||||
<div id="new_comment_form">
|
||||
<h2 class="title">{l s='Write your review' mod='productcomments'}</h2>
|
||||
<div class="product clearfix">
|
||||
<img src="{$link->getImageLink($product->link_rewrite, $productcomment_cover, 'home')}" height="{$homeSize.height}" width="{$homeSize.width}" alt="{$product->name|escape:html:'UTF-8'}" />
|
||||
<div class="product_desc">
|
||||
<p class="product_name"><strong>{$product->name}</strong></p>
|
||||
{$product->description_short}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="new_comment_form_content">
|
||||
<p class="intro_form">{l s='Write your review' mod='productcomments'}</p>
|
||||
{if $criterions|@count > 0}
|
||||
<div class="grade_content clearfix">
|
||||
{section loop=$criterions name=i start=0 step=1}
|
||||
<span>
|
||||
<input type="hidden" name="id_product_comment_criterion_{$smarty.section.i.iteration}" value="{$criterions[i].id_product_comment_criterion|intval}" />
|
||||
{$criterions[i].name|escape:'html':'UTF-8'}:
|
||||
</span>
|
||||
<div class="star_content">
|
||||
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" id="{$smarty.section.i.iteration}_grade" value="1" />
|
||||
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="2" />
|
||||
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="3" checked="checked" />
|
||||
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="4" />
|
||||
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="5" />
|
||||
</div>
|
||||
{/section}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="form_contenair">
|
||||
<p class="text">
|
||||
<label for="comment_title">{l s='Title' mod='productcomments'} <sup>*</sup>:</label>
|
||||
<input id="commentTitle" name="title" type="text" value=""/>
|
||||
</p>
|
||||
<p class="textarea">
|
||||
<label for="content">{l s='Comment' mod='productcomments'} <sup>*</sup>:</label>
|
||||
<textarea id="commentContent" name="content"></textarea>
|
||||
</p>
|
||||
{if $allow_guests == true && $logged == 0}
|
||||
<p class="text">
|
||||
<label>{l s='Your name:' mod='productcomments'} <sup>*</sup>:</label>
|
||||
<input id="commentCustomerName" name="customer_name" type="text" value=""/>
|
||||
</p>
|
||||
{/if}
|
||||
<p class="submit">
|
||||
<span class="txt_required">* {l s='Required fields' mod='productcomments'}</span>
|
||||
<input id="id_product_comment_send" name="id_product" type="hidden" value='{$id_product_comment_form}'></input>
|
||||
<button id="submitNewMessage" name="submitMessage" type="submit">{l s='Send' mod='productcomments'}</button>
|
||||
{l s='or' mod='productcomments'} <a href="#" onclick="$.fancybox.close();">{l s='Cancel' mod='productcomments'}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div><!-- /end new_comment_form_content -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="align_center">
|
||||
<a id="new_comment_tab_btn" href="#new_comment_form">{l s='Be the first to write your review' mod='productcomments'} !</a>
|
||||
</p>
|
||||
{else}
|
||||
<p class="align_center">{l s='No customer comments for the moment.' mod='productcomments'}</p>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user