From 2237a0df033d97d774514a2fabb600c1d5465444 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Mon, 19 Jun 2017 17:04:16 +0200 Subject: [PATCH 1/6] start of new extract --- adm/helpers/includes/css/custom.css | 8 + .../AdminAntConfigurations.php | 2 +- modules/bulkupdate/AdminBulkUpdate.php | 351 +++++++++++++++++- modules/bulkupdate/cron.php | 3 + 4 files changed, 357 insertions(+), 7 deletions(-) diff --git a/adm/helpers/includes/css/custom.css b/adm/helpers/includes/css/custom.css index 013b2498..6402752f 100644 --- a/adm/helpers/includes/css/custom.css +++ b/adm/helpers/includes/css/custom.css @@ -148,6 +148,14 @@ form label{ .panel-title h2 small { margin-left: 10px; } +.heading-title { + margin: 5px 0 20px; + display: block; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + color: #504d8b; +} .navbar-right {margin-right:-5px;} .panel-toolbox>li>a { cursor: pointer; diff --git a/modules/ant_configurations/AdminAntConfigurations.php b/modules/ant_configurations/AdminAntConfigurations.php index 7ad6874c..fe61b49b 100644 --- a/modules/ant_configurations/AdminAntConfigurations.php +++ b/modules/ant_configurations/AdminAntConfigurations.php @@ -517,7 +517,7 @@ class AdminAntConfigurations extends AdminTab $nb_credits = $this->getNbOrderToUpdate(); $helperForm->_forms[] = array( 'action' => $base_link, - 'title' => $this->l('Section Antadis'), + 'title' => ' '.$this->l('Section Antadis'), 'class' => 'form-horizontal', 'class_div' => 'col-md-12', 'sections' => array( diff --git a/modules/bulkupdate/AdminBulkUpdate.php b/modules/bulkupdate/AdminBulkUpdate.php index c68702c3..4700d8bb 100644 --- a/modules/bulkupdate/AdminBulkUpdate.php +++ b/modules/bulkupdate/AdminBulkUpdate.php @@ -1836,7 +1836,331 @@ class AdminBulkUpdate extends AdminTab { $output .= '

'.$this->l('Export complete.').' '.$this->l('Click here to download the file').'

'; } } elseif(Tools::isSubmit('submitExportProducts')) { - HelperFormBootstrap::displayWarning($this->l('En cours de developpement...')); + + set_time_limit(300); + $id_lang = Tools::getValue('id_lang', $cookie->id_lang); + $order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES')); + + $products = Db::getInstance()->ExecuteS('SELECT id_product FROM ps_product WHERE date_add >"'.date('Y-m-d',strtotime('-1 year')).' 00:00:00"'); + if(!$products || empty($products)) { + HelperFormBootstrap::displayError($this->l('Aucun produit trouvé')); + return; + } + + $fname = 'base_produits.csv'; + foreach(glob(dirname(__FILE__).'/*.csv') as $filename) { + if ($fname == $filename) { + unlink($filename); + } + } + + $f = fopen(dirname(__FILE__).'/'.$fname, 'w'); + + // uft8 sans bom pour accent + $BOM = "\xEF\xBB\xBF"; // UTF-8 BOM + fwrite($f, $BOM); // NEW LINE + + fputcsv($f, array( + 'ean13', + 'supplier_reference', + 'id_product', + 'id_product_attribute', + 'position', + 'poids', + 'stock_initial', + 'quantity_sold', + 'quantity', + 'product_name', + 'combination', + 'NC8', + 'Pays de fabrication', + 'public_price_wt', + 'price_wt', + 'wholesale_price', + 'BDC HT', + 'id_TVA', + 'description_short', + 'description_short_es', + 'bon_a_savoir', + 'bon_a_savoir_es', + 'plus', + 'plus_es', + 'videos', + 'videos_es', + 'livraison', + 'livraison_es', + 'images', + 'nb_images', + 'id_sale', + 'categories', + 'id_categories', + 'sous-categories', + 'id_sous-categories', + 'sous-sous-categories', + 'id_sous-sous-categories', + 'family', + 'sale_date', + ), ';', '"'); + + foreach($products as $product) { + $p = new Product((int) $product['id_product'], $id_lang); + if(!Validate::isLoadedObject($p)) { + $output .= '

Erreur produit: '.serialize($product).' ce produit ne figure pas dans l\'export

