public function init() { if ($product_rewrite = Tools::getValue('product_rewrite')) { $url_id_pattern = '/.*?([0-9]+)\\-([a-zA-Z0-9-]*)(\\.html)?/'; $lang_id = (int) Context::getContext()->language->id; $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . pSQL(str_replace('.html', '', $product_rewrite)) . '\' AND `id_lang` = ' . $lang_id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } elseif (preg_match($url_id_pattern, $this->request_uri, $url_parts)) { $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `id_product` = \'' . pSQL($url_parts[1]) . '\' AND `id_lang` = ' . $lang_id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } } } parent::init(); }
public function init() { global $smarty; parent::init(); if (Module::isInstalled('agilepricecomparison')) { $HOOK_AGILE_PRICE_COMPARISON = ''; if (!intval(Configuration::get('AGILE_PC_USE_DEFAULT_HOOK'))) { $HOOK_AGILE_PRICE_COMPARISON = Module::hookExec('agilepricecomparison', array()); } $smarty->assign(array('HOOK_AGILE_PRICE_COMPARISON' => $HOOK_AGILE_PRICE_COMPARISON)); } }
public function init() { if (Tools::getValue('product_rewrite')) { $rewrite_url = Tools::getValue('product_rewrite'); $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $rewrite_url . '\''); if ($id_product > 0) { $_GET['id_product'] = $id_product; //$_GET['noredirect'] = 1; } else { Tools::display404Error(); die; } } parent::init(); }
public function init() { if (Tools::getValue('product_rewrite')) { //$url_id_pattern = '/[a-zA-Z0-9-]*\/([0-9]+)\-([a-zA-Z0-9-]*)\.html/'; $url_id_pattern = '/.*?([0-9]+)\\-([a-zA-Z0-9-]*)\\.html/'; $rewrite_url = Tools::getValue('product_rewrite'); $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $rewrite_url . '\' AND `id_lang` = ' . Context::getContext()->language->id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } else { if (preg_match($url_id_pattern, $_SERVER['REQUEST_URI'], $url_split)) { $url_id_product = $url_split[1]; $sql = 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `id_product` = \'' . $url_id_product . '\' AND `id_lang` = ' . Context::getContext()->language->id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID(); } $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_product > 0) { $_GET['id_product'] = $id_product; } else { //TODO: Do we need to send 404? header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } } else { //TODO: Do we need to send 404? header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } } } parent::init(); }
public function init() { parent::init(); $pagerCat = FALSE; if (isset($_SERVER['HTTP_REFERER'])) { $parseQuery = explode('id_category=', $_SERVER['HTTP_REFERER']); if (count($parseQuery) == 2) { $parseQuery[1] = (int) $parseQuery[1]; if ($parseQuery[1]) { $pagerCat = $parseQuery[1]; } } } if ((int) Tools::getValue('pagerCat')) { $pagerCat = (int) Tools::getValue('pagerCat'); } if ($pagerCat) { if (Product::idIsOnCategoryId((int) $this->product->id, array(array('id_category' => $pagerCat)))) { $this->category = new Category($pagerCat, (int) $this->context->cookie->id_lang); } } }
/** * Method init() : Initialize product controller with product_rewrite params * * @module now_seo_links * * @see ProductControllerCore::init() */ public function init() { // Get rewrite $sRewrite = Tools::getValue('product_rewrite', false); if ($sRewrite) { $iIdProduct = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $sRewrite . '\' AND `id_lang` = ' . Context::getContext()->language->id); if ($iIdProduct) { $_GET['id_product'] = $iIdProduct; } } parent::init(); // On vérifie si l'URL actuelle est correcte ou pas $goodUrl = Context::getContext()->link->getProductLink($this->product); if (!preg_match('#' . $_SERVER['REDIRECT_URL'] . '#', $goodUrl)) { header('Status: 301 Moved Permanently', false, 301); header('Location: ' . $goodUrl); exit; } }
/** * Initialize product controller * @see FrontController::init() */ public function init() { if (Tools::getValue('product_rewrite')) { $rewrite_url = Tools::getValue('product_rewrite'); $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $rewrite_url . '\''); if ($id_product > 0) { $_GET['id_product'] = $id_product; $_GET['noredirect'] = 1; } else { $redirect_url = str_replace('.html', '', $_SERVER['REQUEST_URI']); $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302'; header('HTTP/1.0 ' . $redirect_type . ' Moved'); header('Cache-Control: no-cache'); Tools::redirectLink('http://' . $_SERVER['HTTP_HOST'] . $redirect_url); Tools::display404Error(); die; } } parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product not found'); } else { $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if ($this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '404': default: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('This product is no longer available.'); break; } } } elseif (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { // Load category $id_category = false; if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category $id_object = false; if (isset($regs[1]) && is_numeric($regs[1])) { $id_object = (int) $regs[1]; } elseif (isset($regs[5]) && is_numeric($regs[5])) { $id_object = (int) $regs[5]; } if ($id_object) { $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER'])); if (in_array($this->context->link->getCategoryLink($id_object), $referers)) { $id_category = (int) $id_object; } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) { $id_category = (int) $this->context->cookie->last_visited_category; } } } if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) { $id_category = (int) $this->product->id_category_default; } if (Category::inDecor($id_category) && !$this->ajax && strpos($_SERVER['SERVER_NAME'], 'decor') <= -1) { $final_url = $this->context->link->getProductLink($this->product); $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302'; header('HTTP/1.0 ' . $redirect_type . ' Moved'); header('Cache-Control: no-cache'); Tools::redirectLink($final_url); } $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang); if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) { $this->context->cookie->last_visited_category = (int) $this->category->id_category; } } } }
/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product not found'); } else { $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if ($this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '404': default: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('This product is no longer available.'); break; } } } elseif (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { if ($this->context->language->id != 1) { $this->product->name = $this->rus2translit($this->product->name); } // Load category $id_category = false; if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category $id_object = false; if (isset($regs[1]) && is_numeric($regs[1])) { $id_object = (int) $regs[2]; } elseif (isset($regs[5]) && is_numeric($regs[5])) { $id_object = (int) $regs[6]; } if ($id_object) { $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER'])); if (in_array($this->context->link->getCategoryLink($id_object), $referers)) { $id_category = (int) $id_object; } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) { $id_category = (int) $this->context->cookie->last_visited_category; } } } if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) { $id_category = (int) $this->product->id_category_default; } $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang); if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) { $this->context->cookie->last_visited_category = (int) $this->category->id_category; } } } }