2016-06-28 11:54:23 +02:00

56 lines
1.2 KiB
PHP

<?php
include_once (dirname(__FILE__).'/../../config/config.inc.php');
if (!Tools::getValue('y_event'))
die(0);
$YAjax = new YAjax();
$YAjax->process();
class YAjax{
public function __construct(){
}
public function process(){
$lifetime = (int)Tools::getValue('lifetime');
$update = (int)Tools::getValue('update');
switch (Tools::getValue('y_event')) {
case 'cart':
case 'customer':
case 'product':
case 'concours':
case 'promo':
die(Tools::JsonEncode($response = $this->processYield(Tools::getValue('y_event'), $update, $lifetime)));
break;
default:
die(0);
break;
}
}
private function processYield($event, $update = false, $lifetime = 3600){
$cookie = $this->getCookie('ps_yieldify_' . $event . 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);
}
}