I already passed the ajax value to the front controller from js in prestashop 1.7.6. So I first set the link in hookFooter function of module class file with
// Create a link with the path
$link = new Link;
$parameters = array("action" => "send_changed_price");
$ajax_link = $link->getModuleLink('mymodule','ajax', $parameters);
Second, used this url in custom.js file and made a Ajax call with
$.getJSON(
ajax_link,
{parameter1 : 1100},
function(data) {
if(typeof data.status !== "undefined") {
// Use your new datas here
console.log(data);
}
}
);
And get the Ajax value in init_content function of front controller mymoduele/controllers/front/ajax.php with
switch (Tools::getValue('action')) {
case 'send_changed_price':
$var1 = Tools::getValue('parameter1');
// $var1.=$var;//(float)$var1;
// Edit default response and do some work here
$response = array('status' => true, "message" => $var1);
break;
default:
break;
}
The problem is I want to use this ajax value in my module class, but not in front controller class. Because I have to use this value in hookActionCartSave(one of hook) function of my module class.
How can I pass this value to the module main class? Or is there any other way to pass Ajax value to main module class directly?