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);
402 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
406 if ($this->product->type != $oldproduct->type && ($this->product->isProduct() || $this->product->isService())) {
410 $result = $this->product->update($id, DolibarrApiAccess::$user, 1,
'update', $updatetype);
415 $pricemodified =
false;
416 if ($this->product->price_base_type != $oldproduct->price_base_type) {
417 $pricemodified =
true;
419 if ($this->product->tva_tx != $oldproduct->tva_tx) {
420 $pricemodified =
true;
422 if ($this->product->tva_npr != $oldproduct->tva_npr) {
423 $pricemodified =
true;
425 if ($this->product->default_vat_code != $oldproduct->default_vat_code) {
426 $pricemodified =
true;
429 if ($this->product->price_base_type ==
'TTC') {
430 if ($this->product->price_ttc != $oldproduct->price_ttc) {
431 $pricemodified =
true;
433 if ($this->product->price_min_ttc != $oldproduct->price_min_ttc) {
434 $pricemodified =
true;
437 if ($this->product->price != $oldproduct->price) {
438 $pricemodified =
true;
440 if ($this->product->price_min != $oldproduct->price_min) {
441 $pricemodified =
true;
446 if ($pricemodified) {
447 $newvat = $this->product->tva_tx;
448 $newnpr = $this->product->tva_npr;
449 $newvatsrccode = $this->product->default_vat_code;
451 $newprice = $this->product->price;
452 $newpricemin = $this->product->price_min;
453 if ($this->product->price_base_type ==
'TTC') {
454 $newprice = $this->product->price_ttc;
455 $newpricemin = $this->product->price_min_ttc;
458 $result = $this->product->updatePrice($newprice, $this->product->price_base_type, DolibarrApiAccess::$user, $newvat, $newpricemin, 0, $newnpr, 0, 0, array(), $newvatsrccode);
464 for ($key = 1; $key <= $key_max ; $key++) {
465 $pricemodified =
false;
466 if ($this->product->multiprices_base_type[$key] != $oldproduct->multiprices_base_type[$key]) {
467 $pricemodified =
true;
469 if ($this->product->multiprices_tva_tx[$key] != $oldproduct->multiprices_tva_tx[$key]) $pricemodified =
true;
470 if ($this->product->multiprices_base_type[$key] ==
'TTC') {
471 if ($this->product->multiprices_ttc[$key] != $oldproduct->multiprices_ttc[$key]) $pricemodified =
true;
472 if ($this->product->multiprices_min_ttc[$key] != $oldproduct->multiprices_min_ttc[$key]) $pricemodified =
true;
474 if ($this->product->multiprices[$key] != $oldproduct->multiprices[$key]) $pricemodified =
true;
475 if ($this->product->multiprices_min[$key] != $oldproduct->multiprices[$key]) $pricemodified =
true;
478 if ($pricemodified && $result > 0) {
479 $newvat = $this->product->multiprices_tva_tx[$key];
481 $newvatsrccode = $this->product->default_vat_code;
482 $newprice = $this->product->multiprices[$key];
483 $newpricemin = $this->product->multiprices_min[$key];
484 $newbasetype = $this->product->multiprices_base_type[$key];
485 if (empty($newbasetype) || $newbasetype ==
'') {
486 $newbasetype = $this->product->price_base_type;
488 if ($newbasetype ==
'TTC') {
489 $newprice = $this->product->multiprices_ttc[$key];
490 $newpricemin = $this->product->multiprices_min_ttc[$key];
493 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
499 throw new RestException(500,
"Error updating product", array_merge(array($this->product->error), $this->product->errors));
502 return $this->
get($id);
511 public function delete($id)
513 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
514 throw new RestException(403);
516 $result = $this->product->fetch($id);
518 throw new RestException(404,
'Product not found');
522 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
527 $user = DolibarrApiAccess::$user;
529 $res = $this->product->delete(DolibarrApiAccess::$user);
531 throw new RestException(500,
"Can't delete, error occurs");
532 } elseif ($res == 0) {
533 throw new RestException(409,
"Can't delete, that product is probably used");
539 'message' =>
'Object deleted'
558 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
559 throw new RestException(403);
563 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
566 $childrenArbo = $this->product->getChildsArbo($id, 1);
568 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
570 foreach ($childrenArbo as $values) {
571 $children[] = array_combine($keys, $values);
596 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
597 throw new RestException(403);
601 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
604 $result = $this->product->add_sousproduit($id, $subproduct_id, $qty, $incdec);
606 throw new RestException(500,
"Error adding product child");
626 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
627 throw new RestException(403);
631 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
634 $result = $this->product->del_sousproduit($id, $subproduct_id);
636 throw new RestException(500,
"Error while removing product child");
655 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
657 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
658 throw new RestException(403);
663 $result = $categories->getListForItem($id,
'product', $sortfield, $sortorder, $limit, $page);
666 throw new RestException(503,
'Error when retrieve category list : '.implode(
',', array_merge(array($categories->error), $categories->errors)));
685 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
686 throw new RestException(403);
690 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
693 $result = $this->product->fetch($id);
695 throw new RestException(404,
'Product not found');
699 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
703 'multiprices'=>$this->product->multiprices,
704 'multiprices_inc_tax'=>$this->product->multiprices_ttc,
705 'multiprices_min'=>$this->product->multiprices_min,
706 'multiprices_min_inc_tax'=>$this->product->multiprices_min_ttc,
707 'multiprices_vat'=>$this->product->multiprices_tva_tx,
708 'multiprices_base_type'=>$this->product->multiprices_base_type,
727 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
728 throw new RestException(403);
732 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
735 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
736 if ($socid > 0 && $socid != $thirdparty_id) {
737 throw new RestException(403,
'Getting prices for all customers or for the customer ID '.$thirdparty_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
740 $result = $this->product->fetch($id);
742 throw new RestException(404,
'Product not found');
746 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
749 $filter[
't.fk_product'] = $id;
750 if ($thirdparty_id) {
751 $filter[
't.fk_soc'] = $thirdparty_id;
753 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
756 if (empty($prodcustprice->lines)) {
757 throw new RestException(404,
'Prices not found');
760 return $prodcustprice->lines;
776 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
777 throw new RestException(403);
781 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
784 $result = $this->product->fetch($id);
786 throw new RestException(404,
'Product not found');
790 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
794 'prices_by_qty'=>$this->product->prices_by_qty[0],
795 'prices_by_qty_list'=>$this->product->prices_by_qty_list[0]
832 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)
834 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
835 throw new RestException(403);
838 $result = $this->productsupplier->fetch($id);
840 throw new RestException(404,
'Product not found');
844 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
847 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
848 if ($socid > 0 && $socid != $fourn_id) {
849 throw new RestException(403,
'Adding purchase price for the supplier ID '.$fourn_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
852 $result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
854 throw new RestException(500,
"Error adding supplier to product : ".$this->db->lasterror());
858 $result = $fourn->fetch($fourn_id);
860 throw new RestException(404,
'Supplier not found');
864 $ref_fourn =
sanitizeVal($ref_fourn,
'alphanohtml');
865 $desc_fourn =
sanitizeVal($desc_fourn,
'restricthtml');
868 $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);
871 throw new RestException(500,
"Error updating buy price : ".$this->db->lasterror());
873 return (
int) $this->productsupplier->product_fourn_price_id;
892 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
893 throw new RestException(403);
895 $result = $this->productsupplier->fetch($id);
897 throw new RestException(404,
'Product not found');
901 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
906 $resultsupplier = $this->productsupplier->remove_product_fournisseur_price($priceid);
909 return $resultsupplier;
927 public function getSupplierProducts($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $supplier = 0, $sqlfilters =
'')
931 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
932 throw new RestException(403);
938 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
940 if ($supplier != $socid || empty($supplier)) {
941 throw new RestException(403,
'As an external user, you can request only for your supplier id = '.$socid);
945 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
946 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product AS t LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON (ef.fk_object = t.rowid)";
949 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
951 $sql .=
", ".$this->db->prefix().
"product_fournisseur_price as s";
953 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
956 $sql .=
" AND s.fk_soc = ".((int) $supplier);
959 $sql .=
" AND s.fk_soc = ".((int) $socid);
961 $sql .=
" AND s.fk_product = t.rowid";
964 $sql .=
" AND c.fk_categorie = ".((int) $category);
965 $sql .=
" AND c.fk_product = t.rowid";
969 $sql .=
" AND t.fk_product_type = 0";
970 } elseif ($mode == 2) {
972 $sql .=
" AND t.fk_product_type = 1";
979 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
983 $sql .= $this->db->order($sortfield, $sortorder);
988 $offset = $limit * $page;
989 $sql .= $this->db->plimit($limit + 1, $offset);
991 $result = $this->db->query($sql);
993 $num = $this->db->num_rows($result);
994 $min = min($num, ($limit <= 0 ? $num : $limit));
997 $obj = $this->db->fetch_object($result);
1000 $product_fourn_list = $product_fourn->list_product_fournisseur_price($obj->rowid,
'',
'', 0, 0);
1001 foreach ($product_fourn_list as $tmpobj) {
1006 $obj_ret[$obj->rowid] = $product_fourn_list;
1011 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
1038 if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
1039 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
1042 $id = (empty($id) ? 0 : $id);
1044 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1045 throw new RestException(403);
1048 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
1050 $result = $this->product->fetch($id, $ref, $ref_ext, $barcode);
1052 throw new RestException(404,
'Product not found');
1056 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1059 $product_fourn_list = array();
1063 $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->product->id,
'',
'', 0, 0, ($socid > 0 ? $socid : 0));
1066 foreach ($product_fourn_list as $tmpobj) {
1090 public function getAttributes($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
1092 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1093 throw new RestException(403);
1096 $sql =
"SELECT t.rowid, t.ref, t.ref_ext, t.label, t.position, t.entity";
1097 $sql .=
" FROM ".$this->db->prefix().
"product_attribute as t";
1098 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
1104 if ($errormessage) {
1105 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1109 $sql .= $this->db->order($sortfield, $sortorder);
1114 $offset = $limit * $page;
1116 $sql .= $this->db->plimit($limit, $offset);
1119 $resql = $this->db->query($sql);
1122 throw new RestException(503,
'Error when retrieving product attribute list : '.$this->db->lasterror());
1126 while ($obj = $this->db->fetch_object($resql)) {
1128 $tmp->id = $obj->rowid;
1129 $tmp->ref = $obj->ref;
1130 $tmp->ref_ext = $obj->ref_ext;
1131 $tmp->label = $obj->label;
1132 $tmp->position = $obj->position;
1133 $tmp->entity = $obj->entity;
1154 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1155 throw new RestException(403);
1159 $result = $prodattr->fetch((
int) $id);
1162 throw new RestException(404,
"Product attribute not found");
1165 $fields = [
"id",
"ref",
"ref_ext",
"label",
"position",
"entity"];
1167 foreach ($prodattr as $field => $value) {
1168 if (!in_array($field, $fields)) {
1169 unset($prodattr->{$field});
1173 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1174 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1175 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id).
" AND pac.entity IN (".
getEntity(
'product').
")";
1177 $resql = $this->db->query($sql);
1178 $obj = $this->db->fetch_object($resql);
1179 $prodattr->is_used_by_products = (int) $obj->nb;
1197 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1198 throw new RestException(403);
1203 $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').
")";
1205 $query = $this->db->query($sql);
1207 if (!$this->db->num_rows($query)) {
1208 throw new RestException(404);
1211 $result = $this->db->fetch_object($query);
1214 $attr[
'id'] = $result->rowid;
1215 $attr[
'ref'] = $result->ref;
1216 $attr[
'ref_ext'] = $result->ref_ext;
1217 $attr[
'label'] = $result->label;
1218 $attr[
'rang'] = $result->position;
1219 $attr[
'position'] = $result->position;
1220 $attr[
'entity'] = $result->entity;
1222 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1223 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1224 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1226 $resql = $this->db->query($sql);
1227 $obj = $this->db->fetch_object($resql);
1229 $attr[
"is_used_by_products"] = (int) $obj->nb;
1247 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1248 throw new RestException(403);
1251 $ref_ext = trim($ref_ext);
1253 $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').
")";
1255 $query = $this->db->query($sql);
1257 if (!$this->db->num_rows($query)) {
1258 throw new RestException(404);
1261 $result = $this->db->fetch_object($query);
1264 $attr[
'id'] = $result->rowid;
1265 $attr[
'ref'] = $result->ref;
1266 $attr[
'ref_ext'] = $result->ref_ext;
1267 $attr[
'label'] = $result->label;
1268 $attr[
'rang'] = $result->position;
1269 $attr[
'position'] = $result->position;
1270 $attr[
'entity'] = $result->entity;
1272 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1273 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1274 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1276 $resql = $this->db->query($sql);
1277 $obj = $this->db->fetch_object($resql);
1279 $attr[
"is_used_by_products"] = (int) $obj->nb;
1299 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1300 throw new RestException(403);
1304 $prodattr->label = $label;
1305 $prodattr->ref = $ref;
1306 $prodattr->ref_ext = $ref_ext;
1308 $resid = $prodattr->create(DolibarrApiAccess::$user);
1310 throw new RestException(500,
"Error creating new attribute");
1331 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1332 throw new RestException(403);
1337 $result = $prodattr->fetch((
int) $id);
1339 throw new RestException(404,
'Attribute not found');
1340 } elseif ($result < 0) {
1341 throw new RestException(500,
"Error fetching attribute");
1344 foreach ($request_data as $field => $value) {
1345 if ($field ==
'rowid') {
1348 if ($field ===
'caller') {
1350 $prodattr->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1354 $prodattr->$field = $this->_checkValForAPI($field, $value, $prodattr);
1357 if ($prodattr->update(DolibarrApiAccess::$user) > 0) {
1358 $result = $prodattr->fetch((
int) $id);
1360 throw new RestException(404,
'Attribute not found');
1361 } elseif ($result < 0) {
1362 throw new RestException(500,
"Error fetching attribute");
1364 return $this->_cleanObjectDatas($prodattr);
1367 throw new RestException(500,
"Error updating attribute");
1383 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1384 throw new RestException(403);
1388 $prodattr->id = (int) $id;
1389 $result = $prodattr->delete(DolibarrApiAccess::$user);
1392 throw new RestException(500,
"Error deleting attribute");
1411 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1412 throw new RestException(403);
1415 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value WHERE rowid = ".(int) $id.
" AND entity IN (".
getEntity(
'product').
")";
1417 $query = $this->db->query($sql);
1420 throw new RestException(403);
1423 if (!$this->db->num_rows($query)) {
1424 throw new RestException(404,
'Attribute value not found');
1427 $result = $this->db->fetch_object($query);
1430 $attrval[
'id'] = $result->rowid;
1431 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1432 $attrval[
'ref'] = $result->ref;
1433 $attrval[
'value'] = $result->value;
1452 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1453 throw new RestException(403);
1458 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value";
1459 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int) $id).
" AND entity IN (".
getEntity(
'product').
")";
1461 $query = $this->db->query($sql);
1464 throw new RestException(403);
1467 if (!$this->db->num_rows($query)) {
1468 throw new RestException(404,
'Attribute value not found');
1471 $result = $this->db->fetch_object($query);
1474 $attrval[
'id'] = $result->rowid;
1475 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1476 $attrval[
'ref'] = $result->ref;
1477 $attrval[
'value'] = $result->value;
1495 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1496 throw new RestException(403);
1501 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"product_attribute_value";
1502 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int) $id).
" AND entity IN (".
getEntity(
'product').
")";
1503 $query = $this->db->query($sql);
1506 throw new RestException(403);
1509 if (!$this->db->num_rows($query)) {
1510 throw new RestException(404,
'Attribute value not found');
1513 $result = $this->db->fetch_object($query);
1516 $attrval->id = $result->rowid;
1517 $result = $attrval->delete(DolibarrApiAccess::$user);
1522 throw new RestException(500,
"Error deleting attribute value");
1538 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1539 throw new RestException(403);
1544 $return = $objectval->fetchAllByProductAttribute((
int) $id);
1546 if (count($return) == 0) {
1547 throw new RestException(404,
'Attribute values not found');
1550 foreach ($return as $key => $val) {
1551 $return[$key] = $this->_cleanObjectDatas($return[$key]);
1569 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1570 throw new RestException(403);
1578 $sql .=
"v.fk_product_attribute, v.rowid, v.ref, v.value FROM ".$this->db->prefix().
"product_attribute_value as v";
1579 $sql .=
" WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix().
"product_attribute WHERE ref LIKE '".$this->db->escape($ref).
"')";
1581 $resql = $this->db->query($sql);
1583 while ($result = $this->db->fetch_object($resql)) {
1585 $tmp->fk_product_attribute = $result->fk_product_attribute;
1586 $tmp->id = $result->rowid;
1587 $tmp->ref = $result->ref;
1588 $tmp->value = $result->value;
1590 $return[] = $this->_cleanObjectDatas($tmp);
1611 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1612 throw new RestException(403);
1615 if (empty($ref) || empty($value)) {
1616 throw new RestException(403);
1620 $objectval->fk_product_attribute = ((int) $id);
1621 $objectval->ref = $ref;
1622 $objectval->value = $value;
1624 if ($objectval->create(DolibarrApiAccess::$user) > 0) {
1625 return $objectval->id;
1627 throw new RestException(500,
"Error creating new attribute value");
1644 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1645 throw new RestException(403);
1649 $result = $objectval->fetch((
int) $id);
1652 throw new RestException(404,
'Attribute value not found');
1653 } elseif ($result < 0) {
1654 throw new RestException(500,
"Error fetching attribute value");
1657 foreach ($request_data as $field => $value) {
1658 if ($field ==
'rowid') {
1661 if ($field ===
'caller') {
1663 $objectval->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1667 $objectval->$field = $this->_checkValForAPI($field, $value, $objectval);
1670 if ($objectval->update(DolibarrApiAccess::$user) > 0) {
1671 $result = $objectval->fetch((
int) $id);
1673 throw new RestException(404,
'Attribute not found');
1674 } elseif ($result < 0) {
1675 throw new RestException(500,
"Error fetching attribute");
1677 return $this->_cleanObjectDatas($objectval);
1680 throw new RestException(500,
"Error updating attribute");
1696 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1697 throw new RestException(403);
1701 $objectval->id = (int) $id;
1703 if ($objectval->delete(DolibarrApiAccess::$user) > 0) {
1706 throw new RestException(500,
"Error deleting attribute value");
1723 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1724 throw new RestException(403);
1728 $combinations = $prodcomb->fetchAllByFkProductParent((
int) $id);
1730 foreach ($combinations as $key => $combination) {
1732 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1733 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1735 if (!empty($includestock) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1736 $productModel =
new Product($this->db);
1737 $productModel->fetch((
int) $combination->fk_product_child);
1738 $productModel->load_stock($includestock);
1739 $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse;
1743 return $combinations;
1759 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1760 throw new RestException(403);
1763 $result = $this->product->fetch(0, $ref);
1765 throw new RestException(404,
'Product not found');
1769 $combinations = $prodcomb->fetchAllByFkProductParent((
int) $this->product->id);
1771 foreach ($combinations as $key => $combination) {
1773 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1774 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1777 return $combinations;
1800 public function addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference =
'', $ref_ext =
'')
1802 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1803 throw new RestException(403);
1807 throw new RestException(400,
'Product ID is mandatory');
1810 if (empty($features) || !is_array($features)) {
1811 throw new RestException(400,
'Features is mandatory and should be IDs of attribute values indexed by IDs of attributes');
1814 $weight_impact =
price2num($weight_impact);
1815 $price_impact =
price2num($price_impact);
1819 foreach ($features as $id_attr => $id_value) {
1820 if ($prodattr->fetch((
int) $id_attr) < 0) {
1821 throw new RestException(400,
'Invalid attribute ID: '.$id_attr);
1823 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1824 throw new RestException(400,
'Invalid attribute value ID: '.$id_value);
1828 $result = $this->product->fetch((
int) $id);
1830 throw new RestException(404,
'Product not found');
1835 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference, $ref_ext);
1839 throw new RestException(500,
"Error creating new product variant");
1863 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1864 throw new RestException(403);
1867 if (empty($ref) || empty($features) || !is_array($features)) {
1868 throw new RestException(403);
1871 $weight_impact =
price2num($weight_impact);
1872 $price_impact =
price2num($price_impact);
1876 foreach ($features as $id_attr => $id_value) {
1877 if ($prodattr->fetch((
int) $id_attr) < 0) {
1878 throw new RestException(404);
1880 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1881 throw new RestException(404);
1885 $result = $this->product->fetch(0, trim($ref));
1887 throw new RestException(404,
'Product not found');
1891 if (!$prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) {
1892 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact);
1896 throw new RestException(500,
"Error creating new product variant");
1899 return $prodcomb->id;
1917 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1918 throw new RestException(403);
1922 $prodcomb->fetch((
int) $id);
1924 foreach ($request_data as $field => $value) {
1925 if ($field ==
'rowid') {
1928 if ($field ===
'caller') {
1930 $prodcomb->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1934 $prodcomb->$field = $this->_checkValForAPI($field, $value, $prodcomb);
1937 $result = $prodcomb->update(DolibarrApiAccess::$user);
1941 throw new RestException(500,
"Error editing variant");
1957 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1958 throw new RestException(403);
1962 $prodcomb->id = (int) $id;
1963 $result = $prodcomb->delete(DolibarrApiAccess::$user);
1965 throw new RestException(500,
"Error deleting variant");
1984 public function getStock($id, $selected_warehouse_id =
null)
1986 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire') || !DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1987 throw new RestException(403);
1991 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1994 $product_model =
new Product($this->db);
1995 $product_model->fetch($id);
1996 $product_model->load_stock();
1998 $stockData = $this->_cleanObjectDatas($product_model)->stock_warehouse;
1999 if ($selected_warehouse_id) {
2000 foreach ($stockData as $warehouse_id => $warehouse) {
2001 if ($warehouse_id != $selected_warehouse_id) {
2002 unset($stockData[$warehouse_id]);
2007 return array(
'stock_warehouses'=>$stockData);
2026 unset(
$object->prices_by_qty_id);
2028 unset(
$object->product_id_already_linked);
2042 unset(
$object->fourn_price_base_type);
2046 unset(
$object->product_fourn_id);
2049 unset(
$object->mode_reglement_id);
2050 unset(
$object->cond_reglement_id);
2051 unset(
$object->demand_reason_id);
2052 unset(
$object->transport_mode_id);
2053 unset(
$object->cond_reglement);
2054 unset(
$object->shipping_method_id);
2059 unset(
$object->recuperableonly);
2060 unset(
$object->multiprices_recuperableonly);
2066 unset(
$object->supplierprices);
2068 if (!DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2070 unset(
$object->stock_theorique);
2071 unset(
$object->stock_warehouse);
2087 foreach (Products::$FIELDS as $field) {
2088 if (!isset($data[$field])) {
2089 throw new RestException(400,
"$field field missing");
2091 $product[$field] = $data[$field];
2115 private function _fetch($id, $ref =
'', $ref_ext =
'', $barcode =
'', $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includeifobjectisused =
false, $includetrans =
false)
2117 if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
2118 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
2121 $id = (empty($id) ? 0 : $id);
2123 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
2124 throw new RestException(403);
2127 $result = $this->product->fetch($id, $ref, $ref_ext, $barcode, 0, 0, ($includetrans ? 0 : 1));
2129 throw new RestException(404,
'Product not found');
2133 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2136 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2137 $this->product->load_stock($includestockdata);
2139 if (is_array($this->product->stock_warehouse)) {
2140 foreach ($this->product->stock_warehouse as $keytmp => $valtmp) {
2141 if (isset($this->product->stock_warehouse[$keytmp]->detail_batch) && is_array($this->product->stock_warehouse[$keytmp]->detail_batch)) {
2142 foreach ($this->product->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
2143 unset($this->product->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
2150 if ($includesubproducts) {
2151 $childrenArbo = $this->product->getChildsArbo($id, 1);
2153 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
2154 $children = array();
2155 foreach ($childrenArbo as $values) {
2156 $children[] = array_combine($keys, $values);
2159 $this->product->sousprods = $children;
2162 if ($includeparentid) {
2164 $this->product->fk_product_parent =
null;
2165 if (($fk_product_parent = $prodcomb->fetchByFkProductChild($this->product->id)) > 0) {
2166 $this->product->fk_product_parent = $fk_product_parent;
2170 if ($includeifobjectisused) {
2171 $this->product->is_object_used = ($this->product->isObjectUsed() > 0);
2174 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.