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 += (double) $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'); }
public function initCategoriesAssociation($id_root = null, $id_criterion = 0) { if (is_null($id_root)) { $id_root = Configuration::get('PS_ROOT_CATEGORY'); } $id_shop = (int) Tools::getValue('id_shop'); $shop = new Shop($id_shop); if ($id_criterion == 0) { $selected_cat = array(); } else { $pdc_object = new ProductCommentCriterion($id_criterion); $selected_cat = $pdc_object->getCategories(); } if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) { $root_category = new Category($shop->id_category); } else { $root_category = new Category($id_root); } $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name[$this->context->language->id]); $helper = new Helper(); return $helper->renderCategoryTree($root_category, $selected_cat, 'categoryBox', false, true); }
protected function ajaxProcessAddComment() { $module_instance = new ProductComments(); $result = true; $id_guest = 0; $id_customer = $this->context->customer->id; if (!$id_customer) { $id_guest = $this->context->cookie->id_guest; } $errors = array(); // Validation if (!Validate::isInt(Tools::getValue('id_product'))) { $errors[] = $module_instance->l('ID product is incorrect', 'default'); } if (!Tools::getValue('title') || !Validate::isGenericName(Tools::getValue('title'))) { $errors[] = $module_instance->l('Title is incorrect', 'default'); } if (!Tools::getValue('content') || !Validate::isMessage(Tools::getValue('content'))) { $errors[] = $module_instance->l('Comment is incorrect', 'default'); } if (!$id_customer && (!Tools::isSubmit('customer_name') || !Tools::getValue('customer_name') || !Validate::isGenericName(Tools::getValue('customer_name')))) { $errors[] = $module_instance->l('Customer name is incorrect', 'default'); } if (!$this->context->customer->id && !Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS')) { $errors[] = $module_instance->l('You must be logged in order to send a comment', 'default'); } if (!count(Tools::getValue('criterion'))) { $errors[] = $module_instance->l('You must give a rating', 'default'); } $product = new Product(Tools::getValue('id_product')); if (!$product->id) { $errors[] = $module_instance->l('Product not found', 'default'); } if (!count($errors)) { $customer_comment = ProductComment::getByCustomer(Tools::getValue('id_product'), $id_customer, true, $id_guest); if (!$customer_comment || $customer_comment && strtotime($customer_comment['date_add']) + (int) Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME') < time()) { $comment = new ProductComment(); $comment->content = strip_tags(Tools::getValue('content')); $comment->id_product = (int) Tools::getValue('id_product'); $comment->id_customer = (int) $id_customer; $comment->id_guest = $id_guest; $comment->customer_name = Tools::getValue('customer_name'); if (!$comment->customer_name) { $comment->customer_name = pSQL($this->context->customer->firstname . ' ' . $this->context->customer->lastname); } $comment->title = Tools::getValue('title'); $comment->grade = 0; $comment->validate = 0; $comment->save(); $grade_sum = 0; foreach (Tools::getValue('criterion') as $id_product_comment_criterion => $grade) { $grade_sum += $grade; $product_comment_criterion = new ProductCommentCriterion($id_product_comment_criterion); if ($product_comment_criterion->id) { $product_comment_criterion->addGrade($comment->id, $grade); } } if (count(Tools::getValue('criterion')) >= 1) { $comment->grade = $grade_sum / count(Tools::getValue('criterion')); // Update Grade average of comment $comment->save(); } $result = true; } else { $result = false; $errors[] = $module_instance->l('You should wait') . ' ' . Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME') . ' ' . $module_instance->l('seconds before posting a new comment'); } } else { $result = false; } die(Tools::jsonEncode(array('result' => $result, 'errors' => $errors))); }
* needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <*****@*****.**> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 1.4 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once dirname(__FILE__) . '/../../classes/Validate.php'; require_once dirname(__FILE__) . '/../../classes/Db.php'; require_once dirname(__FILE__) . '/../../classes/Tools.php'; require_once dirname(__FILE__) . '/ProductCommentCriterion.php'; if (empty($_GET['id_lang']) === false && isset($_GET['id_product']) === true) { $criterions = ProductCommentCriterion::get($_GET['id_lang']); if ((int) $_GET['id_product']) { $selects = ProductCommentCriterion::getByProduct($_GET['id_product'], $_GET['id_lang']); } echo '<select name="id_product_comment_criterion[]" id="id_product_comment_criterion" multiple="true" style="height:100px;width:360px;">'; foreach ($criterions as $criterion) { echo '<option value="' . (int) $criterion['id_product_comment_criterion'] . '"'; if (isset($selects) === true && sizeof($selects)) { foreach ($selects as $select) { if ($select['id_product_comment_criterion'] == $criterion['id_product_comment_criterion']) { echo ' selected="selected"'; } } } echo '>' . htmlspecialchars($criterion['name'], ENT_COMPAT, 'UTF-8') . '</option>'; } echo '</select>'; }
$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); if (!$comment->id_customer) { $comment->customer_name = pSQL($name); } $comment->title = pSQL($title); $comment->grade = 0; $comment->validate = 0; $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.'); }
public function hookProductTabContent($params) { global $smarty, $cookie, $nbProducts; $commentNumber = intval(ProductComment::getCommentNumber(intval($_GET['id_product']))); $averages = ProductComment::getAveragesByProduct(intval($_GET['id_product']), intval($cookie->id_lang)); $averageTotal = 0; foreach ($averages as $average) { $averageTotal += floatval($average); } $averageTotal = count($averages) ? $averageTotal / count($averages) : 0; $smarty->assign(array('logged' => intval($cookie->id_customer), 'action_url' => $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], 'comments' => ProductComment::getByProduct(intval($_GET['id_product'])), 'criterions' => ProductCommentCriterion::getByProduct(intval($_GET['id_product']), intval($cookie->id_lang)), 'averages' => $averages, 'product_comment_path' => $this->_path, 'averageTotal' => $averageTotal)); $nbProducts = $commentNumber; require_once dirname(__FILE__) . '/../../pagination.php'; return $this->display(__FILE__, '/productcomments.tpl'); }
public function hookProductTabContent($params) { global $smarty, $cookie, $nbProducts; $commentNumber = intval(ProductComment::getCommentNumber(intval(Tools::getValue('id_product')))); $averages = ProductComment::getAveragesByProduct(intval(Tools::getValue('id_product')), intval($cookie->id_lang)); $customerComment = ProductComment::getByCustomer(intval(Tools::getValue('id_product')), intval($cookie->id_customer), true); $averageTotal = 0; foreach ($averages as $average) { $averageTotal += floatval($average); } $averageTotal = count($averages) ? $averageTotal / count($averages) : 0; $smarty->assign(array('logged' => intval($cookie->id_customer), 'action_url' => Tools::safeOutput($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING'], 'comments' => ProductComment::getByProduct(intval(Tools::getValue('id_product'))), 'criterions' => ProductCommentCriterion::getByProduct(intval(Tools::getValue('id_product')), intval($cookie->id_lang)), 'averages' => $averages, 'product_comment_path' => $this->_path, 'averageTotal' => $averageTotal, 'too_early' => $customerComment and strtotime($customerComment['date_add']) + self::DELAY * 3600 > time(), 'delay' => self::DELAY)); $nbProducts = $commentNumber; require_once dirname(__FILE__) . '/../../pagination.php'; return $this->display(__FILE__, '/productcomments.tpl'); }
public function hookExtraProductComparison($params) { global $smarty, $cookie; $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((int) $id_product, (int) $cookie->id_lang); $criterions = ProductCommentCriterion::getByProduct((int) $id_product, (int) $cookie->id_lang); $grade_total = 0; 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 += (double) $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) { return false; } $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'); }