Jump to content
Diddino12

ajax call to AdminOrdersController from view.tpl

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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) {
                    
                },
            });

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Hello Please change the function name of Controller to ajaxProcessCallDBPArrotondamenti and get the value of id order by using Tools::getValue() function.
Thanks.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Hello you can write the function like 

public function ajaxProcessCallDBPArrotondamenti() {
        $id_order = Tools::getValue('id_order');
       // Your logic here
    }

 

Share this post


Link to post
Share on other sites

but this function doesn't want anything in input, order_id should come with my ajax request from template, isn't it?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More