I have created a button in admin page with the codes below. This is a customised module that I am creating to execute a function from Prestashop back-office.
public function hookDisplayAdminOrder($params) {
$shipping = 'index.php?controller=AdminShipping&type=refund&id_order='.$params['id_order'].'&token='.Tools::getAdminTokenLite('AdminShipping');
$this->context->smarty->assign(array(
'shipping' => $shipping
));
return $this->display(__FILE__, 'views/templates/admin/link.tpl');
}
The button is displayed with the codes below:
<div id="Panel" class="panel">
<div class="panel-heading">
<i class="icon-money"></i>
Shipping Charges
</div>
<button type="button" class="btn btn-default" name="submitShipLabel" onclick="window.open('{$shipping}','_blank');">Execute</button>
My main aim is to execute a function upon button click. I have minimal idea how where to place and call the function from.
Any assistance is greatly appreciated.
Thank you.
<...If I got it right...>
Add custom handler to url:
$shipping = 'index.php?controller=AdminShipping&type=refund&id_order='.$params['id_order'].'&token='.Tools::getAdminTokenLite('AdminShipping').'&customAction=1';
Prepend control to your hook:
if (Tools::getIsSet('customAction') {
$this->yourFunction();
}
result :
public function hookDisplayAdminOrder($params) {
if (Tools::getIsSet('customAction') {
$this->yourFunction();
}
$shipping = 'index.php?controller=AdminShipping&type=refund&id_order='.$params['id_order'].'&token='.Tools::getAdminTokenLite('AdminShipping').'&customAction=1';
$this->context->smarty->assign(array(
'shipping' => $shipping
));
return $this->display(__FILE__, 'views/templates/admin/link.tpl');
}
public function yourFunction()
{
//Do something
}