From 7fbf0953876e5da8b6e511ac6374531a3bda7bff Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Mon, 4 Apr 2016 15:20:32 +0200 Subject: [PATCH] update for delete ean in sale --- modules/labelgenerate/AdminLabelGenerate.php | 75 ++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index 500be3ad..9d9df87a 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -13,7 +13,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 .= '

Suppression terminée

'; + } + } + + if ($current_sale && !Tools::getValue('deleteEAN')) { $sale = new Sale((int)$current_sale); if(!Validate::isLoadedObject($sale)) { @@ -121,6 +175,10 @@ class AdminLabelGenerate extends AdminTab { } $this->_html .= ' +
+
+ +

'; @@ -140,10 +198,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(); } });