76 lines
2.0 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
include dirname(__FILE__).'/../../config/config.inc.php';
if((Tools::getValue('token') === Tools::getAdminToken('AdminEANManager'.(int) Tab::getIdFromClassName('AdminEANManager').(int) Tools::getValue('id_employee')))) {
if(!$id_product = (int) Tools::getValue('id_product')) {
echo json_encode(array('result' => 'PRODUCT'));
exit;
}
$id_product_attribute = (int) Tools::getValue('id_product_attribute');
$value = Tools::getValue('value');
if($value === FALSE) {
echo json_encode(array('result' => 'EMPTY'));
exit;
}
2016-05-13 16:13:39 +02:00
if(!Validate::isReference($value)) {
2016-01-04 12:49:26 +01:00
echo json_encode(array('result' => 'FORMAT'));
exit;
}
if($value == '0') {
if($id_product_attribute != 0) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `ean13` = ""
WHERE `id_product` = '.$id_product.'
AND `id_product_attribute` = '.$id_product_attribute.'
LIMIT 1
');
} else {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'product`
SET `ean13` = ""
WHERE `id_product` = '.$id_product.'
LIMIT 1
');
}
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = ""
WHERE `product_id` = '.(int) $id_product.'
AND `product_attribute_id` = '.(int) $id_product_attribute.'
');
} elseif($value != '') {
if($id_product_attribute != 0) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `ean13` = "'.pSQL($value).'"
WHERE `id_product` = '.$id_product.'
AND `id_product_attribute` = '.$id_product_attribute.'
LIMIT 1
');
} else {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'product`
SET `ean13` = "'.pSQL($value).'"
WHERE `id_product` = '.$id_product.'
LIMIT 1
');
}
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = "'.pSQL($value).'"
WHERE `product_id` = '.(int) $id_product.'
AND `product_attribute_id` = '.(int) $id_product_attribute.'
');
}
echo json_encode(array('result' => 'OK'));
exit;
}