Search code examples
phpcontent-management-systemprestashopprestashop-1.7

Prestashop module off


I'm creating my first blog for prestashop so far I'm getting to do what I wanted, so I came to a problem that I can not solve:

The module needs an api key to work, the issue is that I can give a warning if this api key does not exist, what I can not do is to disconnect the module, so I use it to understand that something is missing.

if (!Configuration::get('API_KEY')){
    $this->warning = $this->l('No api key provided');
}else{
    $this->_apiKey = Configuration::get('API_KEY');
}

I wanted to turn off the module if there is no variable. So that after the hook he does not execute the code.


Solution

  • In any hook you can begin with:

    if(!($this->_apiKey = Configuration::get('API_KEY')))
        return false;
    

    If there is no API_KEY in configuration it will not execute the rest of the code. EDIT: You can disable it using in the hook.

    if(!($this->_apiKey = Configuration::get('API_KEY')))
    {
            $this->disable(false);  // true to disable for all shops
            return false;
    }