name = 'ant_canonical'; $this->tab = 'front_office_features'; $this->author = 'Antadis'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Canonical'); $this->description = $this->l('Generate canonical url to remove duplicate content'); } public function install() { // Register hooks if(!parent::install() || !$this->registerHook('header')) { return false; } return true; } public function hookHeader($params) { global $cookie, $smarty, $page_name, $site_version; switch ($site_version) { case 'es': $tld = 'es'; break; case 'com': case 'fr': default: $tld = 'com'; break; } $domain = Configuration::get('PS_SSL_ENABLED') ? Configuration::get('PS_SHOP_DOMAIN_SSL') : Configuration::get('PS_SHOP_DOMAIN'); $host = str_replace('bebeboutik.com', 'bebeboutik.'.$tld, $domain); //$host = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$host; $host = 'https://'.$host; // Page category if ($page_name == 'category') { $id_category = Tools::getValue('id_category'); $category = new Category($id_category, $cookie->id_lang); if (Validate::isLoadedObject($category)) { $smarty->assign(array('url' => $host.'/'.$this->getLinkRewriteCategory($id_category))); } } // Page product if ($page_name == 'product') { $id_product = Tools::getValue('id_product'); $smarty->assign(array('url' => $host.'/'.$this->getLinkRewriteProduct($id_product))); } return self::display(__FILE__, 'views/front/header.tpl'); } /** * Real product rewrite link * @param int $id * @return string */ private function getLinkRewriteProduct($id) { global $cookie; $product = new Product($id); $link = $this->getLinkRewriteCategory($product->id_category_default, true) .'/'.$id.'-'.$product->link_rewrite[$cookie->id_lang]; if (!empty($product->ean13)) { $link .= '-' . $product->ean13; } $link .= '.html'; return $link; } /** * Real category rewrite link * @param int $id * @param boolean $product * @return string */ private function getLinkRewriteCategory($id, $product = false) { global $cookie; if ($product === false) { return $id.'-'.Category::getLinkRewrite($id, $cookie->id_lang); } else { return Category::getLinkRewrite($id, $cookie->id_lang); } } }