process(); class NWAjax{ public function __construct(){} public function process(){ if(Tools::getValue('cookie')){ $lifetime = (int)Tools::getValue('lifetime'); $update = (int)Tools::getValue('update'); die(Tools::JsonEncode($response = $this->checkCookie($update, $lifetime))); } elseif((int)Tools::getValue('action') == 0){ $action = (int)Tools::getValue('action'); $email = Tools::getValue('email'); $page = Tools::getValue('page'); $post_id = false; if(Tools::getValue('id_post')) $post_id = (int)Tools::getValue('id_post'); $blocknewsletter = new BlockNewsletterOverride(); $response = $blocknewsletter->ajaxCall($email,$action,$page,$post_id); die(Tools::JsonEncode($response)); } } private function checkCookie($update = false, $lifetime = 3600){ $cookie = $this->getCookie('ps_newsletter_ligthbox'.Context::getContext()->shop->id); if ($update){ $cookie->event_date = time(); return false; } if (!isset($cookie->event_date) || time() > $cookie->event_date + $lifetime){ return true; } return false; } private function getCookie($cookie_name){ $cookie = new Cookie($cookie_name); if (!$cookie->exists()) $cookie = $this->createCookie($cookie_name); return $cookie; } private function createCookie($cookie_name){ return new Cookie($cookie_name); } }