bebeboutik/modules/ant_wp/AdminAntWp.php
2018-02-20 11:46:34 +01:00

602 lines
32 KiB
PHP

<?php
require_once PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php';
include_once _PS_ROOT_DIR_.'/modules/ant_wp/GenerateWp.php';
require_once _PS_PHPEXCEL_DIR_.'Classes/PHPExcel.php';
require_once _PS_PHPEXCEL_DIR_.'Classes/PHPExcel/IOFactory.php';
ini_set('memory_limit', '8G');
ini_set('max_execution_time', 300);
class AdminAntWp extends AdminTab
{
const DUPLICATED_REFS = 'duplicated_refs';
const DUPLICATED_REFS_AND_EAN = 'duplicated_refs_ean';
protected $_html;
public $module_name;
public $config_tab;
public $controller;
public $helperForm;
public $_object;
public $report;
public function __construct($config_tab = true)
{
parent::__construct();
$this->_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->report = array();
$this->report[self::DUPLICATED_REFS_AND_EAN] = array();
$this->report[self::DUPLICATED_REFS] = array();
// $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 .='<div class="clearfix"></div>';
$this->_addJs();
$this->_html .= $this->helperForm->renderScript();
echo $this->_html;
}
protected function _addJs()
{
$this->helperForm->_js .= '<script type="text/javascript"></script>';
}
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());
$debug = (Tools::getValue('debug') !== false);
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';');
$products = array();
$product_info = array();
$timer_table = array();
$callStartTime = microtime(true);
$refs = array();
$eans = array();
$refs_ean = array();
while($line = fgetcsv($f, 0, ';')) {
if($line[0] == '' && $line[1] == '') {
continue;
}
if($line[0] != '') {
$ean = trim($line[0]);
if(!isset($products[$ean])){
$products[$ean] = array(
'ean' => $ean,
'supplier_ref' => trim(utf8_encode($line[1])),
'name_ha' => trim(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{
//as the product is using a duplicated EAN we add it by ean¤ref
$ean = trim($line[0]);
$ref = trim(utf8_encode($line[1]));
$key_ean_ref = $ean . '¤' . $ref;
//we need to clean the old ean entry to add the ref
if(isset($products[$ean]) && $products[$ean]['supplier_ref'] != ''){
$products[$ean . '¤' . $products[$ean]['supplier_ref']] = $products[$ean];
$refs_ean[] = $ean . '¤' . $products[$ean]['supplier_ref'];
unset($products[$ean]);
$ean_array_key = array_search($ean,$eans,true);
if($ean_array_key !== false){
unset($eans[$ean_array_key]);
}
}
if(!isset($products[$key_ean_ref])) {
$products[$key_ean_ref] = array(
'ean' => trim($line[0]),
'supplier_ref' => $ref,
'name_ha' => trim(utf8_encode($line[2])),
'quantity' => trim($line[3]),
'ppc' => trim((float)$line[4]),
'prix_ha' => trim((float)$line[5]),
'name_attribute_ha' => trim(utf8_encode($line[6]))
);
$refs_ean[] = $key_ean_ref;
}else{
$this->report[self::DUPLICATED_REFS_AND_EAN][] = $key_ean_ref;
}
}
} else {
$ref = trim(utf8_encode($line[1]));
if(!isset($products[$ref])) {
$products[$ref] = array(
'ean' => trim($line[0]),
'supplier_ref' => $ref,
'name_ha' => trim(utf8_encode($line[2])),
'quantity' => trim($line[3]),
'ppc' => trim((float)$line[4]),
'prix_ha' => trim((float)$line[5]),
'name_attribute_ha' => trim(utf8_encode($line[6]))
);
$refs[] = $ref;
}else{
$this->report[self::DUPLICATED_REFS][] = $ref;
}
}
}
$product_info = array();
$product_found = 0;
$ids = array();
$exclude_ids = $this->getBraderieProducts();
$timer_table[] = 'Excluded products gathered at '.(microtime(true)-$callStartTime);
$timer_table[] = 'Found by ean '.count($eans).', by ref'.count($refs).', duplicates ean '. count($refs_ean);
if(count($eans) > 0) {
$sql = '
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`
WHERE id_product NOT IN (' . implode(',', $exclude_ids) . ')
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) . '")
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
';
$result = Db::getInstance()->executeS($sql);
foreach ($result 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'];
}
}
}
$timer_table[] = 'Ean product gathered at '.(microtime(true)-$callStartTime);
if(count($refs)> 0) {
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`
WHERE id_product NOT IN (' . implode(',', $exclude_ids) . ')
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`)
WHERE p.`supplier_reference` IN ("' . implode('","', $refs) . '")
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
') as $row) {
if ($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'];
}
}
}
$timer_table[] = 'Ref product gathered at '.(microtime(true)-$callStartTime);
if(count($refs_ean) > 0) {
foreach($refs_ean as $key) {
$result[] = $key;
$sql = '
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`
WHERE id_product NOT IN (' . implode(',', $exclude_ids) . ')
GROUP BY ean13, 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`)
WHERE p.`ean13` = "' . explode('¤', $key)[0] . '" AND p.`supplier_reference` = "' . explode('¤', $key)[1] . '"
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
';
$result = Db::getInstance()->executeS($sql);
foreach ($result as $row) {
//$key = $row['ean13'] . '-' . $row['supplier_reference'];
if ($row['ean13'] != '' && $row['supplier_reference'] != '' && isset($products[$key])) {
$products[$key] = array_merge($products[$key], $row);
$product_found++;
$ids[] = (int)$row['id_product'];
}
}
}
}
$timer_table[] = 'Ean-Ref product gathered at '.(microtime(true)-$callStartTime);
if(count($eans) > 0) {
foreach (Db::getInstance()->executeS('
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, b.`id_product_attribute`, b.`ean13`, b.`supplier_reference` as at_ref, 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 max(id_product) as maxid, ean13, `supplier_reference`, `id_product_attribute`
FROM `' . _DB_PREFIX_ . 'product_attribute`
WHERE id_product NOT IN (' . implode(',', $exclude_ids) . ')
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`)
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` ac
ON (ac.`id_product_attribute` = b.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al
ON (al.`id_attribute` = ac.`id_attribute` AND al.`id_lang` = 2)
WHERE b.`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++;
if (!in_array((int)$row['id_product'], $ids)) {
$ids[] = (int)$row['id_product'];
}
}
}
}
$timer_table[] = 'Ean product attr gathered at '.(microtime(true)-$callStartTime);
if(count($refs) > 0) {
foreach (Db::getInstance()->executeS('
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`,b.`id_product_attribute`, b.`ean13`, b.`supplier_reference` as at_ref, 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 max(id_product) as maxid, ean13, `supplier_reference`, `id_product_attribute`
FROM `' . _DB_PREFIX_ . 'product_attribute`
WHERE id_product NOT IN (' . implode(',', $exclude_ids) . ')
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_combination` ac
ON (ac.`id_product_attribute` = b.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al
ON (al.`id_attribute` = ac.`id_attribute` AND al.`id_lang` = 2)
WHERE b.`supplier_reference` IN ("' . implode('","', $refs) . '")
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
') as $row) {
if ($row['at_ref'] != '' && isset($products[$row['at_ref']])) {
$products[$row['at_ref']] = array_merge($products[$row['at_ref']], $row);
$product_found++;
if (!in_array((int)$row['id_product'], $ids)) {
$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++;
if (!in_array((int)$row['id_product'], $ids)) {
$ids[] = (int)$row['id_product'];
}
}
}
}
$timer_table[] = 'Ref product attr gathered at '.(microtime(true)-$callStartTime);
if(count($refs_ean) > 0) {
foreach($refs_ean as $key){
$sql = '
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, b.`id_product_attribute`, b.`ean13`, b.`supplier_reference` as at_ref, 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 max(id_product) as maxid, ean13, `supplier_reference`, `id_product_attribute`
FROM `' . _DB_PREFIX_ . 'product_attribute`
WHERE id_product NOT IN (' . implode(',', $exclude_ids) . ')
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`)
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` ac
ON (ac.`id_product_attribute` = b.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al
ON (al.`id_attribute` = ac.`id_attribute` AND al.`id_lang` = 2)
WHERE b.`ean13` = "'.explode('¤',$key)[0].'" AND b.`supplier_reference` = "' . explode('¤',$key)[1] . '"
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
';
$result = Db::getInstance()->executeS($sql);
foreach ($result as $row) {
if ($row[$key] != '' && isset($products[$key])) {
$products[$key] = array_merge($products[$key], $row);
$product_found++;
if (!in_array((int)$row['id_product'], $ids)) {
$ids[] = (int)$row['id_product'];
}
}
}
}
}
$timer_table[] = 'Ean - Ref product attr gathered at '.(microtime(true)-$callStartTime);
$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;
}
} elseif ($row['supplier_reference'] != '' && $row['ean13'] != '' && isset($products[$row['ean13'] . '¤' . $row['supplier_reference']])) {
$key = $row['ean13'] . '¤' . $row['supplier_reference'];
if (!isset($products[$key]['lang'])) {
$products[$key]['lang'] = array();
}
if (!isset($products[$key]['lang'][(int)$row['id_lang']])) {
$products[$key]['lang'][(int)$row['id_lang']] = $row;
}
}
}
$timer_table[] = 'Additional info gathered at '.(microtime(true)-$callStartTime);
foreach (Db::getInstance()->executeS('
SELECT at.`ean13`, at.`supplier_reference` as at_ref, 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;
}
} elseif ($row['at_ref'] != '' && isset($products[$row['at_ref']])) {
if (!isset($products[$row['at_ref']]['lang'])) {
$products[$row['at_ref']]['lang'] = array();
}
if (!isset($products[$row['at_ref']]['lang'][(int)$row['id_lang']])) {
$products[$row['at_ref']]['lang'][(int)$row['id_lang']] = $row;
}
} elseif ($row['supplier_reference'] != '' && $row['ean13'] != '' && isset($products[$row['ean13'] . '¤' . $row['supplier_reference']])) {
$key = $row['ean13'] . '¤' . $row['supplier_reference'];
if (!isset($products[$key]['lang'])) {
$products[$key]['lang'] = array();
}
if (!isset($products[$key]['lang'][(int)$row['id_lang']])) {
$products[$key]['lang'][(int)$row['id_lang']] = $row;
}
}
}
$timer_table[] = 'Additional info (attr) gathered at '.(microtime(true)-$callStartTime);
}
foreach($products as $product_key => $product_values){
$timer_table[] = $product_key . ' - ' . $product_values['id_product'];
}
$params['lines'] = $products;
if(!empty($params['lines'])){
$wp = new GenerateWp();
$wp->excludedProducts = $exclude_ids;
$wp->generate($params, $timer_table, $callStartTime);
$filename = str_replace(' ', '_', $filename);
$wp->objWriter->save(__DIR__ .'/export/'.$filename.'.xlsx');
$timer_table_formatted = implode('<br>', $timer_table);
$duplicated_formatted = '';
if (!empty($this->report[self::DUPLICATED_REFS])) {
$duplicated_formatted = '<hr>Duplications de Références<br><p style="color:darkred">' . implode('<br>', $this->report[self::DUPLICATED_REFS]). '</p>';
}
if (!empty($this->report[self::DUPLICATED_REFS_AND_EAN])) {
$duplicated_formatted .= '<hr>Duplications d\'EANs<br><p style="color:darkred">' . implode('<br>', $this->report[self::DUPLICATED_REFS_AND_EAN]) . '</p>';
}
$debug_output ='';
if($debug){
$debug_output = $duplicated_formatted.'<p style="font-size: 6px"><br>Timers : <br>'.$timer_table_formatted.'</p>';
}
$this->_html .= HelperFormBootstrap::displaySuccess('Génération complète <br><a class="btn btn-primary btn-xs" href="../modules/ant_wp/export/'.$filename.'.xlsx" download="'.$filename.'.xlsx">Télécharger le XLS</a>'.
'<br>Produits trouvés : '.$product_found.'<br>Produits nouveaux : '.$new_products. $debug_output);
} else {
$this->_html .= HelperFormBootstrap::displayErrors($this->l('Veuillez charger un fichier correct !'));
}
}
}
private function _displayForm()
{
global $cookie, $currentIndex;
if (Validate::isLoadedObject($this->_object)){
$trackingTag = $this->_object;
}
$ps_url = ((Configuration::get('PS_SSL_ENABLED') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == '443')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].__PS_BASE_URI__;
$this->helperForm->_forms = array(
array(
'action' => $currentIndex . '&token=' . Tools::getAdminTokenLite('AdminAntWp'),
// 'action' => $ps_url.'modules/ant_wp/GenerateWp.php?url='.$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminAntWp'),
'title' => '<span class="text-rose anticon anticon-table2"></span> '.$this->l('WP'),
'class' => 'form-horizontal',
'class_div' => 'col-md-12',
'sections' => array(
array(
'class' => 'col-md-6',
'inputs' => array(
array(
'type' => 'simpleText',
'name' => 'filename',
'label-class' => 'col-md-12 text-left',
'input-class' => 'col-md-6',
'text-class' => 'input-sm',
'label' => $this->l('Sale name :'),
),
array(
'type' => 'file',
'label' => $this->l('File :'),
'name' => 'csvfile',
'label-class' => 'col-md-12 text-left',
'input-class' => 'col-md-6',
),
array(
'type' => 'checkbox',
'label' => $this->l('Debug'),
'name' => 'debug',
'text' => $this->l('Debug'),
'class-group' => 'col-md-12 text-left',
),
),
'actions' => array(),
'actions-class' => 'text-right',
),
array(
'class' => 'col-md-6 bg-grey',
'title' => '<span class="anticon anticon-info"></span> Informations',
'inputs' => array(),
'info_html' => '
<p>Pour la génération du WP</p>
<p>Veuillez importer un fichier sous format csv<br>
Avec les colonnes suivantes :<br>
</p>
<ul style="list-style:none;">
<li style="font-size:13px;"><i>ean;ref_fournisseur;nom_produit_HA;quantite;PPC;prix_achat;taille_ha</i></li>
</ul>
<p>Les colonnes suivantes et la première ligne du fichier seront ignorées.</p>
<p></p>'
),
),
'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();
}
public function getBraderieProducts()
{
$products = array();
foreach(Db::getInstance()->executeS('
SELECT categ.id_product
FROM '._DB_PREFIX_.'category_product categ
INNER JOIN '._DB_PREFIX_.'category_lang lang ON (categ.id_category=lang.id_category AND lang.id_lang=2 AND lang.name LIKE "%braderie%")'
) as $row){
$products[] = (int)$row['id_product'];
}
return $products;
}
}