public function init() { if (Tools::getValue('supplier_rewrite')) { $name_supplier = str_replace('-', '%', Tools::getValue('supplier_rewrite')); // // TODO:: need to core update Prestashop code and // DB for link_rewrite for suppliers // Should we use the Mysql FullText Index Search ?? // $sql = 'SELECT sp.`id_supplier` FROM `' . _DB_PREFIX_ . 'supplier` sp LEFT JOIN `' . _DB_PREFIX_ . 'supplier_shop` s ON (sp.`id_supplier` = s.`id_supplier`) WHERE sp.`name` LIKE \'' . $name_supplier . '\''; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND s.`id_shop` = ' . (int) Shop::getContextShopID(); } $id_supplier = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_supplier > 0) { $_GET['id_supplier'] = $id_supplier; } 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() { if ($supplier_rewrite = Tools::getValue('supplier_rewrite')) { $sql = 'SELECT sp.`id_supplier` FROM `' . _DB_PREFIX_ . 'supplier` sp LEFT JOIN `' . _DB_PREFIX_ . 'supplier_shop` s ON (sp.`id_supplier` = s.`id_supplier`) WHERE sp.`name` LIKE \'' . pSQL(str_replace('-', '%', $supplier_rewrite)) . '\''; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND s.`id_shop` = ' . (int) Shop::getContextShopID(); } $id_supplier = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if ($id_supplier > 0) { $_GET['id_supplier'] = $id_supplier; } } parent::init(); }
public function init() { if (Tools::getValue('supplier_rewrite')) { $name_supplier = str_replace('-', '%', Tools::getValue('supplier_rewrite')); $id_supplier = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_supplier` FROM `' . _DB_PREFIX_ . 'supplier` WHERE `name` LIKE \'' . $name_supplier . '\''); if ($id_supplier > 0) { $_GET['id_supplier'] = $id_supplier; $_GET['noredirect'] = 1; } else { Tools::display404Error(); die; } } parent::init(); }
/** * Method init() : Initialize supplier controller with supplier_rewrite params * * @module now_seo_links * * @see SupplierControllerCore::init() */ public function init() { // Get rewrite $sRewrite = str_replace('-', '%', Tools::getValue('supplier_rewrite', false)); if ($sRewrite) { $iIdSupplier = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_supplier` FROM `' . _DB_PREFIX_ . 'supplier` WHERE `name` LIKE \'' . $sRewrite . '\' '); if ($iIdSupplier) { $_GET['id_supplier'] = $iIdSupplier; } } parent::init(); // On vérifie si l'URL actuelle est correcte ou pas $goodUrl = Context::getContext()->link->getSupplierLink($this->supplier); if (!preg_match('#' . $_SERVER['REDIRECT_URL'] . '#', $goodUrl)) { header('Status: 301 Moved Permanently', false, 301); header('Location: ' . $goodUrl); exit; } }