_object = false; $this->controller = 'AdminModules'; $this->module_name = 'ant_wp'; $this->config_tab = (bool)$config_tab; if ($config_tab) { $this->controller = 'AdminAntWp'; } $this->helperForm = new HelperFormBootstrap(); // $this->helperForm->_select2 = true; // $this->helperForm->_inputSwitch = true; } public function display() { parent::displayForm(); $this->_html = ''; $this->_postProcess(); $this->_addCss(); $this->_html .= $this->helperForm->renderStyle(); $this->_displayForm(); //$this->_displayList(); $this->_html .='
'; $this->_addJs(); $this->_html .= $this->helperForm->renderScript(); echo $this->_html; } protected function _addJs() { $this->helperForm->_js .= ''; } protected function _addCss() { $this->helperForm->_css .=' .table tr th { background: #565485; background: rgba(86,84,133,0.9); color: #fff; font-size: 12px; } .table tr:nth-child(even) { background: #F1F1F1; } .table .input-group-btn .btn { padding: 4px 5px; color: #504d8b; } .table .input-group-btn .btn .anticon{ font-size: 12px; } .bg-grey{ background: #EFEFEF; border-radius:4px; } .bg-grey .div-title { border-bottom: 2px solid #504D8B; } .control-label.text-left{ text-align:left!important; } '; } protected function _postProcess() { if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') { $filename = Tools::getValue('filename')?'WP-Vente '.Tools::getValue('filename'):'WP-Vente'; $marque = Tools::getValue('filename')?Tools::getValue('filename'):'Marque'; $params = array('marque' => $marque, 'filename' => $filename, 'lines' => array()); $f = fopen($_FILES['csvfile']['tmp_name'], 'r'); fgetcsv($f, 0, ';'); $products = array(); $product_info = array(); $refs = array(); $eans = array(); while($line = fgetcsv($f, 0, ';')) { if($line[0] == '' && $line[1] == '') { continue; } if($line[0] != '') { $ean = trim($line[0]); $products[$ean] = array( 'ean' => $ean, 'supplier_ref' => trim((String)utf8_encode($line[1])), 'name_ha' => trim((String)utf8_encode($line[2])), 'quantity' => trim($line[3]), 'ppc' => trim((float)$line[4]), 'prix_ha' => trim((float)$line[5]), 'name_attribute_ha' => trim((String)$line[6]) ); $eans[] = $ean; } else { $ref = trim((String)utf8_encode($line[1])); $products[$ref] = array( 'ean' => trim($line[0]), 'supplier_ref' => $ref, 'name_ha' => trim((String)utf8_encode($line[2])), 'quantity' => trim($line[3]), 'ppc' => trim((float)$line[4]), 'prix_ha' => trim((float)$line[5]), 'name_attribute_ha' => trim((String)utf8_encode($line[6])) ); $refs[] = $ref; } } $product_info = array(); $product_found = 0; $ids = array(); foreach (Db::getInstance()->executeS(' SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, p.`ean13`, p.`price`, p.`wholesale_price`, p.`reference`, p.`supplier_reference`, p.`weight`, p.`height`, p.`width`, p.`depth`, c.`position`, cu.`nc8`, cu.`id_country` FROM `'._DB_PREFIX_.'product` p INNER JOIN (SELECT date_add, max(id_product) as maxid FROM `'._DB_PREFIX_.'product` GROUP BY ean13) as b ON p.`id_product` = b.maxid LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (b.maxid = c.`id_product` AND p.`id_category_default` = c.`id_category`) LEFT JOIN `'._DB_PREFIX_.'product_customs` cu ON (cu.`id_product` = p.`id_product`) WHERE p.`ean13` IN ("'.implode('","',$eans).'") '.(!empty($refs)?' OR p.`supplier_reference` IN ("'.implode('","',$refs).'")':'').' AND p.`id_product` IS NOT NULL ORDER BY c.`position` ') as $row) { if($row['ean13']!='' && isset($products[$row['ean13']])){ $products[$row['ean13']] = array_merge($products[$row['ean13']], $row); $product_found++; $ids[] = (int)$row['id_product']; } elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){ $products[$row['supplier_reference']] = array_merge($products[$row['supplier_reference']], $row); $product_found++; $ids[] = (int)$row['id_product']; } } foreach (Db::getInstance()->executeS(' SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, at.`ean13`, p.`price`, p.`wholesale_price`, p.`reference`, p.`supplier_reference`, p.`weight`, p.`height`, p.`width`, p.`depth`, c.`position`, cu.`nc8`, cu.`id_country`, al.`name` as attribute_name FROM `'._DB_PREFIX_.'product` p INNER JOIN (SELECT date_add, max(id_product) as maxid FROM `'._DB_PREFIX_.'product` GROUP BY `supplier_reference`) as b ON p.`id_product` = b.maxid LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (b.maxid = c.`id_product` AND p.`id_category_default` = c.`id_category`) LEFT JOIN `'._DB_PREFIX_.'product_customs` cu ON (cu.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` at ON (at.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` ac ON (ac.`id_product_attribute` = at.`id_product_attribute`) LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.`id_attribute` = ac.`id_attribute` AND al.`id_lang` = 2) WHERE at.`ean13` IN ("'.implode('","',$eans).'") AND p.`id_product` IS NOT NULL ORDER BY c.`position` ') as $row) { if($row['ean13']!='' && isset($products[$row['ean13']])){ $products[$row['ean13']] = array_merge($products[$row['ean13']], $row); $product_found++; } elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){ $products[$row['supplier_reference']] = array_merge($products[$row['supplier_reference']], $row); $product_found++; } if(!in_array((int)$row['id_product'],$ids)){ $ids[] = (int)$row['id_product']; } } $new_products = count($products) - $product_found; if(!empty($ids)){ foreach (Db::getInstance()->executeS(' SELECT p.`ean13`, p.`supplier_reference`, pl.* FROM '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.`id_product` = p.`id_product`) WHERE p.`id_product` IN ('.implode(',',$ids).') AND (pl.id_lang = 2 OR pl.id_lang = 3) ORDER BY p.`id_product` ') as $row) { if($row['ean13']!='' && isset($products[(int)$row['ean13']])){ if(!isset($products[$row['ean13']]['lang'])){ $products[$row['ean13']]['lang'] = array(); } if(!isset($products[$row['ean13']]['lang'][(int)$row['id_lang']])){ $products[$row['ean13']]['lang'][(int)$row['id_lang']] = $row; } } elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){ if(!isset($products[$row['supplier_reference']]['lang'])){ $products[$row['supplier_reference']]['lang'] = array(); } if(!isset($products[$row['supplier_reference']]['lang'][(int)$row['id_lang']])){ $products[$row['supplier_reference']]['lang'][(int)$row['id_lang']] = $row; } } } foreach (Db::getInstance()->executeS(' SELECT at.`ean13`, p.`supplier_reference`, pl.* FROM '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` at ON (at.`id_product` = p.`id_product`) WHERE p.`id_product` IN ('.implode(',',$ids).') AND (pl.id_lang = 2 OR pl.id_lang = 3) ORDER BY p.`id_product` ') as $row) { if($row['ean13']!='' && isset($products[(int)$row['ean13']])){ if(!isset($products[$row['ean13']]['lang'])){ $products[$row['ean13']]['lang'] = array(); } if(!isset($products[$row['ean13']]['lang'][(int)$row['id_lang']])){ $products[$row['ean13']]['lang'][(int)$row['id_lang']] = $row; } } elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){ if(!isset($products[$row['supplier_reference']]['lang'])){ $products[$row['supplier_reference']]['lang'] = array(); } if(!isset($products[$row['supplier_reference']]['lang'][(int)$row['id_lang']])){ $products[$row['supplier_reference']]['lang'][(int)$row['id_lang']] = $row; } } } } $params['lines'] = $products; if(!empty($params['lines'])){ $wp = new GenerateWp(); $wp->generate($params); $filename = str_replace(' ', '_', $filename); $wp->objWriter->save(dirname(__FILE__).'/'.$filename.'.xlsx'); $this->_html .= HelperFormBootstrap::displaySuccess('Génération complètePour la génération du WP
Veuillez importer un fichier sous format csv
Avec les colonnes suivantes :
Les colonnes suivantes et la première ligne du fichier seront ignorées.
' ), ), 'actions' => array(), 'actions-class' => 'text-right', ) ); $this->helperForm->_forms[0]['sections'][0]['title'] = "Générer un WP"; $this->helperForm->_forms[0]['sections'][0]['actions'] = array( array( 'type' => 'submit', 'class' => 'btn-primary', 'name' => 'uploadWP', 'value' => $this->l('Générer') ), ); $this->helperForm->renderForm(); } }