|
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__); |
|
|
|
|
|
|
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__); |
|
|
|
|
|
|
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; |
|
|
|
|
|
|
75
|
|
|
$tmp->fk_product_child = $result->fk_product_child; |
|
|
|
|
|
|
76
|
|
|
$tmp->variation_price = $result->variation_price; |
|
|
|
|
|
|
77
|
|
|
$tmp->variation_price_percentage = $result->variation_price_percentage; |
|
|
|
|
|
|
78
|
|
|
$tmp->variation_weight = $result->variation_weight; |
|
|
|
|
|
|
79
|
|
|
$tmp->variation_ref_ext = $result->variation_ref_ext; |
|
|
|
|
|
|
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__); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function update2(User $user) |
|
104
|
|
|
{ |
|
105
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function delete2(User $user) |
|
109
|
|
|
{ |
|
110
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function deleteByFkProductParent($user, $fk_product_parent) |
|
114
|
|
|
{ |
|
115
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function updateProperties(Product $parent, User $user) |
|
119
|
|
|
{ |
|
120
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function fetchByProductCombination2ValuePairs($prodid, array $features) |
|
124
|
|
|
{ |
|
125
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function getUniqueAttributesAndValuesByFkProductParent($productid) |
|
129
|
|
|
{ |
|
130
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
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__); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function copyAll(User $user, $origProductId, Product $destProduct) |
|
139
|
|
|
{ |
|
140
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getCombinationLabel($prod_child) |
|
144
|
|
|
{ |
|
145
|
|
|
die(__METHOD__ . ' of ' . __CLASS__); |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.