From d0cb9bc4edb72d09491aeb30f1846991ee7efd25 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 1 Dec 2020 02:34:24 +0100 Subject: [PATCH] Debug price_rule page. --- htdocs/product/admin/dynamic_prices.php | 4 +- htdocs/product/admin/price_rules.php | 52 ++++++++++++------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/htdocs/product/admin/dynamic_prices.php b/htdocs/product/admin/dynamic_prices.php index 228157a7be8..bae21309022 100644 --- a/htdocs/product/admin/dynamic_prices.php +++ b/htdocs/product/admin/dynamic_prices.php @@ -178,7 +178,7 @@ if ($action != 'create_updater' && $action != 'edit_updater') print ''.$entry->code.''; print ''.$entry->description.''; print ''.price($entry->value).''; - print 'id.'">'.img_edit().'  '; + print 'id.'">'.img_edit().'  '; print 'id.'">'.img_delete().''; print ''; } @@ -269,7 +269,7 @@ if ($action != 'create_variable' && $action != 'edit_variable') print ''.$entry->parameters.''; print ''.$entry->update_interval.''; print ''.$entry->getLastUpdated().''; - print 'id.'">'.img_edit().'  '; + print 'id.'">'.img_edit().'  '; print 'id.'">'.img_delete().''; print ''; } diff --git a/htdocs/product/admin/price_rules.php b/htdocs/product/admin/price_rules.php index 5b5743a742b..a38245d32c7 100644 --- a/htdocs/product/admin/price_rules.php +++ b/htdocs/product/admin/price_rules.php @@ -15,8 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Page to set how to autocalculate price for each level when option - * PRODUCT_MULTIPRICE is on. + * Page to set how to autocalculate price for each level when option PRODUCT_MULTIPRICE is on. + * This page is a tab in the setup of module Product if option PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL is set. */ require '../../main.inc.php'; @@ -32,6 +32,8 @@ $action = GETPOST('action', 'aZ09'); if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) accessforbidden(); +$error = 0; + /** * Actions @@ -55,6 +57,7 @@ if ($action == 'update') { $i_var_percent = 0; + // Set $i_var_percent, the percent of price for level compared to an other level if ($i != 1) { $i_var_percent = (float) price2num($var_percent[$i]); } @@ -67,15 +70,12 @@ if ($action == 'update') { $check2 = $i_var_min_percent; } else { $check1 = $i_fk_level >= 1 && $i_fk_level <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; - $check2 = $i_var_percent && $i_var_min_percent; + $check2 = $i_var_percent && ($i_var_min_percent || (string) $i_var_min_percent === '0'); } - if (!$check1 || !$check2) { + if (empty($i_var_percent) && empty($i_var_min_percent)) { //If the level is between range but percent fields are empty, then we ensure it does not exist in DB - if ($check1) { - $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".((int) $i)); - } - + $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".((int) $i)); continue; } @@ -89,11 +89,14 @@ if ($action == 'update') { if (!$db->query($sql)) { setEventMessages($langs->trans('ErrorSavingChanges'), null, 'errors'); + $error++; } } } - setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + if (!$error) { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + } } @@ -133,32 +136,19 @@ print ''; print ''; $head = product_admin_prepare_head(); -print dol_get_fiche_head($head, 'generator', $tab, 0, 'product'); +print dol_get_fiche_head($head, 'generator', $tab, -1, 'product'); -print $langs->trans("MultiPriceRuleDesc").'

'; +print ''.$langs->trans("MultiPriceRuleDesc").'

'; -print load_fiche_titre($langs->trans('MultipriceRules'), '', ''); - -//Array that contains the number of prices available +// Array that contains the number of prices available $price_options = array(); for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $price_options[$i] = $langs->trans('SellingPrice').' '.$i; } - -$genPriceOptions = function ($level) use ($price_options) { - - $return = array(); - - for ($i = 1; $i < $level; $i++) { - $return[$i] = $price_options[$i]; - } - - return $return; -}; ?> - +
@@ -181,7 +171,15 @@ $genPriceOptions = function ($level) use ($price_options) {
trans('PriceLevel') ?> trans('Price') ?> - trans('PercentVariationOver', Form::selectarray("fk_level[$i]", $genPriceOptions($i), (isset($rules[$i]) ? $rules[$i]->fk_level : null))) ?> + trans('PercentVariationOver', '{s1}'); + $texttoshow = str_replace('{s1}', Form::selectarray("fk_level[$i]", $return, (isset($rules[$i]) ? $rules[$i]->fk_level : null)), $texttoshow); + print $texttoshow; + ?>