Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

79 lines
2.5 KiB
PHP

<?php
/**
* Description of privatesalesnewsletter
*
* @company Antadis
*/
class privatesalesconcoursModuleFrontController extends ModuleFrontController {
public function initContent() {
if(Tools::getValue('ajax'))
$this->ajaxProcessSubmit();
}
public function ajaxProcessSubmit(){
$id_privatesales = Tools::getValue('id_privatesales');
$id_product = Tools::getValue('id_product');
$id_product_attribute = Tools::getValue('id_product_attribute');
$this->registerCustomer($id_privatesales, $id_product, $id_product_attribute);
}
public function registerCustomer($id_privatesales, $id_product, $id_product_attribute = 0){
$customer = Context::getContext()->customer;
if (!$id_product_attribute)
$id_product_attribute = 0;
$register = Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'privatesales_concours`
WHERE `id_customer` = ' . (int)$customer->id . '
AND `id_privatesales` = ' . (int)$id_privatesales . '
AND `id_product` = ' . (int)$id_product . '
AND `id_product_attribute` = ' . (int)$id_product_attribute
);
if ($register){
die(Tools::jsonEncode(array(
'has_error' => true,
'message' => 'Vous avez d&eacute;j&agrave; enregistr&eacute; ce produit pour le jeu concours.'
)));
}
$alreadyPlayed = Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'privatesales_concours`
WHERE `id_customer` = '. (int)$customer->id .'
AND `id_privatesales` = '. (int)$id_privatesales
);
if ($alreadyPlayed)
$sql = 'UPDATE `'._DB_PREFIX_.'privatesales_concours`
SET `id_product` = '. (int)$id_product .', `id_product_attribute` = '. (int)$id_product_attribute .', `date_add` = \''.date('Y-m-d H:i:s').'\'
WHERE `id_customer` = '. (int)$customer->id .'
AND `id_privatesales` = '. (int)$id_privatesales .'';
else
$sql = 'INSERT INTO `'._DB_PREFIX_.'privatesales_concours` VALUE(
DEFAULT,
'.(int)$id_privatesales.',
'.(int)$customer->id.',
'.(int)$id_product.',
'.(int)$id_product_attribute.',
\''.date('Y-m-d H:i:s').'\',
0
)';
$res = Db::getInstance()->execute($sql);
if ($res){
die(Tools::jsonEncode(array(
'has_error' => false,
'message' => 'La s&eacute;lection de ce produit a bien &eacute;t&eacute; enregistr&eacute;e et remplacera la pr&eacute;c&eacute;dente s\'il y en avait une.'
)));
}
die(Tools::jsonEncode(array(
'has_error' => true,
'message' => 'Une erreur c\'est produite lors de votre enregistrement.'
)));
}
}