Пример #1
0
 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 += (double) $average;
     }
     $averageTotal = count($averages) ? $averageTotal / count($averages) : 0;
     $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)));
     $this->context->controller->pagination((int) ProductComment::getCommentNumber((int) Tools::getValue('id_product')));
     return $this->display(__FILE__, '/productcomments.tpl');
 }
Пример #2
0
 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)));
 }
Пример #3
0
                     if (strstr($entry->key, 'grade')) {
                         $id = array(explode('_', $entry->key));
                         $grades[] = array('id' => $id['0']['0'], 'grade' => $entry->value);
                     }
                 }
             }
         }
     }
 }
 if ($title == '' || $content == '' || !$id_product || count($grades) == 0) {
     die('0');
 }
 $allow_guests = (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
 if (Context::getContext()->customer->id || !Context::getContext()->customer->id && $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 || $customerComment && strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME') < time()) {
         $errors = array();
         $customer_name = false;
         if ($id_guest && !($customer_name = Context::getContext()->customer->firstname . ' ' . Context::getContext()->customer->lastname)) {
             $errors[] = $productCom->l('Please fill your name');
         }
         if (!count($errors) && $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);
             if (!$comment->id_customer) {
                 $comment->customer_name = pSQL($name);
Пример #4
0
 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_product = (int) Tools::getValue('id_product');
     $n = Configuration::get('PRODUCT_COMMENTS_PER_PAGE');
     $p = 1;
     $comments = ProductComment::getByProduct($id_product, $p, $n, $this->context->cookie->id_customer);
     $nbComments = (int) ProductComment::getCommentNumber((int) Tools::getValue('id_product'));
     $count_comments_page = count($comments);
     $pages = array();
     if ($nbComments > count($comments)) {
         $count_pages = ceil($nbComments / $n);
         for ($i = 1; $i <= $count_pages; $i++) {
             $pages[$i]['page'] = $i;
             $pages[$i]['active'] = $p == $i ? true : false;
         }
     }
     $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 += (double) $average;
     }
     $averageTotal = count($averages) ? $averageTotal / count($averages) : 0;
     $product = $this->context->controller->getProduct();
     $image = Product::getCover((int) Tools::getValue('id_product'));
     $cover_image = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], 'medium_default');
     $this->context->smarty->assign(array('comment_pages' => $pages, 'comment_pagination' => count($pages) ? true : false, 'comment_per_page' => $n, 'comment_page' => $p, 'comment_count_pages' => isset($count_pages) ? $count_pages : 0, 'logged' => $this->context->customer->isLogged(true), 'action_url' => '', 'product' => $product, 'comments' => $comments, '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'], 'productcomment_cover_image' => $cover_image, 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'nbComments' => $nbComments, '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')));
     $this->context->controller->pagination((int) ProductComment::getCommentNumber((int) Tools::getValue('id_product')));
     return $this->display(__FILE__, '/productcomments.tpl');
 }
Пример #5
0
 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');
 }
Пример #6
0
 public function hookProductTabContent($params)
 {
     global $smarty, $cookie, $link, $isBetaUser;
     $id_guest = !($id_customer = (int) $cookie->id_customer) ? (int) $cookie->id_guest : false;
     $customerComment = ProductComment::getByCustomer((int) Tools::getValue('id_product'), (int) $cookie->id_customer, true, (int) $id_guest);
     $averages = ProductComment::getAveragesByProduct((int) Tools::getValue('id_product'), (int) $cookie->id_lang);
     $averageTotal = 0;
     foreach ($averages as $average) {
         $averageTotal += (double) $average;
     }
     $averageTotal = count($averages) ? $averageTotal / count($averages) : 0;
     //'too_early' => ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
     $too_early = $customerComment;
     $smarty->assign(array('logged' => (int) $cookie->id_customer, 'action_url' => '', 'comments' => ProductComment::getByProduct((int) Tools::getValue('id_product')), 'criterions' => ProductCommentCriterion::getByProduct((int) Tools::getValue('id_product'), (int) $cookie->id_lang), 'averages' => $averages, 'product_comment_path' => $this->_path, 'averageTotal' => $averageTotal, 'allow_guests' => (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), 'too_early' => $too_early, 'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')));
     $controller = new FrontController();
     $controller->pagination((int) ProductComment::getCommentNumber((int) Tools::getValue('id_product')));
     if ($isBetaUser) {
         return $this->display(__FILE__, 'beta/productcomments.tpl');
     } else {
         return $this->display(__FILE__, '/productcomments.tpl');
     }
 }