Jquery – How to add JS for modules in prestashop 1.5

jqueryprestashop

Am developing a module in prestashop 1.5. Am using displayAdminProductsExtra hook to display tpl file in admin tab. when i include my jquery code in tpl, it works fine. but when i try to make it as new file and include its not working. so far I tried the below methods..

using displayBackOfficeHeader to register a hook and called like this..

public function hookdisplayBackOfficeHeader($params) 
{
    $this->context->controller->addJS(($this->_path).'abc.js');
}

and I tried to add it in displayAdminProductsExtra also like this..

$this->context->controller->addJS(_MODULE_DIR_.$this->module->name.'/views/js/abc.js'); //first tried..
$this->context->controller->addJS(($this->_path).'abc.js','all'); //second tried this..

And I tried with getcontent like this..

public function getContent()
{   
    $this->_html= '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
        <script src="../modules/abc/abc.js" type="text/javascript" ></script>';
    return $this->_html;
}

but these methods didn't add my js file. Dont know where am making mistake.any help would be appreciated.

Best Answer

When you are creating a Prestashop module, you must add the function hookHeader and within it, the line that adds the js in your page.

Would need something like this:

public function hookHeader ($ params)
{
     $ this-> controller-> addJS (($ this-> _path). 'abc.js');
}

On the other hand, looking at the code of the module blockcategories in blockcategories.php file we see the following:

public function displayForm()
{
...
}

This function is to create a page for module configuration, in the same way you use other modules. Maybe it's a simpler option, but faster to develop.

Regards