diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index 6c319a38c..02834b8e0 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -519,7 +519,7 @@ class DispatcherCore * @param bool $use_routes If false, don't use to create this url * @param string $anchor Optional anchor to add at the end of this url */ - public function createUrl($route_id, array $params = array(), $use_routes = true, $anchor = '') + public function createUrl($route_id, array $params = array(), $force_routes = false, $anchor = '') { if (!isset($this->routes[$route_id])) { @@ -541,7 +541,7 @@ class DispatcherCore } // Build an url which match a route - if ($this->use_routes && $use_routes) + if ($this->use_routes || $force_routes) { $url = $route['rule']; $add_param = array(); diff --git a/classes/Language.php b/classes/Language.php index 0e6c8685b..abb20689e 100644 --- a/classes/Language.php +++ b/classes/Language.php @@ -736,7 +736,7 @@ class LanguageCore extends ObjectModel { if (!self::$countActiveLanguages) self::$countActiveLanguages = Db::getInstance()->getValue(' - SELECT COUNT(*) FROM `'._DB_PREFIX_.'lang` l + SELECT COUNT(DISTINCT l.id_lang) FROM `'._DB_PREFIX_.'lang` l '.Shop::addSqlAssociation('lang', 'l').' WHERE l.`active` = 1 '); diff --git a/classes/Link.php b/classes/Link.php index 9cf98db54..e30d94871 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -76,7 +76,7 @@ class LinkCore * @param int $ipa ID product attribute * @return string */ - public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0) + public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false) { $dispatcher = Dispatcher::getInstance(); $url = _PS_BASE_URL_.__PS_BASE_URI__; @@ -129,7 +129,7 @@ class LinkCore } $anchor = $ipa ? $product->getAnchor($ipa) : ''; - return $url.$dispatcher->createUrl('product_rule', $params, $this->allow, $anchor); + return $url.$dispatcher->createUrl('product_rule', $params, $force_routes, $anchor); } /** @@ -532,6 +532,7 @@ class LinkCore { if (!$context) $context = Context::getContext(); + var_dump(Language::isMultiLanguageActivated()); if (!$this->allow || !Language::isMultiLanguageActivated()) return ''; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 542a73ed6..91385f936 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1491,10 +1491,16 @@ class AdminProductsControllerCore extends AdminController // Save and preview if (Tools::isSubmit('submitAddProductAndPreview')) { - $preview_url = ($this->context->link->getProductLink( - $this->getFieldValue($this->object, 'id'), - $this->getFieldValue($this->object, 'link_rewrite', $this->context->language->id), - Category::getLinkRewrite($this->getFieldValue($this->object, 'id_category_default'), $this->context->language->id))); + $preview_url = $this->context->link->getProductLink( + $this->getFieldValue($this->object, 'id'), + $this->getFieldValue($this->object, 'link_rewrite', $this->context->language->id), + Category::getLinkRewrite($this->getFieldValue($this->object, 'id_category_default'), $this->context->language->id), + null, + null, + Context::getContext()->shop->id, + 0, + true + ); if (!$this->object->active) { @@ -1606,7 +1612,17 @@ class AdminProductsControllerCore extends AdminController // Save and preview if (Tools::isSubmit('submitAddProductAndPreview')) { - $preview_url = $this->context->link->getProductLink($this->getFieldValue($object, 'id'), $this->getFieldValue($object, 'link_rewrite', $this->context->language->id), Category::getLinkRewrite($this->getFieldValue($object, 'id_category_default'), $this->context->language->id), null, null, Context::getContext()->shop->id); + $preview_url = $this->context->link->getProductLink( + $this->getFieldValue($object, 'id'), + $this->getFieldValue($object, 'link_rewrite', $this->context->language->id), + Category::getLinkRewrite($this->getFieldValue($object, 'id_category_default'), $this->context->language->id), + null, + null, + Context::getContext()->shop->id, + 0, + true + ); + if (!$object->active) { $admin_dir = dirname($_SERVER['PHP_SELF']); @@ -2288,10 +2304,27 @@ class AdminProductsControllerCore extends AdminController $preview_url = $this->context->link->getProductLink( $product, $this->getFieldValue($product, 'link_rewrite', $this->context->language->id), - Category::getLinkRewrite($product->id_category_default, $this->context->language->id), null, null, Context::getContext()->shop->id); + Category::getLinkRewrite($product->id_category_default, $this->context->language->id), + null, + null, + Context::getContext()->shop->id, + 0, + true + ); + if (!$product->active) { - $preview_url = $this->context->link->getProductLink($product, $this->getFieldValue($product, 'link_rewrite', $this->default_form_language), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id)); + $preview_url = $this->context->link->getProductLink( + $product, + $this->getFieldValue($product, 'link_rewrite', $this->default_form_language), + Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id), + null, + null, + Context::getContext()->shop->id, + 0, + true + ); + if (!$product->active) { $admin_dir = dirname($_SERVER['PHP_SELF']);