public function run() { // Get number of comments $id_product = (int) Tools::getValue('id_product'); $nb_comments = MyModComment::getProductNbComments((int) $id_product); // Init $page = 1; $nb_per_page = 10; $nb_pages = ceil($nb_comments / $nb_per_page); if (Tools::getIsset('page')) { $page = (int) Tools::getValue('page'); } $limit_start = ($page - 1) * $nb_per_page; $limit_end = $nb_per_page; // Build actions url $ajax_action_url = $this->context->link->getAdminLink('AdminModules', true); $ajax_action_url = str_replace('index.php', 'ajax-tab.php', $ajax_action_url); $action_url = $this->context->link->getAdminLink('AdminMyModComments', true); // Get comments $comments = MyModComment::getProductComments((int) $id_product, (int) $limit_start, (int) $limit_end); // Assign comments and product object $this->context->smarty->assign('page', $page); $this->context->smarty->assign('nb_pages', $nb_pages); $this->context->smarty->assign('comments', $comments); $this->context->smarty->assign('action_url', $action_url); $this->context->smarty->assign('ajax_action_url', $ajax_action_url); $this->context->smarty->assign('pc_base_dir', __PS_BASE_URI__ . 'modules/' . $this->module->name . '/'); return $this->module->display($this->file, 'displayAdminProductsExtra.tpl'); }
public static function find($id_lang, $expr, $page_number = 1, $page_size = 1, $order_by = 'position', $order_way = 'desc', $ajax = false, $use_cookie = true, Context $context = null) { // Call parent method $find = parent::find($id_lang, $expr, $page_number, $page_size, $order_by, $order_way, $ajax, $use_cookie, $context); if (isset($find['result']) && !empty($find['result']) && Module::isInstalled('mymodcomments')) { // List id product $products = $find['result']; $id_product_list = array(); foreach ($products as $p) { $id_product_list[] = (int) $p['id_product']; } // Get grade average and nb comments for products in list require_once dirname(__FILE__) . '/../../modules/mymodcomments/classes/MyModComment.php'; $grades_comments = MyModComment::getInfosOnProductsList($id_product_list); // Associate grade and nb comments with product foreach ($products as $kp => $p) { foreach ($grades_comments as $gc) { if ($gc['id_product'] == $p['id_product']) { $products[$kp]['mymodcomments']['grade_avg'] = round($gc['grade_avg']); $products[$kp]['mymodcomments']['nb_comments'] = $gc['nb_comments']; } } } $find['result'] = $products; } // Return products return $find; }
public function assignProductTabContent() { $enable_grades = Configuration::get('MYMOD_GRADES'); $enable_comments = Configuration::get('MYMOD_COMMENTS'); $this->context->controller->addCSS($this->_path . 'views/css/star-rating.css', 'all'); $this->context->controller->addJS($this->_path . 'views/js/star-rating.js'); $this->context->controller->addCSS($this->_path . 'views/css/mymodcomments.css', 'all'); $this->context->controller->addJS($this->_path . 'views/js/mymodcomments.js'); if (!$this->module->isCached('displayProductTabContent.tpl', $this->cache_id)) { $id_product = Tools::getValue('id_product'); $comments = MyModComment::getProductComments($id_product, 0, 3); $product = new Product((int) $id_product, false, $this->context->cookie->id_lang); $this->context->smarty->assign('enable_grades', $enable_grades); $this->context->smarty->assign('enable_comments', $enable_comments); $this->context->smarty->assign('comments', $comments); $this->context->smarty->assign('product', $product); } }
protected function initList() { // Get number of comments $nb_comments = MyModComment::getProductNbComments($this->product->id); // Init $nb_per_page = 10; $nb_pages = ceil($nb_comments / $nb_per_page); $page = 1; if (Tools::getValue('page') != '') { $page = (int) $_GET['page']; } $limit_start = ($page - 1) * $nb_per_page; $limit_end = $nb_per_page; // Get comments $comments = MyModComment::getProductComments($this->product->id, $limit_start, $limit_end); // Assign comments and product object $this->context->smarty->assign('comments', $comments); $this->context->smarty->assign('product', $this->product); $this->context->smarty->assign('page', $page); $this->context->smarty->assign('nb_pages', $nb_pages); $this->setTemplate('list.tpl'); }