Jump to content

[SOLVED] Adding a new quick access when module is installed


Recommended Posts

Hello,

I would like to know if is there any function or procedure in prestashop that allows me to add/delete a new quick access when I install/uninstall a new module, but doing it from the module code.

My question is because I am improving a credit card payment module and I would like to add a link to the bank website in the quick access list, allowing the user to access there easily when he wants to check or cancel a payment. But I was checking the quick accesses class code in the admin folder and it was not clear, at least for me.

I hope I explain myself well and you guys can give me any clue about this.

Thanks a lot,
Enrique

Link to comment
Share on other sites

You should be able to do an SQL query like the following in the install() function:

Db::getInstance()->execute("INSERT INTO `"._DB_PREFIX_."quick_access` (`new_window`, `link`) VALUES (1, 'http://www.bank.com')");

$result = Db::getInstance()->executeS("SELECT MAX(`id_quick_access`) AS id FROM `"._DB_PREFIX_."quick_access`");
$languages = Languages::getLanguages();

if (sizeof($result) > 0 AND sizeof($languages) > 0)
  foreach ($languages as $language)
     Db::getInstance()->execute("INSERT INTO `"._DB_PREFIX_."quick_access_lang` (`id_quick_access`, `id_lang`, `name`) VALUES (".$result[0]['id'].", ".$language.", 'Bank')");



and the following in the uninstall() function:

$result = Db::getInstance()->executeS("SELECT `id_quick_access` FROM `"._DB_PREFIX_."quick_access_lang` WHERE `name` = 'Bank'");
if (sizeof($result) > 0)
{
  Db::getInstance()->execute("DELETE FROM `"._DB_PREFIX_."quick_access` WHERE `id_quick_access` = ".$result[0]['id_quick_access']);
  Db::getInstance()->execute("DELETE FROM `"._DB_PREFIX_."quick_access_lang` WHERE `id_quick_access` = ".$result[0]['id_quick_access']);
}



This should hopefully add a quick access when installing the module and delete it when uninstalling the module. I just wrote it off the top of my head and haven't tested the code though, so there may be mistakes.

Link to comment
Share on other sites

×
×
  • Create New...