From 9dd605bd8a2d54fe435fe4b0df070cbe1c7e5a0c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 May 2014 11:54:48 +0200 Subject: [PATCH] Simplify and comment code --- htdocs/product/admin/product.php | 49 ++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 4d5cc811e85..5aa65d69b5a 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -44,11 +44,12 @@ $value = GETPOST('value','alpha'); // Pricing Rules $select_pricing_rules=array( -'PRODUCT_PRICE_UNIQ'=>$langs->trans('PriceCatalogue'), -'PRODUIT_MULTIPRICES'=>$langs->trans('MultiPricesAbility'), -'PRODUIT_CUSTOMER_PRICES'=>$langs->trans('PriceByCustomer') +'PRODUCT_PRICE_UNIQ'=>$langs->trans('PriceCatalogue'), // Unique price +'PRODUIT_MULTIPRICES'=>$langs->trans('MultiPricesAbility'), // Several prices according to a customer level +'PRODUIT_CUSTOMER_PRICES'=>$langs->trans('PriceByCustomer') // Different price for each customer ); -if ($conf->global->MAIN_FEATURES_LEVEL==2) { +if ($conf->global->MAIN_FEATURES_LEVEL==2) +{ $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY'] = $langs->trans('PriceByQuantity'); $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY&PRODUIT_MULTIPRICES'] = $langs->trans('MultiPricesAbility') . '+' . $langs->trans('PriceByQuantity'); } @@ -103,33 +104,37 @@ if ($action == 'nbprod') { $res = dolibarr_set_const($db, "PRODUIT_LIMIT_SIZE", $value,'chaine',0,'',$conf->entity); } -else if ($action == 'multiprix_num') +else if ($action == 'PRODUIT_MULTIPRICES_LIMIT') { $res = dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", $value,'chaine',0,'',$conf->entity); } if ($action == 'pricingrule') { $princingrules = GETPOST('princingrule','alpha'); - foreach ($select_pricing_rules as $rule=>$label) { - - if ($rule==$princingrules) { - if ( $princingrules =='PRODUCT_PRICE_UNIQ') { - $res = dolibarr_set_const($db, 'PRODUIT_MULTIPRICES', 0,'chaine',0,'',$conf->entity); - $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES_BY_QTY', 0,'chaine',0,'',$conf->entity); - $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES', 0,'chaine',0,'',$conf->entity); - } else { + foreach ($select_pricing_rules as $rule=>$label) // Loop on each possible mode + { + if ($rule == $princingrules) // We are on selected rule, we enable it + { + if ($princingrules == 'PRODUCT_PRICE_UNIQ') // For this case, we disable entries manually + { + $res = dolibarr_set_const($db, 'PRODUIT_MULTIPRICES', 0, 'chaine', 0, '', $conf->entity); + $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES_BY_QTY', 0, 'chaine', 0, '', $conf->entity); + $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES', 0, 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, 'PRODUCT_PRICE_UNIQ', 1, 'chaine', 0, '', $conf->entity); + } + else + { $multirule=explode('&',$princingrules); - if (is_array($multirule) && count($multirule)>0) { - foreach($multirule as $rulesselected) { - $res = dolibarr_set_const($db, $rulesselected, 1,'chaine',0,'',$conf->entity); - } - } else { - $res = dolibarr_set_const($db, $rule, 1,'chaine',0,'',$conf->entity); + foreach($multirule as $rulesselected) + { + $res = dolibarr_set_const($db, $rulesselected, 1, 'chaine', 0, '', $conf->entity); } } - } else { + } + else // We clear this mode + { if (strpos($rule,'&')===false) { - $res = dolibarr_set_const($db, $rule, 0,'chaine',0,'',$conf->entity); + $res = dolibarr_set_const($db, $rule, 0, 'chaine', 0, '', $conf->entity); } } @@ -337,7 +342,7 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) $var=!$var; print '
'; print ''; - print ''; + print ''; print ''; print ''.$langs->trans("MultiPricesNumPrices").''; print '';