52 $this->rights_class =
'variants';
56 $this->family =
"products";
58 $this->module_position =
'50';
60 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
62 $this->
description =
'Allows creating products variant based on new attributes';
66 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
70 $this->picto =
'product';
73 $this->module_parts = array();
77 $this->dirs = array();
80 $this->config_page_url = array(
'admin.php@variants');
83 $this->hidden =
false;
84 $this->depends = array(
'modProduct');
85 $this->requiredby = array();
86 $this->conflictwith = array();
87 $this->phpmin = array(7, 0);
88 $this->need_dolibarr_version = array(3, 0);
89 $this->langfiles = array(
"products");
92 $this->
const = array();
100 if (!isset(
$conf->variants->enabled)) {
102 $conf->variants->enabled = 0;
104 $this->dictionaries = array();
108 $this->boxes = array();
111 $this->rights = array();
114 $this->rights[$r][0] = $this->numero + 1;
115 $this->rights[$r][1] =
'Read attributes of variants';
116 $this->rights[$r][4] =
'read';
118 $this->rights[$r][0] = $this->numero + 2;
119 $this->rights[$r][1] =
'Create/Update attributes of variants';
120 $this->rights[$r][4] =
'write';
122 $this->rights[$r][0] = $this->numero + 3;
123 $this->rights[$r][1] =
'Delete attributes of variants';
124 $this->rights[$r][4] =
'delete';
138 $this->import_code[$r] = $this->rights_class.
'_attribute';
139 $this->import_label[$r] =
"VariantAttributes";
140 $this->import_icon[$r] = $this->picto;
141 $this->import_entities_array[$r] = array();
142 $this->import_tables_array[$r] = array(
'pa' => MAIN_DB_PREFIX.
'product_attribute',
'extra' => MAIN_DB_PREFIX.
'product_attribute_extrafields');
143 $this->import_fields_array[$r] = array(
144 'pa.ref' =>
"VariantAttributeRef*",
145 'pa.label' =>
"VariantAttributeLabel*",
146 'pa.ref_ext' =>
"VariantAttributeRefExt",
147 'pa.position' =>
"VariantAttributeRank"
150 $keyforselect =
'product_attribute';
151 $keyforelement =
'productattribute';
152 $keyforaliasextra =
'extra';
153 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
154 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'product_attribute');
155 $this->import_examplevalues_array[$r] = array(
157 'pa.label' =>
"Color",
159 'pa.position' =>
"10"
161 $this->import_convertvalue_array[$r] = array(
162 'pa.position' => array(
'rule' =>
'zeroifnull')
164 $this->import_updatekeys_array[$r] = array(
'pa.ref' =>
'VariantAttributeRef');
168 $this->import_code[$r] = $this->rights_class.
'_value';
169 $this->import_label[$r] =
"VariantAttributeValues";
170 $this->import_icon[$r] = $this->picto;
171 $this->import_entities_array[$r] = array();
172 $this->import_tables_array[$r] = array(
'pav' => MAIN_DB_PREFIX.
'product_attribute_value',
'extra' => MAIN_DB_PREFIX.
'product_attribute_value_extrafields');
173 $this->import_fields_array[$r] = array(
174 'pav.fk_product_attribute' =>
"VariantAttributeRef*",
175 'pav.ref' =>
"VariantValueRef*",
176 'pav.value' =>
"VariantValueLabel*",
177 'pav.position' =>
"VariantValueRank"
179 $this->import_convertvalue_array[$r] = array(
180 'pav.fk_product_attribute' => array(
'rule' =>
'fetchidfromref',
'classfile' =>
'/variants/class/ProductAttribute.class.php',
'class' =>
'ProductAttribute',
'method' =>
'fetch',
'element' =>
'ProductAttribute'),
181 'pav.position' => array(
'rule' =>
'zeroifnull')
184 $keyforselect =
'product_attribute_value';
185 $keyforelement =
'productattributevalue';
186 $keyforaliasextra =
'extra';
187 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
188 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'product_attribute_value');
189 $this->import_examplevalues_array[$r] = array(
190 'pav.fk_product_attribute' =>
"ref:COL",
192 'pav.value' =>
"Blue",
193 'pav.position' =>
"10"
195 $this->import_updatekeys_array[$r] = array(
'pav.fk_product_attribute' =>
'VariantAttributeRef',
'pav.ref' =>
'VariantValueRef');
200 $this->import_code[$r] = $this->rights_class.
'_combination';
201 $this->import_label[$r] =
"ProductCombinations";
202 $this->import_icon[$r] = $this->picto;
203 $this->import_entities_array[$r] = array();
204 $this->import_tables_array[$r] = array(
'pac' => MAIN_DB_PREFIX.
'product_attribute_combination');
205 $this->import_fields_array[$r] = array(
206 'pac.fk_product_parent' =>
"ParentProductOfVariant*",
207 'pac.fk_product_child' =>
"VariantProductRef*",
208 'pac.variation_price' =>
"VariantPriceImpact",
209 'pac.variation_price_percentage' =>
"VariantPriceImpactIsPercent",
210 'pac.variation_weight' =>
"VariantWeightImpact",
211 'pac.variation_ref_ext' =>
"VariantRefExt"
213 $this->import_convertvalue_array[$r] = array(
214 'pac.fk_product_parent' => array(
'rule' =>
'fetchidfromref',
'classfile' =>
'/product/class/product.class.php',
'class' =>
'Product',
'method' =>
'fetch',
'element' =>
'Product'),
215 'pac.fk_product_child' => array(
'rule' =>
'fetchidfromref',
'classfile' =>
'/product/class/product.class.php',
'class' =>
'Product',
'method' =>
'fetch',
'element' =>
'Product'),
216 'pac.variation_price' => array(
'rule' =>
'zeroifnull'),
217 'pac.variation_price_percentage' => array(
'rule' =>
'zeroifnull'),
218 'pac.variation_weight' => array(
'rule' =>
'zeroifnull')
223 $this->import_regex_array[$r] = array(
224 'pac.variation_price_percentage' =>
'^[0-1]$'
228 $this->import_examplevalues_array[$r] = array(
229 'pac.fk_product_parent' =>
"ref:SHIRT (or the id of the parent product)",
230 'pac.fk_product_child' =>
"ref:SHIRT_BLUE_L (or the id of an existing product)",
231 'pac.variation_price' =>
"5.00",
232 'pac.variation_price_percentage' =>
"0",
233 'pac.variation_weight' =>
"0",
234 'pac.variation_ref_ext' =>
""
236 $this->import_updatekeys_array[$r] = array(
'pac.fk_product_parent' =>
'ParentProductOfVariant',
'pac.fk_product_child' =>
'VariantProductRef');
241 $this->import_preselected_updatekeys_array[$r] = array(
'pac.fk_product_parent',
'pac.fk_product_child');
245 $this->import_code[$r] = $this->rights_class.
'_combination2val';
246 $this->import_label[$r] =
"VariantFeatures";
247 $this->import_icon[$r] = $this->picto;
248 $this->import_entities_array[$r] = array();
249 $this->import_tables_array[$r] = array(
'pac2v' => MAIN_DB_PREFIX.
'product_attribute_combination2val');
250 $this->import_fields_array[$r] = array(
251 'pac2v.fk_prod_combination' =>
"VariantProductRef*",
252 'pac2v.fk_prod_attr' =>
"VariantAttributeRef*",
253 'pac2v.fk_prod_attr_val' =>
"VariantValueRef*"
255 $this->import_convertvalue_array[$r] = array(
256 'pac2v.fk_prod_combination' => array(
'rule' =>
'fetchidfromref',
'classfile' =>
'/variants/class/ProductCombination.class.php',
'class' =>
'ProductCombination',
'method' =>
'fetch',
'element' =>
'ProductCombination'),
257 'pac2v.fk_prod_attr' => array(
'rule' =>
'fetchidfromref',
'classfile' =>
'/variants/class/ProductAttribute.class.php',
'class' =>
'ProductAttribute',
'method' =>
'fetch',
'element' =>
'ProductAttribute'),
261 'pac2v.fk_prod_attr_val' => array(
'rule' =>
'compute',
'type' =>
'int',
'classfile' =>
'/variants/class/ProductCombination.class.php',
'class' =>
'ProductCombination',
'method' =>
'resolveAttributeValueId',
'element' =>
'ProductCombination')
263 $this->import_examplevalues_array[$r] = array(
264 'pac2v.fk_prod_combination' =>
"ref:SHIRT_BLUE_L (ref of the variant product)",
265 'pac2v.fk_prod_attr' =>
"ref:COL",
266 'pac2v.fk_prod_attr_val' =>
"ref:BLUE"
268 $this->import_updatekeys_array[$r] = array(
'pac2v.fk_prod_combination' =>
'VariantProductRef',
'pac2v.fk_prod_attr' =>
'VariantAttributeRef');
270 $this->import_preselected_updatekeys_array[$r] = array(
'pac2v.fk_prod_combination',
'pac2v.fk_prod_attr');
279 $this->import_code[$r] = $this->rights_class.
'_pricelevel';
280 $this->import_label[$r] =
"VariantPriceLevels";
281 $this->import_icon[$r] = $this->picto;
282 $this->import_entities_array[$r] = array();
283 $this->import_tables_array[$r] = array(
'pacpl' => MAIN_DB_PREFIX.
'product_attribute_combination_price_level');
284 $this->import_fields_array[$r] = array(
285 'pacpl.fk_product_attribute_combination' =>
"VariantProductRef*",
286 'pacpl.fk_price_level' =>
"VariantPriceLevel*",
287 'pacpl.variation_price' =>
"VariantPriceImpact",
288 'pacpl.variation_price_percentage' =>
"VariantPriceImpactIsPercent"
290 $this->import_convertvalue_array[$r] = array(
291 'pacpl.fk_product_attribute_combination' => array(
'rule' =>
'fetchidfromref',
'classfile' =>
'/variants/class/ProductCombination.class.php',
'class' =>
'ProductCombination',
'method' =>
'fetch',
'element' =>
'ProductCombination'),
292 'pacpl.variation_price' => array(
'rule' =>
'zeroifnull'),
293 'pacpl.variation_price_percentage' => array(
'rule' =>
'zeroifnull')
295 $this->import_regex_array[$r] = array(
296 'pacpl.fk_price_level' =>
'^[1-9][0-9]*$',
297 'pacpl.variation_price_percentage' =>
'^[0-1]$'
299 $this->import_examplevalues_array[$r] = array(
300 'pacpl.fk_product_attribute_combination' =>
"ref:SHIRT_BLUE_L (ref of the variant product)",
301 'pacpl.fk_price_level' =>
"1",
302 'pacpl.variation_price' =>
"5.00",
303 'pacpl.variation_price_percentage' =>
"0"
305 $this->import_updatekeys_array[$r] = array(
'pacpl.fk_product_attribute_combination' =>
'VariantProductRef',
'pacpl.fk_price_level' =>
'VariantPriceLevel');
308 $this->import_preselected_updatekeys_array[$r] = array(
'pacpl.fk_product_attribute_combination',
'pacpl.fk_price_level');
317 $this->export_code[$r] = $this->rights_class.
'_attribute';
318 $this->export_label[$r] =
"VariantAttributes";
319 $this->export_icon[$r] = $this->picto;
320 $this->export_permission[$r] = array(array(
"variants",
"read"), array(
"produit",
"export"));
321 $this->export_fields_array[$r] = array(
323 'pa.ref' =>
"VariantAttributeRef",
324 'pa.label' =>
"VariantAttributeLabel",
325 'pa.ref_ext' =>
"VariantAttributeRefExt",
326 'pa.position' =>
"VariantAttributeRank",
327 'pav.ref' =>
"VariantValueRef",
328 'pav.value' =>
"VariantValueLabel",
329 'pav.position' =>
"VariantValueRank"
331 $this->export_TypeFields_array[$r] = array(
333 'pa.label' =>
"Text",
334 'pa.ref_ext' =>
"Text",
335 'pa.position' =>
"Numeric",
337 'pav.value' =>
"Text",
338 'pav.position' =>
"Numeric"
340 $this->export_entities_array[$r] = array(
341 'pa.rowid' =>
"productattribute",
342 'pa.ref' =>
"productattribute",
343 'pa.label' =>
"productattribute",
344 'pa.ref_ext' =>
"productattribute",
345 'pa.position' =>
"productattribute",
346 'pav.ref' =>
"productattributevalue",
347 'pav.value' =>
"productattributevalue",
348 'pav.position' =>
"productattributevalue"
350 $this->export_dependencies_array[$r] = array(
'productattributevalue' =>
'pa.rowid');
351 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
352 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'product_attribute as pa';
355 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_attribute_value as pav ON pav.fk_product_attribute = pa.rowid AND pav.entity IN ('.
getEntity(
'product').
')';
356 $this->export_sql_end[$r] .=
' WHERE pa.entity IN ('.getEntity(
'product').
')';
357 $this->export_sql_order[$r] =
' ORDER BY pa.position, pa.ref, pav.position, pav.ref';
361 $this->export_code[$r] = $this->rights_class.
'_combination';
362 $this->export_label[$r] =
"ProductCombinations";
363 $this->export_icon[$r] = $this->picto;
364 $this->export_permission[$r] = array(array(
"variants",
"read"), array(
"produit",
"export"));
365 $this->export_fields_array[$r] = array(
366 'p.ref' =>
"ParentProductOfVariant",
367 'p.label' =>
"ParentProductLabel",
368 'p2.ref' =>
"VariantProductRef",
369 'p2.label' =>
"VariantProductLabel",
370 'pac.variation_price' =>
"VariantPriceImpact",
371 'pac.variation_price_percentage' =>
"VariantPriceImpactIsPercent",
372 'pac.variation_weight' =>
"VariantWeightImpact",
373 'pac.variation_ref_ext' =>
"VariantRefExt",
374 'pa.ref' =>
"VariantAttributeRef",
375 'pa.label' =>
"VariantAttributeLabel",
376 'pav.ref' =>
"VariantValueRef",
377 'pav.value' =>
"VariantValueLabel"
379 $this->export_TypeFields_array[$r] = array(
383 'p2.label' =>
"Text",
384 'pac.variation_price' =>
"Numeric",
385 'pac.variation_price_percentage' =>
"Boolean",
386 'pac.variation_weight' =>
"Numeric",
387 'pac.variation_ref_ext' =>
"Text",
389 'pa.label' =>
"Text",
391 'pav.value' =>
"Text"
393 $this->export_entities_array[$r] = array(
394 'p.ref' =>
"product",
395 'p.label' =>
"product",
396 'p2.ref' =>
"productcombination",
397 'p2.label' =>
"productcombination",
398 'pac.variation_price' =>
"productcombination",
399 'pac.variation_price_percentage' =>
"productcombination",
400 'pac.variation_weight' =>
"productcombination",
401 'pac.variation_ref_ext' =>
"productcombination",
402 'pa.ref' =>
"productattribute",
403 'pa.label' =>
"productattribute",
404 'pav.ref' =>
"productattributevalue",
405 'pav.value' =>
"productattributevalue"
409 $this->export_dependencies_array[$r] = array(
'productattribute' =>
'p2.ref',
'productattributevalue' =>
'p2.ref');
410 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
411 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'product_attribute_combination as pac';
412 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product as p ON p.rowid = pac.fk_product_parent';
413 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product as p2 ON p2.rowid = pac.fk_product_child';
414 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_attribute_combination2val as pac2v ON pac2v.fk_prod_combination = pac.rowid';
415 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_attribute as pa ON pa.rowid = pac2v.fk_prod_attr AND pa.entity IN ('.
getEntity(
'product').
')';
416 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_attribute_value as pav ON pav.rowid = pac2v.fk_prod_attr_val AND pav.entity IN ('.
getEntity(
'product').
')';
417 $this->export_sql_end[$r] .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
418 $this->export_sql_end[$r] .=
' AND p2.entity IN ('.getEntity(
'product').
')';
422 $this->export_sql_end[$r] .=
' AND pac.entity IN ('.getEntity(
'product').
')';
423 $this->export_sql_order[$r] =
' ORDER BY p.ref, p2.ref, pa.position, pa.ref';
432 $this->export_code[$r] = $this->rights_class.
'_pricelevel';
433 $this->export_label[$r] =
"VariantPriceLevels";
434 $this->export_icon[$r] = $this->picto;
435 $this->export_permission[$r] = array(array(
"variants",
"read"), array(
"produit",
"export"));
436 $this->export_fields_array[$r] = array(
437 'p.ref' =>
"ParentProductOfVariant",
438 'p2.ref' =>
"VariantProductRef",
439 'pacpl.fk_price_level' =>
"VariantPriceLevel",
440 'pacpl.variation_price' =>
"VariantPriceImpact",
441 'pacpl.variation_price_percentage' =>
"VariantPriceImpactIsPercent"
443 $this->export_TypeFields_array[$r] = array(
446 'pacpl.fk_price_level' =>
"Numeric",
447 'pacpl.variation_price' =>
"Numeric",
448 'pacpl.variation_price_percentage' =>
"Boolean"
450 $this->export_entities_array[$r] = array(
451 'p.ref' =>
"product",
452 'p2.ref' =>
"productcombination",
453 'pacpl.fk_price_level' =>
"productcombination",
454 'pacpl.variation_price' =>
"productcombination",
455 'pacpl.variation_price_percentage' =>
"productcombination"
457 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
458 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'product_attribute_combination_price_level as pacpl';
459 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product_attribute_combination as pac ON pac.rowid = pacpl.fk_product_attribute_combination';
460 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product as p ON p.rowid = pac.fk_product_parent';
461 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product as p2 ON p2.rowid = pac.fk_product_child';
462 $this->export_sql_end[$r] .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
463 $this->export_sql_end[$r] .=
' AND p2.entity IN ('.getEntity(
'product').
')';
465 $this->export_sql_end[$r] .=
' AND pac.entity IN ('.getEntity(
'product').
')';
466 $this->export_sql_order[$r] =
' ORDER BY p.ref, p2.ref, pacpl.fk_price_level';