jellyMan Posted October 26, 2016 Share Posted October 26, 2016 Is there a way to add a new section to a products config page? See screenshot. Link to comment Share on other sites More sharing options...
rocky Posted October 26, 2016 Share Posted October 26, 2016 Yes, there's a displayAdminProductsExtra hook that modules can use to add a new tab there. The module's name is used as the tab name and the content returned from the hookDisplayAdminProductsExtra function in the module will be displayed as the content of the tab. 1 Link to comment Share on other sites More sharing options...
jellyMan Posted October 26, 2016 Author Share Posted October 26, 2016 Great stuff! So now i've done that, id like to save some info from my content tab into the database via ajax. Where can I learn about what url to send my ajax request to? Link to comment Share on other sites More sharing options...
rocky Posted October 27, 2016 Share Posted October 27, 2016 Take your module's configuration page link and add something like &ajax=1&action=myaction to the end and then add a function to your module's PHP file like the following: public function ajaxProcessMyAction() { } Link to comment Share on other sites More sharing options...
jellyMan Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) Whats my modules configuration page link? In my view ive got some jquery to send an ajax request $(document).on('click', '#ajax_add_video', function(e) { e.preventDefault(); var product_id = $('input[name=id_product]').val(); var embed_code = $('#add_video').val(); $.ajax({ type: 'POST', url: '/modules/rvlvideos/rvlvideos.php&ajax=1&action=storevideo', data: { product_id: product_id, embed_code: embed_code }, dataType: 'json', success: function(json) { console.log(json); } }) return false; }); Then in my module controller, /modules/rvlvideos/rvlvideos.php ive got an ajaxProcessStoreVideo() method public function ajaxProcessStoreVideo() { return 'GOT TO MY CLASS'; } But when I click my #ajax_add_video button - my ajax response is a 404 page not found error.... Edited October 27, 2016 by jellyMan (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted October 27, 2016 Share Posted October 27, 2016 The URL should be something like index.php?controller=AdminModules&token=<token>&configure=modulename&ajax=1&action=storevideo Link to comment Share on other sites More sharing options...
jellyMan Posted October 27, 2016 Author Share Posted October 27, 2016 I'm not configuring my module so are you sure this is right? Link to comment Share on other sites More sharing options...
jellyMan Posted October 27, 2016 Author Share Posted October 27, 2016 I'm just wanting to reach a method on my module class from the product options page with ajax... I don't understand how the urls work to be able to get there Link to comment Share on other sites More sharing options...
rocky Posted October 27, 2016 Share Posted October 27, 2016 I think so, but to be honest, I've never actually tried it from a tab on the product editor. I just know that's how I perform AJAX requests on my module's configuration page. I would expect it to work from the the product editor as well. Since it's an AJAX request, it should return the results only and not load the entire configuration page. Link to comment Share on other sites More sharing options...
jellyMan Posted October 27, 2016 Author Share Posted October 27, 2016 Ok - so trying this way just tells me that a method of module cannot be found I've got 'ajax=true&configure=rvlvideos&action=storevideo' Link to comment Share on other sites More sharing options...
rocky Posted October 27, 2016 Share Posted October 27, 2016 Does your module have a configuration page? That error message makes me think it doesn't. Link to comment Share on other sites More sharing options...
jellyMan Posted October 27, 2016 Author Share Posted October 27, 2016 No there isn't a configuration page for my module... My module is at the very early stages and it's my first one so I may be missing a lot out... but for now all im trying to achieve is this... I have a new section on my product editing page called "RVL Videos".... i've got that loading in and displaying a simple form for that section. The confirm just consists of a simple text field and a submit button.... On submit I want to run my storeVideo() method thats in my module and the field input to the database. I havent registered it as an admin module and there is no configuration page. Surely generating the url for the ajax request should be more simple than this - i dont get it. Link to comment Share on other sites More sharing options...
rocky Posted October 27, 2016 Share Posted October 27, 2016 That explains the error. I've never performed AJAX calls to a module without a configuration page before. Maybe there's a way to call the module without calling the configuration page? You can search the PrestaShop Developer Guide to see if there's anything about it. Link to comment Share on other sites More sharing options...
jellyMan Posted October 27, 2016 Author Share Posted October 27, 2016 Yeh ive had a look in the docs theres not much there to help to be honest... getting a little frustrated now Link to comment Share on other sites More sharing options...
rocky Posted October 27, 2016 Share Posted October 27, 2016 I guess your only solution is to create a separate PHP file in your module just to handle AJAX requests. For example, modules/storevideo/ajax.php with the following: include_once('../../config/config.inc.php'); include_once('../../init.php'); include_once('storevideo.php'); $storevideo = new StoreVideo(); Then you can call public functions from your storevideo.php file. 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