[-] 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
|
||||
*
|
||||
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user