Fixing style errors.

This commit is contained in:
stickler-ci 2020-08-12 08:53:24 +00:00
parent 41cbe6db12
commit 1cc673a9c6
2 changed files with 48 additions and 49 deletions

View File

@ -139,13 +139,13 @@ class ProductCombination
public function fetchCombinationPriceLevels($fk_price_level = 0, $useCache = true)
{
// Check cache
if(!empty($this->combination_price_levels) && $useCache){
if((!empty($fk_price_level) && isset($this->combination_price_levels[$fk_price_level])) || empty($fk_price_level)){
if (!empty($this->combination_price_levels) && $useCache){
if ((!empty($fk_price_level) && isset($this->combination_price_levels[$fk_price_level])) || empty($fk_price_level)){
return 1;
}
}
if(!is_array($this->combination_price_levels)
if (!is_array($this->combination_price_levels)
|| empty($fk_price_level) // if fetch an unique level dont erase all already fetched
){
$this->combination_price_levels = array();
@ -178,15 +178,15 @@ class ProductCombination
$staticProductCombinationLevel = new ProductCombinationLevel($this->db);
// Delete all
if(empty($this->combination_price_levels)){
if (empty($this->combination_price_levels)){
return $staticProductCombinationLevel->deleteAllForCombination($this->id);
}
// Clean not needed price levels
if($clean){
if ($clean){
$res = $staticProductCombinationLevel->clean($this->id);
if($res<0){
if ($res<0){
$this->errors[] = 'Fail to clean not needed price levels';
return -1;
}
@ -194,17 +194,17 @@ class ProductCombination
foreach ($this->combination_price_levels as $fk_price_level => $combination_price_level){
$res = $combination_price_level->save();
if($res<1){
if ($res<1){
$this->error = 'save combination price level '.$fk_price_level . ' '.$combination_price_level->error;
$this->errors[] = $this->error;
$errors ++;
}
}
if($errors > 0){
if ($errors > 0){
return $errors*-1;
}
else{
else {
return 1;
}
}
@ -331,7 +331,7 @@ class ProductCombination
if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
$res = $this->saveCombinationPriceLevels();
if($res<0){
if ($res<0){
return -2;
}
}
@ -365,7 +365,7 @@ class ProductCombination
if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
$res = $this->saveCombinationPriceLevels();
if($res<0){
if ($res<0){
return -2;
}
}
@ -392,7 +392,7 @@ class ProductCombination
$comb2val->deleteByFkCombination($this->id);
// remove combination price levels
if(!$this->db->query("DELETE FROM ".MAIN_DB_PREFIX."product_attribute_combination_price_level WHERE fk_product_attribute_combination = ".(int) $this->id)) {
if (!$this->db->query("DELETE FROM ".MAIN_DB_PREFIX."product_attribute_combination_price_level WHERE fk_product_attribute_combination = ".(int) $this->id)) {
$this->db->rollback();
return -1;
}
@ -682,10 +682,10 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1";
$weight_impact = (float) $forced_weightvar; // If false, return 0
//Final price impact
if(!is_array($forced_pricevar)){
if (!is_array($forced_pricevar)){
$price_impact[1] = (float) $forced_pricevar; // If false, return 0
}
else{
else {
$price_impact = $forced_pricevar;
}
@ -732,7 +732,7 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1";
$price_impact[1] += (float) price2num($variations[$currcombattr][$currcombval]['price']);
// Manage Price levels
if($conf->global->PRODUIT_MULTIPRICES){
if ($conf->global->PRODUIT_MULTIPRICES){
for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
{
$price_impact[$i] += (float) price2num($variations[$currcombattr][$currcombval]['price']);
@ -760,16 +760,16 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1";
$newcomb->variation_weight = $weight_impact;
// Init price level
if($conf->global->PRODUIT_MULTIPRICES){
if ($conf->global->PRODUIT_MULTIPRICES){
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++){
$productCombinationLevel = new ProductCombinationLevel($this->db);
$productCombinationLevel->fk_product_attribute_combination = 0;
$productCombinationLevel->fk_price_level = $i;
$productCombinationLevel->variation_price = $price_impact[$i];
if(is_array($price_var_percent)){
if (is_array($price_var_percent)){
$productCombinationLevel->variation_price_percentage = !empty($price_var_percent[$i]) ? $price_var_percent[$i] : 0;
}else{
}else {
$productCombinationLevel->variation_price_percentage = $price_var_percent;
}
@ -1000,11 +1000,11 @@ class ProductCombinationLevel
*/
public function fetch($rowid)
{
$sql = "SELECT rowid, fk_product_attribute_combination, fk_price_level, variation_price, variation_price_percentage FROM " . MAIN_DB_PREFIX . $this->table_element." WHERE rowid = " . (int)$rowid;
$sql = "SELECT rowid, fk_product_attribute_combination, fk_price_level, variation_price, variation_price_percentage FROM " . MAIN_DB_PREFIX . $this->table_element." WHERE rowid = " . (int) $rowid;
$obj = $this->db->getRow($sql);
if($obj){
if ($obj){
return $this->fetchFormObj($obj);
}
@ -1026,7 +1026,7 @@ class ProductCombinationLevel
." FROM ".MAIN_DB_PREFIX.$this->table_element
." WHERE fk_product_attribute_combination = ".intval($fk_product_attribute_combination);
if(!empty($fk_price_level)){
if (!empty($fk_price_level)){
$sql.= ' AND fk_price_level = '.intval($fk_price_level);
}
@ -1039,7 +1039,7 @@ class ProductCombinationLevel
$result = array();
// For more simple usage set level as array key
foreach($combination_price_levels as $k => $row){
foreach ($combination_price_levels as $k => $row){
$productCombinationLevel = new ProductCombinationLevel($this->db);
$productCombinationLevel->fetchFormObj($row);
$result[$row->fk_price_level] = $productCombinationLevel;
@ -1064,7 +1064,7 @@ class ProductCombinationLevel
$this->fk_product_attribute_combination = doubleval($obj->fk_product_attribute_combination);
$this->fk_price_level = intval($obj->fk_price_level);
$this->variation_price = doubleval($obj->variation_price);
$this->variation_price_percentage = (bool)$obj->variation_price_percentage;
$this->variation_price_percentage = (bool) $obj->variation_price_percentage;
return 1;
}
@ -1080,41 +1080,41 @@ class ProductCombinationLevel
$errors = 0;
if(empty($this->fk_product_attribute_combination) || empty($this->fk_price_level)){
if (empty($this->fk_product_attribute_combination) || empty($this->fk_price_level)){
return -1;
}
// check if level exist in DB before add
if(empty($this->id)){
if (empty($this->id)){
$sql = "SELECT rowid id"
." FROM ".MAIN_DB_PREFIX . $this->table_element
." WHERE fk_product_attribute_combination = ".(int) $this->fk_product_attribute_combination
.' AND fk_price_level = '.intval($this->fk_price_level);
$existObj = $this->db->getRow($sql);
if($existObj){
if ($existObj){
$this->id = $existObj->id;
}
}
// Update
if(!empty($this->id)) {
if (!empty($this->id)) {
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET '
. ' variation_price = '.doubleval($this->variation_price)
. ' , variation_price_percentage = '.intval($this->variation_price_percentage)
. ' WHERE rowid = '.intval($this->id);
$res = $this->db->query($sql);
if($res>0){
if ($res>0){
return $this->id;
}
else{
else {
$this->error = $this->db->error();
$this->errors[] = $this->error;
return -1;
}
}
else{
else {
// ADD
$sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("
. " fk_product_attribute_combination, fk_price_level, variation_price, variation_price_percentage"
@ -1126,10 +1126,10 @@ class ProductCombinationLevel
. " )";
$res = $this->db->query($sql);
if($res){
if ($res){
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
}
else{
else {
$this->error = $this->db->error();
$this->errors[] = $this->error;
return -1;
@ -1186,5 +1186,4 @@ class ProductCombinationLevel
return $res ? 1 : -1;
}
}

View File

@ -118,11 +118,11 @@ if ($_POST) {
$price_impact = price2num($price_impact);
// for conf PRODUIT_MULTIPRICES
if($conf->global->PRODUIT_MULTIPRICES) {
if ($conf->global->PRODUIT_MULTIPRICES) {
$level_price_impact = array_map('price2num', $level_price_impact);
$level_price_impact_percent = array_map('price2num', $level_price_impact_percent);
}
else{
else {
$level_price_impact = array(1 => $weight_impact);
$level_price_impact_percent = array(1 => $price_impact_percent);
}
@ -243,19 +243,20 @@ if ($_POST) {
$prodcomb->variation_weight = $weight_impact;
// for conf PRODUIT_MULTIPRICES
if($conf->global->PRODUIT_MULTIPRICES) {
if ($conf->global->PRODUIT_MULTIPRICES) {
$level_price_impact = array_map('price2num', $level_price_impact);
$level_price_impact_percent = array_map(function($a){ return !empty($a);}, $level_price_impact_percent);
$level_price_impact_percent = array_map(function ($a) {
return !empty($a);}, $level_price_impact_percent);
$prodcomb->variation_price = $level_price_impact[1];
$prodcomb->variation_price_percentage = (bool)$level_price_impact_percent[1];
$prodcomb->variation_price_percentage = (bool) $level_price_impact_percent[1];
}
else{
else {
$level_price_impact = array(1 => $weight_impact);
$level_price_impact_percent = array(1 => $price_impact_percent);
}
if($conf->global->PRODUIT_MULTIPRICES){
if ($conf->global->PRODUIT_MULTIPRICES){
$prodcomb->combination_price_levels = array();
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++){
$productCombinationLevel = new ProductCombinationLevel($db);
@ -634,23 +635,22 @@ if (!empty($id) || !empty($ref))
<td><label for="reference"><?php echo $langs->trans('Reference') ?></label></td>
<td><input type="text" id="reference" name="reference" value="<?php echo trim($reference) ?>"></td>
</tr>
<?php if (empty($conf->global->PRODUIT_MULTIPRICES)){ ?>
<?php if (empty($conf->global->PRODUIT_MULTIPRICES)){ ?>
<tr>
<td><label for="price_impact"><?php echo $langs->trans('PriceImpact') ?></label></td>
<td><input type="text" id="price_impact" name="price_impact" value="<?php echo price($price_impact) ?>">
<input type="checkbox" id="price_impact_percent" name="price_impact_percent" <?php echo $price_impact_percent ? ' checked' : '' ?>> <label for="price_impact_percent"><?php echo $langs->trans('PercentageVariation') ?></label>
</td>
</tr>
<?php }
else{
<?php }
else {
$prodcomb->fetchCombinationPriceLevels();
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
{
print '<tr>';
print '<td><label for="level_price_impact_'.$i.'">'.$langs->trans('ImpactOnPriceLevel',$i).'</label>';
if($i===1){
print '<td><label for="level_price_impact_'.$i.'">'.$langs->trans('ImpactOnPriceLevel', $i).'</label>';
if ($i===1){
print ' <a id="apply-price-impact-to-all-level" class="classfortooltip" href="#" title="'.$langs->trans('ApplyToAllPriceImpactLevelHelp').'">('.$langs->trans('ApplyToAllPriceImpactLevel').')</a>';
}
print '</td>';
@ -672,7 +672,7 @@ if (!empty($id) || !empty($ref))
}
if (!empty($conf->global->PRODUIT_MULTIPRICES)){
?>
?>
<script>
$(document).ready(function() {
// Apply level 1 impact to all prices impact levels
@ -690,11 +690,11 @@ if (!empty($id) || !empty($ref))
});
});
</script>
<?php
<?php
}
dol_fiche_end();
?>
?>
<div style="text-align: center">
<input type="submit" name="create" <?php if (!is_array($productCombination2ValuePairs1)) print ' disabled="disabled"'; ?> value="<?php echo $action == 'add' ? $langs->trans('Create') : $langs->trans('Save') ?>" class="button">
&nbsp;