diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 006c8710770..3ea695504da 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -500,52 +500,6 @@ if (empty($reshook)) { // If price has changed, we update it if (!array_key_exists($key, $object->multiprices) || $object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type'] || $object->multiprices_tva_tx[$key] != $newvattx) { $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code'], $val['price_label']); - if ($res > 0) { - $extralabels = $extrafields->fetch_name_optionals_label("product"); - if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($extralabels)) { - // Default price - $extrafield_values = $extrafields->getOptionalsFromPost("product"); - foreach ($extrafield_values as $efkey => $value) { - $object->array_options[$efkey] = $value; - } - $result = $object->insertExtraFields(); - if ($result < 0) { - $error++; - } - } elseif ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($extralabels)) { - $price_extralabels = $extrafields->fetch_name_optionals_label("product_price"); - $sql = "SELECT rowid"; - $sql .= " FROM ".$object->db->prefix()."product_price"; - $sql .= " WHERE entity IN (".getEntity('productprice').")"; - $sql .= " AND price_level=".((int) $key); // $i - $sql .= " AND fk_product = ".((int) $object->id); - $sql .= " ORDER BY date_price DESC, rowid DESC"; - $sql .= " LIMIT 1"; - $resql = $object->db->query($sql); - if ($resql) { - $lineid = $object->db->fetch_object($resql); - $db->free($resql); - } - if (!empty($lineid->rowid)) { - if (!empty($price_extralabels) && is_array($price_extralabels)) { - foreach ($price_extralabels as $code => $label) { - $code_array = GETPOST($code, 'array'); - $object->array_options['options_'.$code] = $code_array[$key]; - } - // We need to force table to update product_price and not product extrafields - $object->id = $lineid->rowid; - $object->table_element = 'product_price'; - $result = $object->insertExtraFields(); - } - // Back to product table - $object->id = $id; - $object->table_element = 'product'; - if ($result < 0) { - $error++; - } - } - } - } } else { $res = 0; } @@ -555,6 +509,41 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); break; } + + // Update level price extrafields + $price_extralabels = $extrafields->fetch_name_optionals_label("product_price"); + if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($price_extralabels)) { + $sql = "SELECT rowid"; + $sql .= " FROM ".$object->db->prefix()."product_price"; + $sql .= " WHERE entity IN (".getEntity('productprice').")"; + $sql .= " AND price_level=".((int) $key); // $i + $sql .= " AND fk_product = ".((int) $object->id); + $sql .= " ORDER BY date_price DESC, rowid DESC"; + $sql .= " LIMIT 1"; + $resql = $object->db->query($sql); + if ($resql) { + $lineid = $object->db->fetch_object($resql); + $db->free($resql); + } + if (!empty($lineid->rowid)) { + if (!empty($price_extralabels) && is_array($price_extralabels)) { + foreach ($price_extralabels as $code => $label) { + $code_array = GETPOST($code, 'array'); + $object->array_options['options_'.$code] = $code_array[$key]; + } + // We need to force table to update product_price and not product extrafields + $object->id = $lineid->rowid; + $object->table_element = 'product_price'; + $result = $object->insertExtraFields(); + } + // Back to product table + $object->id = $id; + $object->table_element = 'product'; + if ($result < 0) { + $error++; + } + } + } } } @@ -1515,39 +1504,6 @@ if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUS } print ''; } - - // Extrafields - $extrafields->fetch_name_optionals_label("product"); - $extralabels = !empty($extrafields->attributes["product"]['label']) ? $extrafields->attributes["product"]['label'] : []; - $extrafield_values = $extrafields->getOptionalsFromPost("product"); - $sql = "SELECT"; - $sql .= " fk_object"; - foreach ($extralabels as $key => $value) { - $sql .= ", ".$key; - } - $sql .= " FROM ".MAIN_DB_PREFIX."product_extrafields"; - $sql .= " WHERE fk_object = ".((int) $object->id); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - foreach ($extralabels as $key => $value) { - if (!empty($extrafields->attributes["product"]['list'][$key]) && ($extrafields->attributes["product"]['list'][$key] == 1 || $extrafields->attributes["product"]['list'][$key] == 3 || ($action == "edit_price" && $extrafields->attributes["product"]['list'][$key] == 4))) { - if (!empty($extrafields->attributes["product"]['langfile'][$key])) { - $langs->load($extrafields->attributes["product"]['langfile'][$key]); - } - - print '