From ff78da047e9061b5c8deb99b5f6b6550f9d5b32d Mon Sep 17 00:00:00 2001 From: bibips <6272184+bibips@users.noreply.github.com> Date: Sat, 3 Jun 2023 23:05:41 +0200 Subject: [PATCH 1/2] Add hook actionMainMenuModifier Thanks this hook it's possible to alter main menu. For instance you can display menu items per customer or per group of customer --- config.xml | 2 +- ps_mainmenu.php | 13 ++++++++++--- upgrade/upgrade-2.3.5.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 upgrade/upgrade-2.3.5.php diff --git a/config.xml b/config.xml index 6f1e466..c5e449e 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_mainmenu - + diff --git a/ps_mainmenu.php b/ps_mainmenu.php index e29ade9..d361e23 100644 --- a/ps_mainmenu.php +++ b/ps_mainmenu.php @@ -69,7 +69,7 @@ public function __construct() { $this->name = 'ps_mainmenu'; $this->tab = 'front_office_features'; - $this->version = '2.3.4'; + $this->version = '2.3.5'; $this->author = 'PrestaShop'; $this->imageFiles = null; @@ -136,7 +136,10 @@ public function installDb() `label` VARCHAR( 128 ) NOT NULL , `link` VARCHAR( 128 ) NOT NULL , INDEX ( `id_linksmenutop` , `id_lang`, `id_shop`) - ) ENGINE = ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8mb4;'); + ) ENGINE = ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8mb4;') && + Db::getInstance()->execute(' + INSERT IGNORE INTO `' . _DB_PREFIX_ . 'hook` (`name`, `title`, `description`) VALUES + (\'actionMainMenuModifier\', \'Modify main menu view data\', \'This hook allows to alter main menu data\');'); } public function uninstall($delete_params = true) @@ -1489,8 +1492,12 @@ public function getWidgetVariables($hookName, array $configuration) public function renderWidget($hookName, array $configuration) { + $menu = $this->getWidgetVariables($hookName, $configuration); + + Hook::exec('actionMainMenuModifier', ['menu' => &$menu]); + $this->smarty->assign([ - 'menu' => $this->getWidgetVariables($hookName, $configuration), + 'menu' => $menu, ]); return $this->fetch('module:ps_mainmenu/ps_mainmenu.tpl'); diff --git a/upgrade/upgrade-2.3.5.php b/upgrade/upgrade-2.3.5.php new file mode 100644 index 0000000..9749377 --- /dev/null +++ b/upgrade/upgrade-2.3.5.php @@ -0,0 +1,28 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_2_3_5($module) +{ + return Db::getInstance()->execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . "hook` (`name`, `title`, `description`) VALUES + ('actionMainMenuModifier', 'Modify main menu view data', 'This hook allows to alter main menu data')"); +} From 888269a292a637b1c05d9103c0b4d4a1589e0b7a Mon Sep 17 00:00:00 2001 From: Codencode Date: Wed, 14 May 2025 12:31:23 +0200 Subject: [PATCH 2/2] Added hook "ActionMetaPageSave" for cache deletion --- ps_mainmenu.php | 6 ++++++ upgrade/upgrade-2.3.5.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ps_mainmenu.php b/ps_mainmenu.php index d361e23..db89d8b 100644 --- a/ps_mainmenu.php +++ b/ps_mainmenu.php @@ -100,6 +100,7 @@ public function install($delete_params = true) !$this->registerHook('actionObjectProductDeleteAfter') || !$this->registerHook('actionObjectProductAddAfter') || !$this->registerHook('actionCategoryUpdate') || + !$this->registerHook('actionMetaPageSave') || !$this->registerHook('actionShopDataDuplication') || !$this->registerHook('displayTop')) { return false; @@ -990,6 +991,11 @@ public function hookActionCategoryUpdate($params) $this->clearMenuCache(); } + public function hookActionMetaPageSave($params) + { + $this->clearMenuCache(); + } + protected function getCacheDirectory() { $dir = _PS_CACHE_DIR_ . 'ps_mainmenu'; diff --git a/upgrade/upgrade-2.3.5.php b/upgrade/upgrade-2.3.5.php index 9749377..005c06e 100644 --- a/upgrade/upgrade-2.3.5.php +++ b/upgrade/upgrade-2.3.5.php @@ -24,5 +24,6 @@ function upgrade_module_2_3_5($module) { return Db::getInstance()->execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . "hook` (`name`, `title`, `description`) VALUES - ('actionMainMenuModifier', 'Modify main menu view data', 'This hook allows to alter main menu data')"); + ('actionMainMenuModifier', 'Modify main menu view data', 'This hook allows to alter main menu data')") + && $module->registerHook('actionMetaPageSave'); }