Merge branch 'ticket-7748'

This commit is contained in:
Marion Muszynski 2016-03-23 13:25:33 +01:00
commit 058aae7d32
2 changed files with 59 additions and 11 deletions

View File

@ -47,7 +47,7 @@ class AdminLabelGenerate extends AdminTab {
}
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);
$barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference);
Db::getInstance()->execute('
UPDATE
`'._DB_PREFIX_.'product_attribute`
@ -78,7 +78,7 @@ class AdminLabelGenerate extends AdminTab {
}
if ($quantity>0) {
$ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference);
$barcode->assocProduct($product->id, NULL, $quantity);
$barcode->assocProduct($product->id, NULL, $quantity, $product->reference);
Db::getInstance()->execute('
UPDATE
`'._DB_PREFIX_.'product`

View File

@ -54,7 +54,7 @@ class GenerateBarcode {
return $number;
}
public function assocProduct($id_product, $id_product_attribute = NULL, $quantity) {
public function assocProduct($id_product, $id_product_attribute = NULL, $quantity, $ref) {
global $cookie;
$p = Db::getInstance()->getRow('
SELECT pl.name
@ -71,18 +71,20 @@ class GenerateBarcode {
for ($i=1; $i <= $quantity; $i++) {
$this->products[] = array(
'key' => ($id_product.'-'.$id_product_attribute),
'label' => ($name_combination . ' ' . $p['name'])
'label' => ($name_combination . ' ' . $p['name']),
'ref' => $ref
);
}
} else {
for ($i=1; $i <= $quantity; $i++) {
$this->products[] = array(
'key' => $id_product.'-0',
'label' => $p['name']
'label' => $p['name'],
'ref' => $ref
);
}
}
$this->products[] = array();
//$this->products[] = array();
}
public function printPDF() {
@ -92,21 +94,22 @@ class GenerateBarcode {
/*for ($i=0; $i < 30; $i++) {
$this->products[$i] = array(
'key' => "125415-322",
'label' => "03 mois (62 cm)- Lot de 2 bodies Ri"
'label' => "03 mois (62 cm)- Lot de 2 bodies Ri",
"ref" => "FIX-06-86763"
);
}
$this->products[count($this->products)] = array();
for ($i=31; $i < 80; $i++) {
$this->products[$i] = array(
'key' => "125416-332",
'label' => "03 mois (62 cm)- Ensemble grenouill"
'label' => "03 mois (62 cm)- Ensemble grenouill",
"ref" => "FIX-04-86763"
);
}
$this->products[count($this->products)] = array();*/
}*/
if (empty($this->products)) {
die('Tous les produits ont déjà un EAN');
}
$this->products = $this->_sortProducts($this->products, 'ref');
ob_start();
$pdf = new FPDF('P', 'mm', 'A4');
@ -170,4 +173,49 @@ class GenerateBarcode {
}
}
private function _sortProducts($array = array(), $field, $order=SORT_ASC) {
$new_array = array();
$sortable_array = array();
$products = array();
if (!empty($array)) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $field) {
$sortable_array[$k] = $v2;
}
}
} elseif (!empty($v)) {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[] = $array[$k];
}
$ref = '';
foreach ($new_array as $k => $v) {
if ($ref !== $v['ref'] && !empty($ref)) {
$products[] = array();
$products[] = $v;
$ref = $v['ref'];
continue;
}
$products[] = $v;
$ref = $v['ref'];
}
}
return $products;
}
}