'; + } else { + $query_sale = Db::getInstance()->getRow(' + SELECT ps.`id_sale`, ps.`date_start` + FROM ps_privatesale ps + LEFT JOIN ps_product_ps_cache psc ON (psc.`id_sale` = ps.`id_sale`) + WHERE psc.`id_product`='.$p->id.' + '); + $sale_info = array( + 'id'=>($query_sale?$query_sale['id_sale']:0), + 'date'=>($query_sale?date('d/m/Y H:i',strtotime($query_sale['date_start'])):'') + ); + + $position = Db::getInstance()->getValue(' + SELECT `position` + FROM `'._DB_PREFIX_.'category_product` + WHERE `id_category` = '.(int) $p->id_category_default.' + AND id_product = '. (int) $p->id . ' + '); + $p->position = $position; + + $categories = array(); + foreach(Db::getInstance()->ExecuteS(' + SELECT `id_category` + FROM `'._DB_PREFIX_.'category_product` + WHERE `id_product` = '.(int) $p->id.' + ') as $cat) { + $categories[] = (int) $cat['id_category']; + } + sort($categories); + + $categories_title = array(); + foreach ($categories as $category) { + $title = Db::getInstance()->getValue(' + SELECT `name` + FROM `'._DB_PREFIX_.'category_lang` + WHERE `id_category` = '.(int) $category.' + AND id_lang = '. $id_lang . ' + '); + $categories_title[] = $title; + } + $categorie_0 = ''; + $categorie_0_id = 0; + $categorie_1 = ''; + $categorie_1_id = 0; + $categorie_2 = ''; + $categorie_2_id = 0; + foreach ($categories as $key => $cat) { + if ($key == 0) { + $categorie_0 = $categories_title[$cat]; + $categorie_0_id = $cat; + } elseif ($key == 1) { + $categorie_1 = $categories_title[$cat]; + $categorie_1_id = $cat; + } elseif ($key == 2) { + $categorie_2 = $categories_title[$cat]; + $categorie_2_id = $cat; + } + } + $family = Db::getInstance()->getRow(' + SELECT fl.`name` + FROM ps_category_family_lang fl + LEFT JOIN ps_category_family_association f ON (f.`id_category_family` = fl.`id_category_family`) + WHERE fl.`id_lang` = 2 AND f.`id_category`='.(int)$categorie_1_id + ); + if(!$family || empty($family['name'])) { + $family = Db::getInstance()->getRow(' + SELECT fl.`name` + FROM ps_category_family_lang fl + LEFT JOIN ps_category_family_association f ON (f.`id_category_family` = fl.`id_category_family`) + WHERE fl.`id_lang` = 2 AND f.`id_category`='.(int)$categorie_0_id + ); + } + + $combinations = array(); + foreach($p->getAttributeCombinaisons($id_lang) as $combi) { + if(!isset($combinations[$combi['id_product_attribute']])) { + $combinations[$combi['id_product_attribute']] = array( + 'qty' => $combi['quantity'], + 'name' => array($combi['attribute_name']), + 'ean13' => $combi['ean13'], + 'location' => empty($combi['location'])? $p->location: $combi['location'], + 'brand' => $p->manufacturer_name, + 'supplier_reference' => empty($combi['supplier_reference'])? $p->supplier_reference: $combi['supplier_reference'], + ); + } else { + $combinations[$combi['id_product_attribute']]['name'][] = $combi['attribute_name']; + } + } + + $images = array(); + foreach(Db::getInstance()->ExecuteS(' + SELECT i.`id_image`, l.`legend` + FROM `'._DB_PREFIX_.'image` i + LEFT JOIN `'._DB_PREFIX_.'image_lang` l + ON l.`id_image` = i.`id_image` + WHERE l.`id_lang` = '.(int) $id_lang.' + AND i.`id_product` = '.(int) $p->id.' + ORDER BY i.`position` + ') as $img) { + $link_image = str_split($img['id_image']); + $images[] = 'http://static.bebeboutik.com/img/p/'.implode('/', $link_image) .'/'. $img['id_image'].'.jpg'; + } + + if(count($combinations) > 0) { + foreach($combinations as $k => $v) { + $c_images = array(); + foreach(Db::getInstance()->ExecuteS(' + SELECT i.`id_image`, l.`legend` + FROM `'._DB_PREFIX_.'image` i + LEFT JOIN `'._DB_PREFIX_.'image_lang` l + ON l.`id_image` = i.`id_image` + LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` a + ON a.`id_image` = i.`id_image` + WHERE l.`id_lang` = '.(int) $id_lang.' + AND a.`id_product_attribute` = '.(int) $k.' + ORDER BY i.`position` + ') as $img) { + $link_image = str_split($img['id_image']); + $c_images[] = 'http://static.bebeboutik.com/img/p/'.implode('/', $link_image) .'/'. $img['id_image'].'.jpg'; + } + + $names = array_unique($v['name']); + sort($names, SORT_STRING); + + $quantity_sold = (int) Db::getInstance()->getValue(' + SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`) + FROM `'._DB_PREFIX_.'order_detail` d + LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + WHERE d.`product_id` = '.(int) $p->id.' + AND d.`product_attribute_id` = '.(int) $k.' + AND ( + SELECT `id_order_state` + FROM `'._DB_PREFIX_.'order_history` oh + WHERE o.`id_order` = oh.`id_order` + ORDER BY `id_order_history` DESC + LIMIT 1 + ) IN ("'.implode('","', $order_states).'") + '); + + $customs = Db::getInstance()->getRow(' + SELECT `nc8`, `id_country` + FROM `'._DB_PREFIX_.'product_customs` + WHERE `id_product` = '.(int) $p->id + ); + + fputcsv($f, array( + $v['ean13'], + $v['supplier_reference'], + $p->id, + $k, + $p->position, + str_replace('.', ',', $p->weight), + ($v['qty']+$quantity_sold), + $quantity_sold, + $v['qty'], + $p->name[$id_lang], + implode(' - ', $names), + $customs['nc8'], + $customs['id_country'], + str_replace('.', ',', $p->getPrice(TRUE, (int) $k, 2, NULL, FALSE, FALSE)), + str_replace('.', ',', $p->getPrice(TRUE, (int) $k, 2)), + str_replace('.', ',', Tools::ps_round($p->wholesale_price, 2)), + str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)), + str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)), + $p->id_tax_rules_group, + $p->description_short[$id_lang], + $p->description_short[3], + $p->description[$id_lang], + $p->description[3], + $p->description_more[$id_lang], + $p->description_more[3], + $p->videos[$id_lang], + $p->videos[3], + $p->description_delivery[$id_lang], + $p->description_delivery[3], + count($c_images) > 0? implode(', ', $c_images): implode(', ', $images), + $sale_info['sale_id'], + $categorie_0, + $categorie_0_id, + $categorie_1, + $categorie_1_id, + $categorie_2, + $categorie_2_id, + $family['name'], + $sale_info['sale_date'], + ), ';', '"'); + } + } else { + + $quantity_sold = (int) Db::getInstance()->getValue(' + SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`) + FROM `'._DB_PREFIX_.'order_detail` d + LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` + WHERE d.`product_id` = '.(int) $p->id.' + AND d.`product_attribute_id` = 0 + AND ( + SELECT `id_order_state` + FROM `'._DB_PREFIX_.'order_history` oh + WHERE o.`id_order` = oh.`id_order` + ORDER BY `id_order_history` DESC + LIMIT 1 + ) IN ("'.implode('","', $order_states).'") + '); + + $customs = Db::getInstance()->getRow(' + SELECT `nc8`, `id_country` + FROM `'._DB_PREFIX_.'product_customs` + WHERE `id_product` = '.(int) $p->id + ); + + fputcsv($f, array( + $p->ean13, + $p->supplier_reference, + $p->id, + 0, + $p->position, + str_replace('.', ',', $p->weight), + ($p->quantity+$quantity_sold), + $quantity_sold, + $p->quantity, + $p->name[$id_lang], + '', + $customs['nc8'], + $customs['id_country'], + str_replace('.', ',', $p->getPrice(TRUE, NULL, 2, NULL, FALSE, FALSE)), + str_replace('.', ',', $p->getPrice(TRUE, NULL, 2)), + str_replace('.', ',', Tools::ps_round($p->wholesale_price, 2)), + str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)), + $p->id_tax_rules_group, + $p->description_short[$id_lang], + $p->description_short[3], + $p->description[$id_lang], + $p->description[3], + $p->description_more[$id_lang], + $p->description_more[3], + $p->videos[$id_lang], + $p->videos[3], + $p->description_delivery[$id_lang], + $p->description_delivery[3], + implode(', ', $images), + $sale_info['sale_id'], + $categorie_0, + $categorie_0_id, + $categorie_1, + $categorie_1_id, + $categorie_2, + $categorie_2_id, + $family['name'], + $sale_info['date_sale'], + ), ';', '"'); + } + } + } + fclose($f); + HelperFormBootstrap::displaySuccess('

'.$this->l('Export complete.').' '.$this->l('Click here to download the file').'

'); } elseif(Tools::isSubmit('submitExportPositions')) { set_time_limit(300); if($id_category = (int) Tools::getValue('category')) { @@ -1953,8 +2277,8 @@ class AdminBulkUpdate extends AdminTab { // Categories $output .= '
-

Mise à jour groupée

+

'.$this->l('Mises à jour groupées').'