getProducts(); $ean_generate = ''; $products_generate = array(); $barcode = new GenerateBarcode(); $barcode->id_sale = $sale->id; $barcode->createFolder($barcode->id_sale); 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'])) { $result_quantities = Db::getInstance()->executeS(' SELECT od.`product_quantity`,od.`product_quantity_reinjected` FROM '._DB_PREFIX_.'order_detail od WHERE od.`product_id` = ' . (int)$combination['id_product'] .' AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'] ); $quantity = 0; foreach ($result_quantities as $od) { $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); } if ($quantity>0) { $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference); $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product_attribute` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id .' AND `id_product_attribute` = ' . (int)$combination['id_product_attribute'] ); } } } } else { if (empty($product->ean13)) { $result_quantities = Db::getInstance()->executeS(' SELECT od.`product_quantity`,od.`product_quantity_reinjected` FROM '._DB_PREFIX_.'order_detail od WHERE od.`product_id` = ' . (int)$product->id ); $quantity = 0; foreach ($result_quantities as $od) { $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); } if ($quantity>0) { $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference); $barcode->assocProduct($product->id, NULL, $quantity); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id ); } } } } if (!empty($ean_generate)) { $barcode->printPDF(); $this->_html .= '
Génération terminée : Télécharger le PDF
'; } else { $this->_html .= 'Tous les produits de la vente ont déjà des EANS
'; if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf')) { $this->_html .= 'Dernières étiquettes générées : Télécharger le PDF
'; } } } } $this->_html .= '