From b027db49b505c4f85206ec763496c9bc47cdb607 Mon Sep 17 00:00:00 2001 From: Jean Date: Sat, 23 Oct 2021 22:21:50 +0200 Subject: [PATCH 1/2] FIX #18934 Non-registration in the extrafieldsline database for deliveries --- htdocs/delivery/card.php | 13 ++++++++---- htdocs/delivery/class/delivery.class.php | 27 ++++++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index a845b7aff95..67a80084710 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -114,7 +114,7 @@ if ($action == 'add') { $idl = "idl".$i; $qtytouse = price2num(GETPOST($qty)); if ($qtytouse > 0) { - $object->addline(GETPOST($idl), price2num($qtytouse)); + $object->addline(GETPOST($idl), price2num($qtytouse), $arrayoptions); } } @@ -603,7 +603,7 @@ if ($action == 'create') { // Create. Seems to no be used print ""; // Display lines extrafields - if (!empty($extrafields)) { + //if (!empty($extrafields)) { $colspan = 2; $mode = ($object->statut == 0) ? 'edit' : 'view'; @@ -618,8 +618,13 @@ if ($action == 'create') { // Create. Seems to no be used $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options); } - print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), $i); - } + else { + $srcLine = new DeliveryLine($db); + $extrafields->fetch_name_optionals_label($srcLine->table_element); + + } + print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), ''); + //} } $i++; diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index 019187fca28..775cd96e2c3 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -211,7 +211,7 @@ class Delivery extends CommonObject $origin_id = $this->lines[$i]->commande_ligne_id; // For backward compatibility } - if (!$this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description)) { + if (!$this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description, $this->lines[$i]->array_options)) { $error++; } } @@ -264,7 +264,7 @@ class Delivery extends CommonObject * @param string $description Description * @return int <0 if KO, >0 if OK */ - public function create_line($origin_id, $qty, $fk_product, $description) + public function create_line($origin_id, $qty, $fk_product, $description, $array_options = 0) { // phpcs:enable $error = 0; @@ -282,6 +282,15 @@ class Delivery extends CommonObject if (!$this->db->query($sql)) { $error++; } + + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."deliverydet"); + + if (is_array($array_options) && count($array_options) > 0) { + $line = new DeliveryLine($this->db); + $line->id = $id; + $line->array_options = $array_options; + $result = $line->insertExtraFields(); + } if ($error == 0) { return 1; @@ -531,7 +540,9 @@ class Delivery extends CommonObject $line->description = $expedition->lines[$i]->description; $line->qty = $expedition->lines[$i]->qty_shipped; $line->fk_product = $expedition->lines[$i]->fk_product; - + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($expedition->lines[$i]->array_options) && count($expedition->lines[$i]->array_options) > 0) { // For avoid conflicts if trigger used + $line->array_options = $expedition->lines[$i]->array_options; + } $this->lines[$i] = $line; } @@ -593,14 +604,18 @@ class Delivery extends CommonObject * @param int $qty Qty * @return void */ - public function addline($origin_id, $qty) + public function addline($origin_id, $qty, $array_options = 0) { - $num = count($this->lines); + global $conf; + + $num = count($this->lines); $line = new DeliveryLine($this->db); $line->origin_id = $origin_id; $line->qty = $qty; - + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used + $line->array_options = $array_options; + } $this->lines[$num] = $line; } From 53e9da4748bcf9a8493ad0a30a3cf5a471a11686 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 23 Oct 2021 20:37:07 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/delivery/card.php | 22 ++++++++++------------ htdocs/delivery/class/delivery.class.php | 18 +++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index 67a80084710..ee41019d218 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -609,20 +609,18 @@ if ($action == 'create') { // Create. Seems to no be used $object->lines[$i]->fetch_optionals(); - if ($action == 'create_delivery') { - $srcLine = new ExpeditionLigne($db); + if ($action == 'create_delivery') { + $srcLine = new ExpeditionLigne($db); + $extrafields->fetch_name_optionals_label($srcLine->table_element); + $srcLine->id = $expedition->lines[$i]->id; + $srcLine->fetch_optionals(); + + $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options); + } else { + $srcLine = new DeliveryLine($db); $extrafields->fetch_name_optionals_label($srcLine->table_element); - $srcLine->id = $expedition->lines[$i]->id; - $srcLine->fetch_optionals(); - - $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options); - } - else { - $srcLine = new DeliveryLine($db); - $extrafields->fetch_name_optionals_label($srcLine->table_element); - - } + } print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), ''); //} } diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index 775cd96e2c3..dee6d021e17 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -282,14 +282,14 @@ class Delivery extends CommonObject if (!$this->db->query($sql)) { $error++; } - + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."deliverydet"); - + if (is_array($array_options) && count($array_options) > 0) { - $line = new DeliveryLine($this->db); - $line->id = $id; - $line->array_options = $array_options; - $result = $line->insertExtraFields(); + $line = new DeliveryLine($this->db); + $line->id = $id; + $line->array_options = $array_options; + $result = $line->insertExtraFields(); } if ($error == 0) { @@ -541,7 +541,7 @@ class Delivery extends CommonObject $line->qty = $expedition->lines[$i]->qty_shipped; $line->fk_product = $expedition->lines[$i]->fk_product; if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($expedition->lines[$i]->array_options) && count($expedition->lines[$i]->array_options) > 0) { // For avoid conflicts if trigger used - $line->array_options = $expedition->lines[$i]->array_options; + $line->array_options = $expedition->lines[$i]->array_options; } $this->lines[$i] = $line; } @@ -608,13 +608,13 @@ class Delivery extends CommonObject { global $conf; - $num = count($this->lines); + $num = count($this->lines); $line = new DeliveryLine($this->db); $line->origin_id = $origin_id; $line->qty = $qty; if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used - $line->array_options = $array_options; + $line->array_options = $array_options; } $this->lines[$num] = $line; }