Passed
Push — MODEL_LIB_240928 ( 9bf6d2...bd3167 )
by Rafael
49:03
created

ProductAttributeCombination::updateProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/* Copyright (C) 2024       Rafael San José         <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Dolibarr\Code\Variants\Model;
20
21
use Dolibarr\Code\User\Classes\User;
22
use Dolibarr\Core\Base\Model;
23
24
class ProductAttributeCombination extends Model
25
{
26
    public $table = 'product_attribute_combination';
27
28
    public function fetch($rowid)
29
    {
30
        return static::firstWhere('rowid', $rowid);
31
    }
32
33
    public function saveCombinationPriceLevels($clean = 1)
34
    {
35
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
36
    }
37
38
    public function fetchByFkProductChild($productid, $donotloadpricelevel = 0)
39
    {
40
        $result = static::firstWhere('fk_product_child', $productid);
41
        if (empty($donotloadpricelevel) && getDolGlobalString('PRODUIT_MULTIPRICES')) {
42
            $this->fetchCombinationPriceLevels();
43
        }
44
        return $result;
45
    }
46
47
    public function fetchCombinationPriceLevels($fk_price_level = 0, $useCache = true)
48
    {
49
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
50
    }
51
52
    public function fetchAllByFkProductParent($fk_product_parent, $sort_by_ref = false)
53
    {
54
        $entities = getEntity('product');
55
        if (!is_array($entities)) {
56
            $entities = [$entities];
57
        }
58
59
        $query = ProductAttributeCombination::where('fk_product_parent', $fk_product_parent)
60
            ->whereIn('product_attribute_combination.entity', $entities);
61
62
        if ($sort_by_ref) {
63
            $query->leftJoin('product', 'product.rowid', '=', 'product_attribute_combination.fk_product_child')
64
                ->orderBy('product.ref', 'ASC');
65
        }
66
67
        $results = $query->get();
68
69
        $return = [];
70
71
        foreach ($results as $result) {
72
            $tmp = new ProductAttributeCombination();
73
            $tmp->id = $result->rowid;
74
            $tmp->fk_product_parent = $result->fk_product_parent;
0 ignored issues
show
Bug introduced by
The property fk_product_parent does not seem to exist on Dolibarr\Code\Variants\M...uctAttributeCombination. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
75
            $tmp->fk_product_child = $result->fk_product_child;
0 ignored issues
show
Bug introduced by
The property fk_product_child does not seem to exist on Dolibarr\Code\Variants\M...uctAttributeCombination. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
76
            $tmp->variation_price = $result->variation_price;
0 ignored issues
show
Bug introduced by
The property variation_price does not seem to exist on Dolibarr\Code\Variants\M...uctAttributeCombination. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
77
            $tmp->variation_price_percentage = $result->variation_price_percentage;
0 ignored issues
show
Bug introduced by
The property variation_price_percentage does not seem to exist on Dolibarr\Code\Variants\M...uctAttributeCombination. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
78
            $tmp->variation_weight = $result->variation_weight;
0 ignored issues
show
Bug introduced by
The property variation_weight does not seem to exist on Dolibarr\Code\Variants\M...uctAttributeCombination. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
79
            $tmp->variation_ref_ext = $result->variation_ref_ext;
0 ignored issues
show
Bug introduced by
The property variation_ref_ext does not seem to exist on Dolibarr\Code\Variants\M...uctAttributeCombination. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
80
81
            if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
82
                $tmp->fetchCombinationPriceLevels();
83
            }
84
85
            $return[] = $tmp;
86
        }
87
88
        return $return;
89
    }
90
91
    public function countNbOfCombinationForFkProductParent($fk_product_parent)
92
    {
93
        return static::where('fk_product_parent', $fk_product_parent)
94
            ->where('entity', getEntity('product'))
95
            ->count();
96
    }
97
98
    public function create($user)
99
    {
100
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
101
    }
102
103
    public function update2(User $user)
104
    {
105
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
106
    }
107
108
    public function delete2(User $user)
109
    {
110
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
111
    }
112
113
    public function deleteByFkProductParent($user, $fk_product_parent)
114
    {
115
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
116
    }
117
118
    public function updateProperties(Product $parent, User $user)
119
    {
120
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
121
    }
122
123
    public function fetchByProductCombination2ValuePairs($prodid, array $features)
124
    {
125
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
126
    }
127
128
    public function getUniqueAttributesAndValuesByFkProductParent($productid)
129
    {
130
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
131
    }
132
133
    public function createProductCombination(User $user, Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false, $forced_refvar = false, $ref_ext = '')
134
    {
135
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
136
    }
137
138
    public function copyAll(User $user, $origProductId, Product $destProduct)
139
    {
140
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
141
    }
142
143
    public function getCombinationLabel($prod_child)
144
    {
145
        die(__METHOD__ . ' of ' . __CLASS__);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
146
    }
147
}
148