Merge branch 'ticket-ean' into develop

This commit is contained in:
Marion Muszynski 2016-04-04 15:21:02 +02:00
commit 0880f08f07

View File

@ -14,7 +14,61 @@ class AdminLabelGenerate extends AdminTab {
global $cookie;
$current_sale = Tools::getValue('id_sale');
if ($current_sale) {
if ($current_sale && Tools::getValue('deleteEAN')) {
$sale = new Sale((int)$current_sale);
if(!Validate::isLoadedObject($sale)) {
throw new Exception('This sale doesnt exist');
} else {
$products = $sale->getProducts();
foreach ($products as $key => $id_product) {
$product = new Product($id_product, FALSE, (int) $cookie->id_lang);
$attributes = array();
$combinations = $product->getAttributeCombinaisons($cookie->id_lang);
if ($combinations) {
foreach ($combinations as $key => $combination) {
if (!empty($combination['ean13'])) {
Db::getInstance()->execute('
UPDATE
`'._DB_PREFIX_.'product_attribute`
SET `ean13` = ""
WHERE `id_product` = ' . (int)$product->id .'
AND `id_product_attribute` = ' . (int)$combination['id_product_attribute']
);
Db::getInstance()->Execute('
UPDATE
`'._DB_PREFIX_.'order_detail`
SET `product_ean13` = ""
WHERE `product_id` = '. (int)$product->id .'
AND `product_attribute_id` = '. (int)$combination['id_product_attribute']
);
}
}
} else {
if (!empty($product->ean13)) {
Db::getInstance()->execute('
UPDATE
`'._DB_PREFIX_.'product`
SET `ean13` = ""
WHERE `id_product` = ' . (int)$product->id
);
Db::getInstance()->Execute('
UPDATE
`'._DB_PREFIX_.'order_detail`
SET `product_ean13` = ""
WHERE `product_id` = '. (int)$product->id .'
AND `product_attribute_id` = 0
');
}
}
}
$this->_html .= '<p class="conf">Suppression terminée </p>';
}
}
if ($current_sale && !Tools::getValue('deleteEAN')) {
$sale = new Sale((int)$current_sale);
if(!Validate::isLoadedObject($sale)) {
@ -122,6 +176,10 @@ class AdminLabelGenerate extends AdminTab {
}
$this->_html .= '
</select>
<br class="clear"/>
<br class="clear"/>
<button class="button" id="generateEAN">Générer les EANs</button>
<button class="button" id="deleteEAN" onclick="return confirm(\'Êtes cous sur de vouloir supprimer les eans de cette vente ?\');">Supprimer les EANs</button>
</div>
</fieldset>
<br /><br />';
@ -141,10 +199,19 @@ class AdminLabelGenerate extends AdminTab {
}
);
$(".chosen-select").chosen().change( function() {
if($(this).val() != 999999) {
$(".chosen-select").chosen().change( function() {});
$("#generateEAN").click(function(){
if($(".chosen-select").val() != 999999) {
$(\'#category_selector\').hide();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&id_sale=\' + $(this).val();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&id_sale=\' + $(".chosen-select").val();
}
});
$("#deleteEAN").click(function(){
if($(".chosen-select").val() != 999999) {
console.log($(".chosen-select").val());
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&deleteEAN=1&id_sale=\' + $(".chosen-select").val();
}
});