19use Luracast\Restler\RestException;
21require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
22require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
23require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
24require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductAttribute.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductAttributeValue.class.php';
26require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination2ValuePair.class.php';
40 public static $FIELDS = array(
53 public $productsupplier;
63 $this->product =
new Product($this->db);
83 public function get($id, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
85 return $this->
_fetch($id,
'',
'',
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
107 public function getByRef($ref, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
109 return $this->
_fetch(
'', $ref,
'',
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
131 public function getByRefExt($ref_ext, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
133 return $this->
_fetch(
'',
'', $ref_ext,
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
155 public function getByBarcode($barcode, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
157 return $this->
_fetch(
'',
'',
'', $barcode, $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
179 public function index($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters =
'', $ids_only =
false, $variant_filter = 0, $pagination_data =
false, $includestockdata = 0, $properties =
'')
183 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
184 throw new RestException(403);
189 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
191 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
192 $sql .=
" FROM ".$this->db->prefix().
"product as t";
193 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON ef.fk_object = t.rowid";
195 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
197 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
199 if ($variant_filter == 1) {
200 $sql .=
' AND t.rowid not in (select distinct fk_product_parent from '.$this->db->prefix().
'product_attribute_combination)';
201 $sql .=
' AND t.rowid not in (select distinct fk_product_child from '.$this->db->prefix().
'product_attribute_combination)';
203 if ($variant_filter == 2) {
204 $sql .=
' AND t.rowid in (select distinct fk_product_parent from '.$this->db->prefix().
'product_attribute_combination)';
206 if ($variant_filter == 3) {
207 $sql .=
' AND t.rowid in (select distinct fk_product_child from '.$this->db->prefix().
'product_attribute_combination)';
212 $sql .=
" AND c.fk_categorie = ".((int) $category);
213 $sql .=
" AND c.fk_product = t.rowid";
217 $sql .=
" AND t.fk_product_type = 0";
218 } elseif ($mode == 2) {
220 $sql .=
" AND t.fk_product_type = 1";
228 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
233 $sqlTotals = str_replace(
'SELECT t.rowid, t.ref, t.ref_ext',
'SELECT count(t.rowid) as total', $sql);
235 $sql .= $this->db->order($sortfield, $sortorder);
240 $offset = $limit * $page;
242 $sql .= $this->db->plimit($limit + 1, $offset);
245 $result = $this->db->query($sql);
247 $num = $this->db->num_rows($result);
248 $min = min($num, ($limit <= 0 ? $num : $limit));
251 $obj = $this->db->fetch_object($result);
253 $product_static =
new Product($this->db);
254 if ($product_static->fetch($obj->rowid)) {
255 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
256 $product_static->load_stock();
258 if (is_array($product_static->stock_warehouse)) {
259 foreach ($product_static->stock_warehouse as $keytmp => $valtmp) {
260 if (isset($product_static->stock_warehouse[$keytmp]->detail_batch) && is_array($product_static->stock_warehouse[$keytmp]->detail_batch)) {
261 foreach ($product_static->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
262 unset($product_static->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
273 $obj_ret[] = $obj->rowid;
278 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
282 if ($pagination_data) {
283 $totalsResult = $this->db->query($sqlTotals);
284 $total = $this->db->fetch_object($totalsResult)->total;
289 $obj_ret[
'data'] = $tmp;
290 $obj_ret[
'pagination'] = array(
291 'total' => (
int) $total,
293 'page_count' => ceil((
int) $total/$limit),
307 public function post($request_data =
null)
309 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
310 throw new RestException(403);
313 $result = $this->
_validate($request_data);
315 foreach ($request_data as $field => $value) {
316 if ($field ===
'caller') {
318 $this->product->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
322 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
324 if ($this->product->create(DolibarrApiAccess::$user) < 0) {
325 throw new RestException(500,
"Error creating product", array_merge(array($this->product->error), $this->product->errors));
330 for ($key = 1; $key <= $key_max ; $key++) {
331 $newvat = $this->product->multiprices_tva_tx[$key];
333 $newvatsrccode = $this->product->default_vat_code;
334 $newprice = $this->product->multiprices[$key];
335 $newpricemin = $this->product->multiprices_min[$key];
336 $newbasetype = $this->product->multiprices_base_type[$key];
337 if (empty($newbasetype) || $newbasetype ==
'') {
338 $newbasetype = $this->product->price_base_type;
340 if ($newbasetype ==
'TTC') {
341 $newprice = $this->product->multiprices_ttc[$key];
342 $newpricemin = $this->product->multiprices_min_ttc[$key];
345 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
350 return $this->product->id;
366 public function put($id, $request_data =
null)
368 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
369 throw new RestException(403);
372 $result = $this->product->fetch($id);
374 throw new RestException(404,
'Product not found');
378 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
381 $oldproduct =
dol_clone($this->product, 2);
383 foreach ($request_data as $field => $value) {
384 if ($field ==
'id') {
387 if ($field ==
'stock_reel') {
388 throw new RestException(400,
'Stock reel cannot be updated here. Use the /stockmovements endpoint instead');
390 if ($field ===
'caller') {
392 $this->product->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
395 if ($field ==
'array_options' && is_array($value)) {
396 foreach ($value as $index => $val) {
397 $this->product->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->product);
401 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
405 if ($this->product->type != $oldproduct->type && ($this->product->isProduct() || $this->product->isService())) {
409 $result = $this->product->update($id, DolibarrApiAccess::$user, 1,
'update', $updatetype);
414 $pricemodified =
false;
415 if ($this->product->price_base_type != $oldproduct->price_base_type) {
416 $pricemodified =
true;
418 if ($this->product->tva_tx != $oldproduct->tva_tx) {
419 $pricemodified =
true;
421 if ($this->product->tva_npr != $oldproduct->tva_npr) {
422 $pricemodified =
true;
424 if ($this->product->default_vat_code != $oldproduct->default_vat_code) {
425 $pricemodified =
true;
428 if ($this->product->price_base_type ==
'TTC') {
429 if ($this->product->price_ttc != $oldproduct->price_ttc) {
430 $pricemodified =
true;
432 if ($this->product->price_min_ttc != $oldproduct->price_min_ttc) {
433 $pricemodified =
true;
436 if ($this->product->price != $oldproduct->price) {
437 $pricemodified =
true;
439 if ($this->product->price_min != $oldproduct->price_min) {
440 $pricemodified =
true;
445 if ($pricemodified) {
446 $newvat = $this->product->tva_tx;
447 $newnpr = $this->product->tva_npr;
448 $newvatsrccode = $this->product->default_vat_code;
450 $newprice = $this->product->price;
451 $newpricemin = $this->product->price_min;
452 if ($this->product->price_base_type ==
'TTC') {
453 $newprice = $this->product->price_ttc;
454 $newpricemin = $this->product->price_min_ttc;
457 $result = $this->product->updatePrice($newprice, $this->product->price_base_type, DolibarrApiAccess::$user, $newvat, $newpricemin, 0, $newnpr, 0, 0, array(), $newvatsrccode);
463 for ($key = 1; $key <= $key_max ; $key++) {
464 $pricemodified =
false;
465 if ($this->product->multiprices_base_type[$key] != $oldproduct->multiprices_base_type[$key]) {
466 $pricemodified =
true;
468 if ($this->product->multiprices_tva_tx[$key] != $oldproduct->multiprices_tva_tx[$key]) $pricemodified =
true;
469 if ($this->product->multiprices_base_type[$key] ==
'TTC') {
470 if ($this->product->multiprices_ttc[$key] != $oldproduct->multiprices_ttc[$key]) $pricemodified =
true;
471 if ($this->product->multiprices_min_ttc[$key] != $oldproduct->multiprices_min_ttc[$key]) $pricemodified =
true;
473 if ($this->product->multiprices[$key] != $oldproduct->multiprices[$key]) $pricemodified =
true;
474 if ($this->product->multiprices_min[$key] != $oldproduct->multiprices[$key]) $pricemodified =
true;
477 if ($pricemodified && $result > 0) {
478 $newvat = $this->product->multiprices_tva_tx[$key];
480 $newvatsrccode = $this->product->default_vat_code;
481 $newprice = $this->product->multiprices[$key];
482 $newpricemin = $this->product->multiprices_min[$key];
483 $newbasetype = $this->product->multiprices_base_type[$key];
484 if (empty($newbasetype) || $newbasetype ==
'') {
485 $newbasetype = $this->product->price_base_type;
487 if ($newbasetype ==
'TTC') {
488 $newprice = $this->product->multiprices_ttc[$key];
489 $newpricemin = $this->product->multiprices_min_ttc[$key];
492 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
498 throw new RestException(500,
"Error updating product", array_merge(array($this->product->error), $this->product->errors));
501 return $this->
get($id);
510 public function delete($id)
512 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
513 throw new RestException(403);
515 $result = $this->product->fetch($id);
517 throw new RestException(404,
'Product not found');
521 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
526 $user = DolibarrApiAccess::$user;
528 $res = $this->product->delete(DolibarrApiAccess::$user);
530 throw new RestException(500,
"Can't delete, error occurs");
531 } elseif ($res == 0) {
532 throw new RestException(409,
"Can't delete, that product is probably used");
538 'message' =>
'Object deleted'
557 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
558 throw new RestException(403);
562 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
565 $childrenArbo = $this->product->getChildsArbo($id, 1);
567 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
569 foreach ($childrenArbo as $values) {
570 $children[] = array_combine($keys, $values);
595 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
596 throw new RestException(403);
600 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
603 $result = $this->product->add_sousproduit($id, $subproduct_id, $qty, $incdec);
605 throw new RestException(500,
"Error adding product child");
625 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
626 throw new RestException(403);
630 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
633 $result = $this->product->del_sousproduit($id, $subproduct_id);
635 throw new RestException(500,
"Error while removing product child");
654 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
656 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
657 throw new RestException(403);
662 $result = $categories->getListForItem($id,
'product', $sortfield, $sortorder, $limit, $page);
665 throw new RestException(503,
'Error when retrieve category list : '.implode(
',', array_merge(array($categories->error), $categories->errors)));
684 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
685 throw new RestException(403);
689 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
692 $result = $this->product->fetch($id);
694 throw new RestException(404,
'Product not found');
698 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
702 'multiprices'=>$this->product->multiprices,
703 'multiprices_inc_tax'=>$this->product->multiprices_ttc,
704 'multiprices_min'=>$this->product->multiprices_min,
705 'multiprices_min_inc_tax'=>$this->product->multiprices_min_ttc,
706 'multiprices_vat'=>$this->product->multiprices_tva_tx,
707 'multiprices_base_type'=>$this->product->multiprices_base_type,
726 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
727 throw new RestException(403);
731 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
734 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
735 if ($socid > 0 && $socid != $thirdparty_id) {
736 throw new RestException(403,
'Getting prices for all customers or for the customer ID '.$thirdparty_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
739 $result = $this->product->fetch($id);
741 throw new RestException(404,
'Product not found');
745 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
748 $filter[
't.fk_product'] = $id;
749 if ($thirdparty_id) {
750 $filter[
't.fk_soc'] = $thirdparty_id;
752 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
755 if (empty($prodcustprice->lines)) {
756 throw new RestException(404,
'Prices not found');
759 return $prodcustprice->lines;
775 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
776 throw new RestException(403);
780 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
783 $result = $this->product->fetch($id);
785 throw new RestException(404,
'Product not found');
789 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
793 'prices_by_qty'=>$this->product->prices_by_qty[0],
794 'prices_by_qty_list'=>$this->product->prices_by_qty_list[0]
831 public function addPurchasePrice($id, $qty, $buyprice, $price_base_type, $fourn_id, $availability, $ref_fourn, $tva_tx, $charges = 0, $remise_percent = 0, $remise = 0, $newnpr = 0, $delivery_time_days = 0, $supplier_reputation =
'', $localtaxes_array = array(), $newdefaultvatcode =
'', $multicurrency_buyprice = 0, $multicurrency_price_base_type =
'HT', $multicurrency_tx = 1, $multicurrency_code =
'', $desc_fourn =
'', $barcode =
'', $fk_barcode_type =
null)
833 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
834 throw new RestException(403);
837 $result = $this->productsupplier->fetch($id);
839 throw new RestException(404,
'Product not found');
843 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
846 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
847 if ($socid > 0 && $socid != $fourn_id) {
848 throw new RestException(403,
'Adding purchase price for the supplier ID '.$fourn_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
851 $result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
853 throw new RestException(500,
"Error adding supplier to product : ".$this->db->lasterror());
857 $result = $fourn->fetch($fourn_id);
859 throw new RestException(404,
'Supplier not found');
863 $ref_fourn =
sanitizeVal($ref_fourn,
'alphanohtml');
864 $desc_fourn =
sanitizeVal($desc_fourn,
'restricthtml');
867 $result = $this->productsupplier->update_buyprice($qty, $buyprice, DolibarrApiAccess::$user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges, $remise_percent, $remise, $newnpr, $delivery_time_days, $supplier_reputation, $localtaxes_array, $newdefaultvatcode, $multicurrency_buyprice, $multicurrency_price_base_type, $multicurrency_tx, $multicurrency_code, $desc_fourn, $barcode, $fk_barcode_type);
870 throw new RestException(500,
"Error updating buy price : ".$this->db->lasterror());
872 return (
int) $this->productsupplier->product_fourn_price_id;
891 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
892 throw new RestException(403);
894 $result = $this->productsupplier->fetch($id);
896 throw new RestException(404,
'Product not found');
900 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
905 $resultsupplier = $this->productsupplier->remove_product_fournisseur_price($priceid);
908 return $resultsupplier;
926 public function getSupplierProducts($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $supplier = 0, $sqlfilters =
'')
930 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
931 throw new RestException(403);
937 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
939 if ($supplier != $socid || empty($supplier)) {
940 throw new RestException(403,
'As an external user, you can request only for your supplier id = '.$socid);
944 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
945 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product AS t LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON (ef.fk_object = t.rowid)";
948 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
950 $sql .=
", ".$this->db->prefix().
"product_fournisseur_price as s";
952 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
955 $sql .=
" AND s.fk_soc = ".((int) $supplier);
958 $sql .=
" AND s.fk_soc = ".((int) $socid);
960 $sql .=
" AND s.fk_product = t.rowid";
963 $sql .=
" AND c.fk_categorie = ".((int) $category);
964 $sql .=
" AND c.fk_product = t.rowid";
968 $sql .=
" AND t.fk_product_type = 0";
969 } elseif ($mode == 2) {
971 $sql .=
" AND t.fk_product_type = 1";
978 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
982 $sql .= $this->db->order($sortfield, $sortorder);
987 $offset = $limit * $page;
988 $sql .= $this->db->plimit($limit + 1, $offset);
990 $result = $this->db->query($sql);
992 $num = $this->db->num_rows($result);
993 $min = min($num, ($limit <= 0 ? $num : $limit));
996 $obj = $this->db->fetch_object($result);
999 $product_fourn_list = $product_fourn->list_product_fournisseur_price($obj->rowid,
'',
'', 0, 0);
1000 foreach ($product_fourn_list as $tmpobj) {
1005 $obj_ret[$obj->rowid] = $product_fourn_list;
1010 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
1037 if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
1038 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
1041 $id = (empty($id) ? 0 : $id);
1043 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1044 throw new RestException(403);
1047 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
1049 $result = $this->product->fetch($id, $ref, $ref_ext, $barcode);
1051 throw new RestException(404,
'Product not found');
1055 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1058 $product_fourn_list = array();
1062 $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->product->id,
'',
'', 0, 0, ($socid > 0 ? $socid : 0));
1065 foreach ($product_fourn_list as $tmpobj) {
1089 public function getAttributes($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
1091 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1092 throw new RestException(403);
1095 $sql =
"SELECT t.rowid, t.ref, t.ref_ext, t.label, t.position, t.entity";
1096 $sql .=
" FROM ".$this->db->prefix().
"product_attribute as t";
1097 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
1103 if ($errormessage) {
1104 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1108 $sql .= $this->db->order($sortfield, $sortorder);
1113 $offset = $limit * $page;
1115 $sql .= $this->db->plimit($limit, $offset);
1118 $resql = $this->db->query($sql);
1121 throw new RestException(503,
'Error when retrieving product attribute list : '.$this->db->lasterror());
1125 while ($obj = $this->db->fetch_object($resql)) {
1127 $tmp->id = $obj->rowid;
1128 $tmp->ref = $obj->ref;
1129 $tmp->ref_ext = $obj->ref_ext;
1130 $tmp->label = $obj->label;
1131 $tmp->position = $obj->position;
1132 $tmp->entity = $obj->entity;
1153 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1154 throw new RestException(403);
1158 $result = $prodattr->fetch((
int) $id);
1161 throw new RestException(404,
"Product attribute not found");
1164 $fields = [
"id",
"ref",
"ref_ext",
"label",
"position",
"entity"];
1166 foreach ($prodattr as $field => $value) {
1167 if (!in_array($field, $fields)) {
1168 unset($prodattr->{$field});
1172 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1173 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1174 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id).
" AND pac.entity IN (".
getEntity(
'product').
")";
1176 $resql = $this->db->query($sql);
1177 $obj = $this->db->fetch_object($resql);
1178 $prodattr->is_used_by_products = (int) $obj->nb;
1196 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1197 throw new RestException(403);
1202 $sql =
"SELECT rowid, ref, ref_ext, label, position, entity FROM ".$this->db->prefix().
"product_attribute WHERE ref LIKE '".$this->db->escape($ref).
"' AND entity IN (".
getEntity(
'product').
")";
1204 $query = $this->db->query($sql);
1206 if (!$this->db->num_rows($query)) {
1207 throw new RestException(404);
1210 $result = $this->db->fetch_object($query);
1213 $attr[
'id'] = $result->rowid;
1214 $attr[
'ref'] = $result->ref;
1215 $attr[
'ref_ext'] = $result->ref_ext;
1216 $attr[
'label'] = $result->label;
1217 $attr[
'rang'] = $result->position;
1218 $attr[
'position'] = $result->position;
1219 $attr[
'entity'] = $result->entity;
1221 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1222 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1223 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1225 $resql = $this->db->query($sql);
1226 $obj = $this->db->fetch_object($resql);
1228 $attr[
"is_used_by_products"] = (int) $obj->nb;
1246 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1247 throw new RestException(403);
1250 $ref_ext = trim($ref_ext);
1252 $sql =
"SELECT rowid, ref, ref_ext, label, position, entity FROM ".$this->db->prefix().
"product_attribute WHERE ref_ext LIKE '".$this->db->escape($ref_ext).
"' AND entity IN (".
getEntity(
'product').
")";
1254 $query = $this->db->query($sql);
1256 if (!$this->db->num_rows($query)) {
1257 throw new RestException(404);
1260 $result = $this->db->fetch_object($query);
1263 $attr[
'id'] = $result->rowid;
1264 $attr[
'ref'] = $result->ref;
1265 $attr[
'ref_ext'] = $result->ref_ext;
1266 $attr[
'label'] = $result->label;
1267 $attr[
'rang'] = $result->position;
1268 $attr[
'position'] = $result->position;
1269 $attr[
'entity'] = $result->entity;
1271 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1272 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1273 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1275 $resql = $this->db->query($sql);
1276 $obj = $this->db->fetch_object($resql);
1278 $attr[
"is_used_by_products"] = (int) $obj->nb;
1298 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1299 throw new RestException(403);
1303 $prodattr->label = $label;
1304 $prodattr->ref = $ref;
1305 $prodattr->ref_ext = $ref_ext;
1307 $resid = $prodattr->create(DolibarrApiAccess::$user);
1309 throw new RestException(500,
"Error creating new attribute");
1330 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1331 throw new RestException(403);
1336 $result = $prodattr->fetch((
int) $id);
1338 throw new RestException(404,
'Attribute not found');
1339 } elseif ($result < 0) {
1340 throw new RestException(500,
"Error fetching attribute");
1343 foreach ($request_data as $field => $value) {
1344 if ($field ==
'rowid') {
1347 if ($field ===
'caller') {
1349 $prodattr->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1353 $prodattr->$field = $this->_checkValForAPI($field, $value, $prodattr);
1356 if ($prodattr->update(DolibarrApiAccess::$user) > 0) {
1357 $result = $prodattr->fetch((
int) $id);
1359 throw new RestException(404,
'Attribute not found');
1360 } elseif ($result < 0) {
1361 throw new RestException(500,
"Error fetching attribute");
1363 return $this->_cleanObjectDatas($prodattr);
1366 throw new RestException(500,
"Error updating attribute");
1382 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1383 throw new RestException(403);
1387 $prodattr->id = (int) $id;
1388 $result = $prodattr->delete(DolibarrApiAccess::$user);
1391 throw new RestException(500,
"Error deleting attribute");
1410 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1411 throw new RestException(403);
1414 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value WHERE rowid = ".(int) $id.
" AND entity IN (".
getEntity(
'product').
")";
1416 $query = $this->db->query($sql);
1419 throw new RestException(403);
1422 if (!$this->db->num_rows($query)) {
1423 throw new RestException(404,
'Attribute value not found');
1426 $result = $this->db->fetch_object($query);
1429 $attrval[
'id'] = $result->rowid;
1430 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1431 $attrval[
'ref'] = $result->ref;
1432 $attrval[
'value'] = $result->value;
1451 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1452 throw new RestException(403);
1457 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value";
1458 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int) $id).
" AND entity IN (".
getEntity(
'product').
")";
1460 $query = $this->db->query($sql);
1463 throw new RestException(403);
1466 if (!$this->db->num_rows($query)) {
1467 throw new RestException(404,
'Attribute value not found');
1470 $result = $this->db->fetch_object($query);
1473 $attrval[
'id'] = $result->rowid;
1474 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1475 $attrval[
'ref'] = $result->ref;
1476 $attrval[
'value'] = $result->value;
1494 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1495 throw new RestException(403);
1500 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"product_attribute_value";
1501 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int) $id).
" AND entity IN (".
getEntity(
'product').
")";
1502 $query = $this->db->query($sql);
1505 throw new RestException(403);
1508 if (!$this->db->num_rows($query)) {
1509 throw new RestException(404,
'Attribute value not found');
1512 $result = $this->db->fetch_object($query);
1515 $attrval->id = $result->rowid;
1516 $result = $attrval->delete(DolibarrApiAccess::$user);
1521 throw new RestException(500,
"Error deleting attribute value");
1537 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1538 throw new RestException(403);
1543 $return = $objectval->fetchAllByProductAttribute((
int) $id);
1545 if (count($return) == 0) {
1546 throw new RestException(404,
'Attribute values not found');
1549 foreach ($return as $key => $val) {
1550 $return[$key] = $this->_cleanObjectDatas($return[$key]);
1568 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1569 throw new RestException(403);
1577 $sql .=
"v.fk_product_attribute, v.rowid, v.ref, v.value FROM ".$this->db->prefix().
"product_attribute_value as v";
1578 $sql .=
" WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix().
"product_attribute WHERE ref LIKE '".$this->db->escape($ref).
"')";
1580 $resql = $this->db->query($sql);
1582 while ($result = $this->db->fetch_object($resql)) {
1584 $tmp->fk_product_attribute = $result->fk_product_attribute;
1585 $tmp->id = $result->rowid;
1586 $tmp->ref = $result->ref;
1587 $tmp->value = $result->value;
1589 $return[] = $this->_cleanObjectDatas($tmp);
1610 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1611 throw new RestException(403);
1614 if (empty($ref) || empty($value)) {
1615 throw new RestException(403);
1619 $objectval->fk_product_attribute = ((int) $id);
1620 $objectval->ref = $ref;
1621 $objectval->value = $value;
1623 if ($objectval->create(DolibarrApiAccess::$user) > 0) {
1624 return $objectval->id;
1626 throw new RestException(500,
"Error creating new attribute value");
1643 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1644 throw new RestException(403);
1648 $result = $objectval->fetch((
int) $id);
1651 throw new RestException(404,
'Attribute value not found');
1652 } elseif ($result < 0) {
1653 throw new RestException(500,
"Error fetching attribute value");
1656 foreach ($request_data as $field => $value) {
1657 if ($field ==
'rowid') {
1660 if ($field ===
'caller') {
1662 $objectval->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1666 $objectval->$field = $this->_checkValForAPI($field, $value, $objectval);
1669 if ($objectval->update(DolibarrApiAccess::$user) > 0) {
1670 $result = $objectval->fetch((
int) $id);
1672 throw new RestException(404,
'Attribute not found');
1673 } elseif ($result < 0) {
1674 throw new RestException(500,
"Error fetching attribute");
1676 return $this->_cleanObjectDatas($objectval);
1679 throw new RestException(500,
"Error updating attribute");
1695 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1696 throw new RestException(403);
1700 $objectval->id = (int) $id;
1702 if ($objectval->delete(DolibarrApiAccess::$user) > 0) {
1705 throw new RestException(500,
"Error deleting attribute value");
1722 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1723 throw new RestException(403);
1727 $combinations = $prodcomb->fetchAllByFkProductParent((
int) $id);
1729 foreach ($combinations as $key => $combination) {
1731 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1732 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1734 if (!empty($includestock) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1735 $productModel =
new Product($this->db);
1736 $productModel->fetch((
int) $combination->fk_product_child);
1737 $productModel->load_stock($includestock);
1738 $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse;
1742 return $combinations;
1758 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1759 throw new RestException(403);
1762 $result = $this->product->fetch(0, $ref);
1764 throw new RestException(404,
'Product not found');
1768 $combinations = $prodcomb->fetchAllByFkProductParent((
int) $this->product->id);
1770 foreach ($combinations as $key => $combination) {
1772 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1773 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1776 return $combinations;
1799 public function addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference =
'', $ref_ext =
'')
1801 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1802 throw new RestException(403);
1806 throw new RestException(400,
'Product ID is mandatory');
1809 if (empty($features) || !is_array($features)) {
1810 throw new RestException(400,
'Features is mandatory and should be IDs of attribute values indexed by IDs of attributes');
1813 $weight_impact =
price2num($weight_impact);
1814 $price_impact =
price2num($price_impact);
1818 foreach ($features as $id_attr => $id_value) {
1819 if ($prodattr->fetch((
int) $id_attr) < 0) {
1820 throw new RestException(400,
'Invalid attribute ID: '.$id_attr);
1822 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1823 throw new RestException(400,
'Invalid attribute value ID: '.$id_value);
1827 $result = $this->product->fetch((
int) $id);
1829 throw new RestException(404,
'Product not found');
1834 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference, $ref_ext);
1838 throw new RestException(500,
"Error creating new product variant");
1862 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1863 throw new RestException(403);
1866 if (empty($ref) || empty($features) || !is_array($features)) {
1867 throw new RestException(403);
1870 $weight_impact =
price2num($weight_impact);
1871 $price_impact =
price2num($price_impact);
1875 foreach ($features as $id_attr => $id_value) {
1876 if ($prodattr->fetch((
int) $id_attr) < 0) {
1877 throw new RestException(404);
1879 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1880 throw new RestException(404);
1884 $result = $this->product->fetch(0, trim($ref));
1886 throw new RestException(404,
'Product not found');
1890 if (!$prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) {
1891 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact);
1895 throw new RestException(500,
"Error creating new product variant");
1898 return $prodcomb->id;
1916 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1917 throw new RestException(403);
1921 $prodcomb->fetch((
int) $id);
1923 foreach ($request_data as $field => $value) {
1924 if ($field ==
'rowid') {
1927 if ($field ===
'caller') {
1929 $prodcomb->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1933 $prodcomb->$field = $this->_checkValForAPI($field, $value, $prodcomb);
1936 $result = $prodcomb->update(DolibarrApiAccess::$user);
1940 throw new RestException(500,
"Error editing variant");
1956 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1957 throw new RestException(403);
1961 $prodcomb->id = (int) $id;
1962 $result = $prodcomb->delete(DolibarrApiAccess::$user);
1964 throw new RestException(500,
"Error deleting variant");
1983 public function getStock($id, $selected_warehouse_id =
null)
1985 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire') || !DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1986 throw new RestException(403);
1990 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1993 $product_model =
new Product($this->db);
1994 $product_model->fetch($id);
1995 $product_model->load_stock();
1997 $stockData = $this->_cleanObjectDatas($product_model)->stock_warehouse;
1998 if ($selected_warehouse_id) {
1999 foreach ($stockData as $warehouse_id => $warehouse) {
2000 if ($warehouse_id != $selected_warehouse_id) {
2001 unset($stockData[$warehouse_id]);
2006 return array(
'stock_warehouses'=>$stockData);
2025 unset(
$object->prices_by_qty_id);
2027 unset(
$object->product_id_already_linked);
2041 unset(
$object->fourn_price_base_type);
2045 unset(
$object->product_fourn_id);
2048 unset(
$object->mode_reglement_id);
2049 unset(
$object->cond_reglement_id);
2050 unset(
$object->demand_reason_id);
2051 unset(
$object->transport_mode_id);
2052 unset(
$object->cond_reglement);
2053 unset(
$object->shipping_method_id);
2058 unset(
$object->recuperableonly);
2059 unset(
$object->multiprices_recuperableonly);
2065 unset(
$object->supplierprices);
2067 if (!DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2069 unset(
$object->stock_theorique);
2070 unset(
$object->stock_warehouse);
2086 foreach (Products::$FIELDS as $field) {
2087 if (!isset($data[$field])) {
2088 throw new RestException(400,
"$field field missing");
2090 $product[$field] = $data[$field];
2114 private function _fetch($id, $ref =
'', $ref_ext =
'', $barcode =
'', $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includeifobjectisused =
false, $includetrans =
false)
2116 if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
2117 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
2120 $id = (empty($id) ? 0 : $id);
2122 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
2123 throw new RestException(403);
2126 $result = $this->product->fetch($id, $ref, $ref_ext, $barcode, 0, 0, ($includetrans ? 0 : 1));
2128 throw new RestException(404,
'Product not found');
2132 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2135 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2136 $this->product->load_stock($includestockdata);
2138 if (is_array($this->product->stock_warehouse)) {
2139 foreach ($this->product->stock_warehouse as $keytmp => $valtmp) {
2140 if (isset($this->product->stock_warehouse[$keytmp]->detail_batch) && is_array($this->product->stock_warehouse[$keytmp]->detail_batch)) {
2141 foreach ($this->product->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
2142 unset($this->product->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
2149 if ($includesubproducts) {
2150 $childrenArbo = $this->product->getChildsArbo($id, 1);
2152 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
2153 $children = array();
2154 foreach ($childrenArbo as $values) {
2155 $children[] = array_combine($keys, $values);
2158 $this->product->sousprods = $children;
2161 if ($includeparentid) {
2163 $this->product->fk_product_parent =
null;
2164 if (($fk_product_parent = $prodcomb->fetchByFkProductChild($this->product->id)) > 0) {
2165 $this->product->fk_product_parent = $fk_product_parent;
2169 if ($includeifobjectisused) {
2170 $this->product->is_object_used = ($this->product->isObjectUsed() > 0);
2173 return $this->_cleanObjectDatas($this->product);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage categories.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage suppliers.
Class ProductAttribute Used to represent a Product attribute Examples:
Class ProductAttributeValue Used to represent a product attribute value.
Class ProductCombination2ValuePair Used to represent the relation between a variant and its attribute...
Class ProductCombination Used to represent the relation between a product and one of its variants.
File of class to manage predefined price products or services by customer.
Class to manage predefined suppliers products.
Class to manage products or services.
_cleanObjectDatas($object)
Clean sensible object datas.
getAttributes($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
Get attributes.
putAttributeValue($id, $request_data)
Update attribute value.
deleteAttributes($id)
Delete attributes by id.
deletePurchasePrice($id, $priceid)
Delete purchase price for a product.
getAttributeValuesByRef($ref)
Get all values for an attribute ref.
putVariant($id, $request_data=null)
Put product variants.
index($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $mode=0, $category=0, $sqlfilters='', $ids_only=false, $variant_filter=0, $pagination_data=false, $includestockdata=0, $properties='')
List products.
put($id, $request_data=null)
Update product.
addAttributeValue($id, $ref, $value)
Add attribute value.
addVariantByProductRef($ref, $weight_impact, $price_impact, $price_impact_is_percent, $features)
Add variant by product ref.
getAttributeValueById($id)
Get attribute value by id.
getVariantsByProdRef($ref)
Get product variants by Product ref.
getCustomerPricesPerQuantity($id)
Get prices per quantity for a product.
__construct()
Constructor.
getPurchasePrices($id, $ref='', $ref_ext='', $barcode='')
Get purchase prices for a product.
delSubproducts($id, $subproduct_id)
Remove subproduct.
getVariants($id, $includestock=0)
Get product variants.
putAttributes($id, $request_data=null)
Update attributes by id.
deleteAttributeValueById($id)
Delete attribute value by id.
getAttributeValues($id)
Get all values for an attribute id.
addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference='', $ref_ext='')
Add variant.
getSubproducts($id)
Get the list of subproducts of the product.
getAttributesByRefExt($ref_ext)
Get attributes by ref_ext.
getByRef($ref, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
Get properties of a product object by ref.
deleteAttributeValueByRef($id, $ref)
Delete attribute value by ref.
post($request_data=null)
Create product object.
addPurchasePrice($id, $qty, $buyprice, $price_base_type, $fourn_id, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='', $localtaxes_array=array(), $newdefaultvatcode='', $multicurrency_buyprice=0, $multicurrency_price_base_type='HT', $multicurrency_tx=1, $multicurrency_code='', $desc_fourn='', $barcode='', $fk_barcode_type=null)
Add/Update purchase prices for a product.
getCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get categories for a product.
getByBarcode($barcode, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
Get properties of a product object by barcode.
getByRefExt($ref_ext, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
Get properties of a product object by ref_ext.
getCustomerPricesPerCustomer($id, $thirdparty_id='')
Get prices per customer for a product.
deleteVariant($id)
Delete product variants.
_validate($data)
Validate fields before create or update object.
getCustomerPricesPerSegment($id)
Get prices per segment for a product.
_fetch($id, $ref='', $ref_ext='', $barcode='', $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includeifobjectisused=false, $includetrans=false)
Get properties of 1 product object.
addAttributes($ref, $label, $ref_ext='')
Add attributes.
getAttributeValueByRef($id, $ref)
Get attribute value by ref.
getSupplierProducts($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $mode=0, $category=0, $supplier=0, $sqlfilters='')
Get a list of all purchase prices of products.
getAttributeById($id)
Get attribute by ID.
getStock($id, $selected_warehouse_id=null)
Get stock data for the product id given.
getAttributesByRef($ref)
Get attributes by ref.
addSubproducts($id, $subproduct_id, $qty, $incdec=1)
Add subproduct.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.