mzfp Posted October 22, 2012 Share Posted October 22, 2012 Hi, I'm looking to create a module for my store, and part of the module needs to be available in the Back office, and more specifically, it needs to be visible on the product edit page down the left hand side below the other links, i.e "Information, Prices, Seo, Associations" etc. Is it possible to do the above through a module, preferably during installation and programatically? I've spent an awful amount of time trying to get it done via the AdminTab class but not had any luck at all. If someone could share there know ow on this I would be forever grateful. Thanks in advance Musaffar P.S Prestashop version 1.5 Link to comment Share on other sites More sharing options...
nowotny Posted October 23, 2012 Share Posted October 23, 2012 Hello. I've been struggling with the exact same problem for the past week... I didn't find any tutorial or even code example for it so it involved much trial and error but I finally did it... Basically you have to hook the 'displayAdminProductsExtra' hook in which you'll return the html for the contents of your tab... I'm attaching a sample module, that's ready to go and modify... sample.zip 3 Link to comment Share on other sites More sharing options...
mzfp Posted October 23, 2012 Author Share Posted October 23, 2012 Hi nowotny, You're quite a star! ... After spending a few days *really* grinding away at the problem I came to same solution as you. I'm going to take your sample module as I'm sure you've done a better job than I. Would you happen to know how to run a ajax call from the content of these tabs? I've found a solution but it involved created a Admin Controller file in /classes, I was quite keen to keep all my code within my module folder. Thanks Musaffar Link to comment Share on other sites More sharing options...
nowotny Posted October 23, 2012 Share Posted October 23, 2012 Would you happen to know how to run a ajax call from the content of these tabs? Unfortunately no... not from the top of my head... The 'Accessories' feature in 'Associations' tab in Product edit does something with ajax so you could take a look at that... Also search through modules` files in Presta's 'modules' directory on how to do stuff inside a module. That's a great source of information... Getting back to your question - take a look at 'blockwishlist' or 'blockcart' modules... You'd have to put your ajax javascript into a file and load it from your hook like this: $this->context->controller->addJS(($this->_path).'file.js'); And to retrieve data with ajax, you'd have to make separate script and query it with something like this: $.ajax({ type: 'GET', url: baseDir + 'modules/blockcart/blockcart-set-collapse.php', async: true, data: 'ajax_blockcart_display=expand' + '&rand=' + new Date().getTime() }); Hope that helps a little... Link to comment Share on other sites More sharing options...
Czcibor Piotr Posted January 19, 2013 Share Posted January 19, 2013 Hello, I am also trying to add JS file and wonder why this doesn't work: public function hookDisplayAdminProductsExtra($params) { $this->context->controller->addJS($this->path.'script.js'); ... } ? Link to comment Share on other sites More sharing options...
nowotny Posted January 21, 2013 Share Posted January 21, 2013 To add JS file to your tab in BO you have 2 options: 1. Add an ordinary <script> tag for your javascript file to your module's tpl file or html string you return from your hook, like this: public function hookDisplayAdminProductsExtra($params){ return '<h1>My Module</h1><script type="text/javascript" src="'. $this->_path .'script.js"></script>'; } 2. Use the 'ActionAdminControllerSetMedia' hook, like this: public function hookActionAdminControllerSetMedia($arr){ $this->context->controller->addJS( $this->_path .'script.js' ); } The advantage of the first approach is that your javascript file will only be loaded when your module's tab is loaded. If you use the second approach you have to know that your javascript file will be loaded on EVERY page in the BO. However, this can be further restricted if you want to, like this: public function hookActionAdminControllerSetMedia($arr){ if( strtolower(Tools::getValue('controller')) == 'adminproducts' && Tools::getValue('id_product'){ $this->context->controller->addJS( $this->_path .'script.js' ); } } I'm attaching an updated sample module with both solutions. sample_v.2.0.zip Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now