Diddino12 Posted July 16, 2019 Share Posted July 16, 2019 hello, i'm new in developing world, and i hope i can find some help here; I need to call AdminOrdersController from adminXXXXXXXX\themes\default\template\controllers\orders\helpers\view\view.tpl inside view.tpl i created a button; <button id="ricalcolo_tot" class="btn btn-success" type="button" disabled> <i class="fa fa-dollar"></i> {l s='calculate total price' d='Admin.Orderscustomers.Feature'} </button> inside AdminOrdersController.php I have a function that should make a db Call to a stores Procedure: public function callDBPArrotondamenti($id_order) { echo "called"; $orders_qy = Db::getInstance()->ExecuteS('CALL arrotondamenti($id_order)'); } how can i call the function form view.tpl with an ajax request directly from template? Thanks for any answer. Link to comment Share on other sites More sharing options...
CedCommerce Team Posted July 18, 2019 Share Posted July 18, 2019 Hi You can call AdminOrdersController from your tpl file as: $.ajax({ type: 'POST', url: 'ajax-tab.php', data: { controller: 'AdminOrdersController', ajax : true, action : //Your function name in controller , token : //Controller token }, success: function (response) { }, }); Link to comment Share on other sites More sharing options...
Diddino12 Posted July 18, 2019 Author Share Posted July 18, 2019 hello CedCommerceTeam and thanks for your reply, i already tried to contact AdminOrdersController throught a ajax POST call but this call doesn't reach the controller: function Button2listener(event) { /* $.ajax({ type : 'POST', dataType : 'json', url : 'ajax-tab.php', data : { //required parameters ajax : true, controller : 'AdminOrdersController', action : 'callDBPArrotondamenti', token : '{$token}', //additional parameters to your controller id_order : '{$order->id}' } }) .done(function(){ console.log('success'); }) .fail(function(){ console.log('fail'); });*/ } any advice? Link to comment Share on other sites More sharing options...
CedCommerce Team Posted July 18, 2019 Share Posted July 18, 2019 Hello Please change the function name of Controller to ajaxProcessCallDBPArrotondamenti and get the value of id order by using Tools::getValue() function. Thanks. Link to comment Share on other sites More sharing options...
Diddino12 Posted July 18, 2019 Author Share Posted July 18, 2019 can you please give me an example of a function that i can use inside my controller to pass the value id_order (received by ajax call from tpl) to a stored procedure inside my db? dont know how to read the value sent throught the ajax call. thanks for replies. Link to comment Share on other sites More sharing options...
CedCommerce Team Posted July 18, 2019 Share Posted July 18, 2019 Hello you can write the function like public function ajaxProcessCallDBPArrotondamenti() { $id_order = Tools::getValue('id_order'); // Your logic here } Link to comment Share on other sites More sharing options...
Diddino12 Posted July 18, 2019 Author Share Posted July 18, 2019 but this function doesn't want anything in input, order_id should come with my ajax request from template, isn't it? Link to comment Share on other sites More sharing options...
CedCommerce Team Posted July 18, 2019 Share Posted July 18, 2019 Yes. You dont need to pass any argument in the function. The request parameter like order id of ajax request can be get by using the Tools::getValue() function. 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