From f191da259ca5bc823e573cacde94cac150945e60 Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Tue, 10 Dec 2024 12:28:04 +0100 Subject: [PATCH] Set new option of lang prefix dynamically depending on current URL structure --- upgrade/php/ps_900_set_url_lang_prefix.php | 45 ++++++++++++++++++++++ upgrade/sql/9.0.0.sql | 7 ++-- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 upgrade/php/ps_900_set_url_lang_prefix.php diff --git a/upgrade/php/ps_900_set_url_lang_prefix.php b/upgrade/php/ps_900_set_url_lang_prefix.php new file mode 100644 index 000000000..d3ebaaff8 --- /dev/null +++ b/upgrade/php/ps_900_set_url_lang_prefix.php @@ -0,0 +1,45 @@ + + */ + +use PrestaShop\Module\AutoUpgrade\DbWrapper; + +/** + * @return void + * + * @throws \PrestaShop\Module\AutoUpgrade\Exceptions\UpdateDatabaseException + */ +function ps_900_set_url_lang_prefix() +{ + $numberOfActiveLanguages = (int) DbWrapper::getValue( + 'SELECT COUNT(*) AS lang_count FROM `' . _DB_PREFIX_ . 'lang` WHERE `active` = 1' + ); + + if ($numberOfActiveLanguages > 1) { + Configuration::updateValue('PS_DEFAULT_LANGUAGE_URL_PREFIX', 1); + } else { + Configuration::updateValue('PS_DEFAULT_LANGUAGE_URL_PREFIX', 0); + } +} diff --git a/upgrade/sql/9.0.0.sql b/upgrade/sql/9.0.0.sql index c73c7cb12..2820f9e1e 100644 --- a/upgrade/sql/9.0.0.sql +++ b/upgrade/sql/9.0.0.sql @@ -1,7 +1,6 @@ SET SESSION sql_mode=''; SET NAMES 'utf8mb4'; -/* Enable controlling of default language URL prefix - https://github.com/PrestaShop/PrestaShop/pull/37236 */ /* Add a file separator input to the sql manager settings - https://github.com/PrestaShop/PrestaShop/pull/35843 */ /* Allow configuring maximum word difference - https://github.com/PrestaShop/PrestaShop/pull/37261 */ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES @@ -9,10 +8,12 @@ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VAL ('PS_DEBUG_COOKIE_VALUE', '', NOW(), NOW()), ('PS_SEPARATOR_FILE_MANAGER_SQL', ';', NOW(), NOW()), ('PS_PRODUCT_BREADCRUMB_CATEGORY', 'default', NOW(), NOW()), - ('PS_SEARCH_FUZZY_MAX_DIFFERENCE', 5, NOW(), NOW()), - ('PS_DEFAULT_LANGUAGE_URL_PREFIX', 1, NOW(), NOW()) + ('PS_SEARCH_FUZZY_MAX_DIFFERENCE', 5, NOW(), NOW()) ; +/* Enable controlling of default language URL prefix - https://github.com/PrestaShop/PrestaShop/pull/37236 */ +/* PHP:ps_900_set_url_lang_prefix(); */; + /* Remove meta keywords - https://github.com/PrestaShop/PrestaShop/pull/36873 */ /* PHP:drop_column_if_exists('category_lang', 'meta_keywords'); */; /* PHP:drop_column_if_exists('cms_lang', 'meta_keywords'); */;