From e2eb4e9168fc61de192f96122d1ad87541b8cee2 Mon Sep 17 00:00:00 2001 From: thibdrev Date: Thu, 25 Apr 2024 10:33:47 +0200 Subject: [PATCH 1/2] qual: clean code (#29454) * qual: clean code * Update combinations.php * Update combinations.php --------- Co-authored-by: Laurent Destailleur --- htdocs/variants/combinations.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index c54e606fa65..719b18394d6 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -32,13 +32,11 @@ $langs->loadLangs(array("products", "other")); $id = GETPOSTINT('id'); $valueid = GETPOSTINT('valueid'); $ref = GETPOST('ref', 'alpha'); -$weight_impact = price2num(GETPOST('weight_impact', 'alpha'), 2); + +$weight_impact = GETPOSTFLOAT('weight_impact', 2); $price_impact_percent = (bool) GETPOST('price_impact_percent'); -if ($price_impact_percent) { - $price_impact = price2num(GETPOST('price_impact', 'alpha'), 2); -} else { - $price_impact = price2num(GETPOST('price_impact', 'alpha'), 'MU'); -} +$price_impact = $price_impact_percent ? GETPOSTFLOAT('price_impact', 2) : GETPOSTFLOAT('price_impact', 'MU'); + $level_price_impact = GETPOST('level_price_impact', 'array'); $level_price_impact_percent = GETPOST('level_price_impact_percent', 'array'); @@ -687,10 +685,9 @@ if (!empty($id) || !empty($ref)) {
$val) { - $result1 = $prodattr->fetch($val->fk_prod_attr); - $result2 = $prodattr_val->fetch($val->fk_prod_attr_val); - //print 'rr'.$result1.' '.$result2; + foreach ($productCombination2ValuePairs1 as $pc2v) { + $result1 = $prodattr->fetch($pc2v->fk_prod_attr); + $result2 = $prodattr_val->fetch($pc2v->fk_prod_attr_val); if ($result1 > 0 && $result2 > 0) { print $prodattr->label.' : '.$prodattr_val->value.'
'; // TODO Add delete link From 86b219a17fd5c6d37eae0ba619b82df24ef8427f Mon Sep 17 00:00:00 2001 From: thibdrev Date: Thu, 25 Apr 2024 10:40:05 +0200 Subject: [PATCH 2/2] qual: clean code (#29457) Co-authored-by: Laurent Destailleur --- htdocs/variants/combinations.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 719b18394d6..b0d95a83337 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -56,8 +56,8 @@ $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); // Security check -$fieldvalue = (!empty($id) ? $id : $ref); -$fieldtype = (!empty($ref) ? 'ref' : 'rowid'); +$fieldvalue = $id ?: $ref; +$fieldtype = !empty($ref) ? 'ref' : 'rowid'; $prodstatic = new Product($db); $prodattr = new ProductAttribute($db); @@ -68,8 +68,8 @@ if ($id > 0 || $ref) { $object->fetch($id, $ref); } -$selectedvariant = !empty($_SESSION['addvariant_'.$object->id]) ? $_SESSION['addvariant_'.$object->id] : array(); -$selected = ""; +$selectedvariant = $_SESSION['addvariant_'.$object->id] ?: array(); +$selected = ''; // Security check if (!isModEnabled('variants')) { accessforbidden('Module not enabled'); @@ -79,10 +79,10 @@ if ($user->socid > 0) { // Protection if external user } if ($object->id > 0) { - if ($object->type == $object::TYPE_PRODUCT) { + if ($object->type == Product::TYPE_PRODUCT) { restrictedArea($user, 'produit', $object->id, 'product&product', '', ''); } - if ($object->type == $object::TYPE_SERVICE) { + if ($object->type == Product::TYPE_SERVICE) { restrictedArea($user, 'service', $object->id, 'product&product', '', ''); } } else {