name = 'cyb_simplecomment'; $this->tab = 'cyb_simplecomment'; $this->version = '1.1'; $this->author = 'Cyberscope Gabriel'; $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->display = 'view'; parent::__construct(); $this->displayName = $this->l('Cyberscope Simple Comment'); $this->description = $this->l(''); $this->confirmUninstall = $this->l('Êtes-vous sûr de vouloir désinstaller ce module ?'); $this->templateFile = 'module:cyb_simplecomment/cyb_simplecomment.tpl'; if (isset($this->context)){ $this->current_shop_id = $this->context->shop->getContextShopID(); }else{ // _PS_VERSION_ < 1.4 $this->current_shop_id = ''; } if (Configuration::get('AV_MULTILINGUE', null, null, $this->current_shop_id) == 'checked') { $this->id_lang = $this->context->language->id; $this->iso_lang = pSQL(Language::getIsoById($this->id_lang)); $this->group_name = $this->getIdConfigurationGroup($this->iso_lang); } $this->all_multishops_reviews = false; $this->all_languages_reviews = false; } public function install(){ if(!parent::install() || !Configuration::updateValue('cy_sc', '') || !$this->registerHook('displayProductRatingAVG') || !$this->registerHook('displayProductRatingSUM') || !$this->registerHook('displayMenuItems') ){ return false; } else{ return true; } } public function uninstall(){ if(!parent::uninstall() || !Configuration::deleteByName('cy_sc')){ return false; } else{ return true; } } public function hookDisplayProductRatingAVG($params){ $id_product = (int)$params['product']['id_product']; $avisverifies_display_stars = Configuration::get('AV_DISPLAYSTARPLIST', null, null, $this->current_shop_id); if (!isset($id_product) || empty($id_product) || !isset($avisverifies_display_stars) || empty($avisverifies_display_stars)) { return ; } $o_av = new NetReviewsModel(); $stats_product = (!isset($this->stats_product) || empty($this->stats_product)) ? $o_av->getStatsProduct($id_product, $this->group_name, $this->current_shop_id) : $this->stats_product; if ($this->all_multishops_reviews || $this->all_languages_reviews){ // override rate & nb_reviews $language_group = ($this->all_languages_reviews)?null:$this->group_name; $shop_id_group = ($this->all_multishops_reviews)?null:$this->current_shop_id; $reviews = $o_av->getProductReviews($id_product, $language_group, $shop_id_group, 0, 1, 'horodate_DESC', 0, false); $num_reviews = count($reviews); if ($num_reviews < 1 || !$avisverifies_display_stars) { return ; } $somme_rate = 0; foreach ($reviews as $review) { $somme_rate += $review['rate']; } $stats_product['rate'] = $somme_rate / $num_reviews; $stats_product['nb_reviews'] = $num_reviews; } if (!isset($stats_product['nb_reviews']) || $stats_product['nb_reviews'] == 0) { return ; } return !is_null($stats_product) && !is_null($stats_product['rate']) ? ceil((float)$stats_product['rate']) : ""; } public function hookDisplayProductRatingSUM($params){ $id_product = (int)$params['product']['id_product']; $avisverifies_display_stars = Configuration::get('AV_DISPLAYSTARPLIST', null, null, $this->current_shop_id); if (!isset($id_product) || empty($id_product) || !isset($avisverifies_display_stars) || empty($avisverifies_display_stars)) { return ; } $o_av = new NetReviewsModel(); $stats_product = (!isset($this->stats_product) || empty($this->stats_product)) ? $o_av->getStatsProduct($id_product, $this->group_name, $this->current_shop_id) : $this->stats_product; if ($this->all_multishops_reviews || $this->all_languages_reviews){ // override rate & nb_reviews $language_group = ($this->all_languages_reviews)?null:$this->group_name; $shop_id_group = ($this->all_multishops_reviews)?null:$this->current_shop_id; $reviews = $o_av->getProductReviews($id_product, $language_group, $shop_id_group, 0, 1, 'horodate_DESC', 0, false); $num_reviews = count($reviews); if ($num_reviews < 1 || !$avisverifies_display_stars) { return ; } $somme_rate = 0; foreach ($reviews as $review) { $somme_rate += $review['rate']; } $stats_product['rate'] = $somme_rate / $num_reviews; $stats_product['nb_reviews'] = $num_reviews; } if (!isset($stats_product['nb_reviews']) || $stats_product['nb_reviews'] == 0) { return ; } return !is_null($stats_product) && !is_null($stats_product['nb_reviews']) ? $stats_product['nb_reviews'] : ""; } public function hookDisplayMenuItems($params) { return $this->display(__FILE__, '/views/templates/hook/rating-sorts.tpl'); } }