21use Luracast\Restler\RestException;
23require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
24require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
26require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductAttribute.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductAttributeValue.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination2ValuePair.class.php';
42 public static $FIELDS = array(
55 public $productsupplier;
65 $this->product =
new Product($this->db);
85 public function get(
$id, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
87 return $this->
_fetch(
$id,
'',
'',
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
109 public function getByRef($ref, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
111 return $this->
_fetch(0, $ref,
'',
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
133 public function getByRefExt($ref_ext, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
135 return $this->
_fetch(0,
'', $ref_ext,
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
157 public function getByBarcode($barcode, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
159 return $this->
_fetch(0,
'',
'', $barcode, $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
181 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 =
'')
185 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
186 throw new RestException(403);
191 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
193 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
194 $sql .=
" FROM ".$this->db->prefix().
"product as t";
195 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON ef.fk_object = t.rowid";
197 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
199 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
201 if ($variant_filter == 1) {
202 $sql .=
' AND t.rowid not in (select distinct fk_product_parent from '.$this->db->prefix().
'product_attribute_combination)';
203 $sql .=
' AND t.rowid not in (select distinct fk_product_child from '.$this->db->prefix().
'product_attribute_combination)';
205 if ($variant_filter == 2) {
206 $sql .=
' AND t.rowid in (select distinct fk_product_parent from '.$this->db->prefix().
'product_attribute_combination)';
208 if ($variant_filter == 3) {
209 $sql .=
' AND t.rowid in (select distinct fk_product_child from '.$this->db->prefix().
'product_attribute_combination)';
214 $sql .=
" AND c.fk_categorie = ".((int) $category);
215 $sql .=
" AND c.fk_product = t.rowid";
219 $sql .=
" AND t.fk_product_type = 0";
220 } elseif ($mode == 2) {
222 $sql .=
" AND t.fk_product_type = 1";
230 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
235 $sqlTotals = str_replace(
'SELECT t.rowid, t.ref, t.ref_ext',
'SELECT count(t.rowid) as total', $sql);
237 $sql .= $this->db->order($sortfield, $sortorder);
242 $offset = $limit * $page;
244 $sql .= $this->db->plimit($limit + 1, $offset);
247 $result = $this->db->query($sql);
249 $num = $this->db->num_rows($result);
250 $min = min($num, ($limit <= 0 ? $num : $limit));
253 $obj = $this->db->fetch_object($result);
255 $product_static =
new Product($this->db);
256 if ($product_static->fetch($obj->rowid)) {
257 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
258 $product_static->load_stock();
260 if (is_array($product_static->stock_warehouse)) {
261 foreach ($product_static->stock_warehouse as $keytmp => $valtmp) {
262 if (isset($product_static->stock_warehouse[$keytmp]->detail_batch) && is_array($product_static->stock_warehouse[$keytmp]->detail_batch)) {
263 foreach ($product_static->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
264 unset($product_static->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
275 $obj_ret[] = $obj->rowid;
280 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
284 if ($pagination_data) {
285 $totalsResult = $this->db->query($sqlTotals);
286 $total = $this->db->fetch_object($totalsResult)->total;
291 $obj_ret[
'data'] = $tmp;
292 $obj_ret[
'pagination'] = array(
293 'total' => (
int) $total,
295 'page_count' => ceil((
int) $total / $limit),
309 public function post($request_data =
null)
311 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
312 throw new RestException(403);
315 $result = $this->
_validate($request_data);
317 foreach ($request_data as $field => $value) {
318 if ($field ===
'caller') {
320 $this->product->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
324 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
326 if ($this->product->create(DolibarrApiAccess::$user) < 0) {
327 throw new RestException(500,
"Error creating product", array_merge(array($this->product->error), $this->product->errors));
332 for ($key = 1; $key <= $key_max ; $key++) {
333 $newvat = $this->product->multiprices_tva_tx[$key];
335 $newvatsrccode = $this->product->default_vat_code;
336 $newprice = $this->product->multiprices[$key];
337 $newpricemin = $this->product->multiprices_min[$key];
338 $newbasetype = $this->product->multiprices_base_type[$key];
339 if (empty($newbasetype) || $newbasetype ==
'') {
340 $newbasetype = $this->product->price_base_type;
342 if ($newbasetype ==
'TTC') {
343 $newprice = $this->product->multiprices_ttc[$key];
344 $newpricemin = $this->product->multiprices_min_ttc[$key];
347 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
352 return $this->product->id;
368 public function put(
$id, $request_data =
null)
370 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
371 throw new RestException(403);
374 $result = $this->product->fetch(
$id);
376 throw new RestException(404,
'Product not found');
380 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
383 $oldproduct =
dol_clone($this->product, 2);
385 foreach ($request_data as $field => $value) {
386 if ($field ==
'id') {
389 if ($field ==
'stock_reel') {
390 throw new RestException(400,
'Stock reel cannot be updated here. Use the /stockmovements endpoint instead');
392 if ($field ===
'caller') {
394 $this->product->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
397 if ($field ==
'array_options' && is_array($value)) {
398 foreach ($value as $index => $val) {
399 $this->product->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->product);
403 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
407 if ($this->product->type != $oldproduct->type && ($this->product->isProduct() || $this->product->isService())) {
411 $result = $this->product->update(
$id, DolibarrApiAccess::$user, 1,
'update', $updatetype);
416 $pricemodified =
false;
417 if ($this->product->price_base_type != $oldproduct->price_base_type) {
418 $pricemodified =
true;
420 if ($this->product->tva_tx != $oldproduct->tva_tx) {
421 $pricemodified =
true;
423 if ($this->product->tva_npr != $oldproduct->tva_npr) {
424 $pricemodified =
true;
426 if ($this->product->default_vat_code != $oldproduct->default_vat_code) {
427 $pricemodified =
true;
430 if ($this->product->price_base_type ==
'TTC') {
431 if ($this->product->price_ttc != $oldproduct->price_ttc) {
432 $pricemodified =
true;
434 if ($this->product->price_min_ttc != $oldproduct->price_min_ttc) {
435 $pricemodified =
true;
438 if ($this->product->price != $oldproduct->price) {
439 $pricemodified =
true;
441 if ($this->product->price_min != $oldproduct->price_min) {
442 $pricemodified =
true;
447 if ($pricemodified) {
448 $newvat = $this->product->tva_tx;
449 $newnpr = $this->product->tva_npr;
450 $newvatsrccode = $this->product->default_vat_code;
452 $newprice = $this->product->price;
453 $newpricemin = $this->product->price_min;
454 if ($this->product->price_base_type ==
'TTC') {
455 $newprice = $this->product->price_ttc;
456 $newpricemin = $this->product->price_min_ttc;
459 $result = $this->product->updatePrice($newprice, $this->product->price_base_type, DolibarrApiAccess::$user, $newvat, $newpricemin, 0, $newnpr, 0, 0, array(), $newvatsrccode);
465 for ($key = 1; $key <= $key_max ; $key++) {
466 $pricemodified =
false;
467 if ($this->product->multiprices_base_type[$key] != $oldproduct->multiprices_base_type[$key]) {
468 $pricemodified =
true;
470 if ($this->product->multiprices_tva_tx[$key] != $oldproduct->multiprices_tva_tx[$key]) {
471 $pricemodified =
true;
473 if ($this->product->multiprices_base_type[$key] ==
'TTC') {
474 if ($this->product->multiprices_ttc[$key] != $oldproduct->multiprices_ttc[$key]) {
475 $pricemodified =
true;
477 if ($this->product->multiprices_min_ttc[$key] != $oldproduct->multiprices_min_ttc[$key]) {
478 $pricemodified =
true;
481 if ($this->product->multiprices[$key] != $oldproduct->multiprices[$key]) {
482 $pricemodified =
true;
484 if ($this->product->multiprices_min[$key] != $oldproduct->multiprices[$key]) {
485 $pricemodified =
true;
489 if ($pricemodified && $result > 0) {
490 $newvat = $this->product->multiprices_tva_tx[$key];
492 $newvatsrccode = $this->product->default_vat_code;
493 $newprice = $this->product->multiprices[$key];
494 $newpricemin = $this->product->multiprices_min[$key];
495 $newbasetype = $this->product->multiprices_base_type[$key];
496 if (empty($newbasetype) || $newbasetype ==
'') {
497 $newbasetype = $this->product->price_base_type;
499 if ($newbasetype ==
'TTC') {
500 $newprice = $this->product->multiprices_ttc[$key];
501 $newpricemin = $this->product->multiprices_min_ttc[$key];
504 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
510 throw new RestException(500,
"Error updating product", array_merge(array($this->product->error), $this->product->errors));
513 return $this->
get(
$id);
522 public function delete(
$id)
524 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
525 throw new RestException(403);
527 $result = $this->product->fetch(
$id);
529 throw new RestException(404,
'Product not found');
533 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
538 $user = DolibarrApiAccess::$user;
540 $res = $this->product->delete(DolibarrApiAccess::$user);
542 throw new RestException(500,
"Can't delete, error occurs");
543 } elseif ($res == 0) {
544 throw new RestException(409,
"Can't delete, that product is probably used");
550 'message' =>
'Object deleted'
569 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
570 throw new RestException(403);
574 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
577 $childrenArbo = $this->product->getChildsArbo(
$id, 1);
579 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
581 foreach ($childrenArbo as $values) {
582 $children[] = array_combine($keys, $values);
607 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
608 throw new RestException(403);
612 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
615 $result = $this->product->add_sousproduit(
$id, $subproduct_id, $qty, $incdec);
617 throw new RestException(500,
"Error adding product child");
637 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
638 throw new RestException(403);
642 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
645 $result = $this->product->del_sousproduit(
$id, $subproduct_id);
647 throw new RestException(500,
"Error while removing product child");
666 public function getCategories(
$id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
668 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
669 throw new RestException(403);
674 $result = $categories->getListForItem(
$id,
'product', $sortfield, $sortorder, $limit, $page);
677 throw new RestException(503,
'Error when retrieve category list : '.implode(
',', array_merge(array($categories->error), $categories->errors)));
696 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
697 throw new RestException(403);
701 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
704 $result = $this->product->fetch(
$id);
706 throw new RestException(404,
'Product not found');
710 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
714 'multiprices' => $this->product->multiprices,
715 'multiprices_inc_tax' => $this->product->multiprices_ttc,
716 'multiprices_min' => $this->product->multiprices_min,
717 'multiprices_min_inc_tax' => $this->product->multiprices_min_ttc,
718 'multiprices_vat' => $this->product->multiprices_tva_tx,
719 'multiprices_base_type' => $this->product->multiprices_base_type,
738 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
739 throw new RestException(403);
743 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
746 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
747 if ($socid > 0 && $socid != $thirdparty_id) {
748 throw new RestException(403,
'Getting prices for all customers or for the customer ID '.$thirdparty_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
751 $result = $this->product->fetch(
$id);
753 throw new RestException(404,
'Product not found');
757 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
760 $filter[
't.fk_product'] =
$id;
761 if ($thirdparty_id) {
762 $filter[
't.fk_soc'] = $thirdparty_id;
764 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
767 if (empty($prodcustprice->lines)) {
768 throw new RestException(404,
'Prices not found');
771 return $prodcustprice->lines;
787 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
788 throw new RestException(403);
792 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
795 $result = $this->product->fetch(
$id);
797 throw new RestException(404,
'Product not found');
801 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
805 'prices_by_qty' => $this->product->prices_by_qty[0],
806 'prices_by_qty_list' => $this->product->prices_by_qty_list[0]
843 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)
845 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
846 throw new RestException(403);
849 $result = $this->productsupplier->fetch(
$id);
851 throw new RestException(404,
'Product not found');
855 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
858 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
859 if ($socid > 0 && $socid != $fourn_id) {
860 throw new RestException(403,
'Adding purchase price for the supplier ID '.$fourn_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
863 $result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
865 throw new RestException(500,
"Error adding supplier to product : ".$this->db->lasterror());
869 $result = $fourn->fetch($fourn_id);
871 throw new RestException(404,
'Supplier not found');
875 $ref_fourn =
sanitizeVal($ref_fourn,
'alphanohtml');
876 $desc_fourn =
sanitizeVal($desc_fourn,
'restricthtml');
879 $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);
882 throw new RestException(500,
"Error updating buy price : ".$this->db->lasterror());
884 return (
int) $this->productsupplier->product_fourn_price_id;
903 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
904 throw new RestException(403);
906 $result = $this->productsupplier->fetch(
$id);
908 throw new RestException(404,
'Product not found');
912 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
917 $resultsupplier = $this->productsupplier->remove_product_fournisseur_price($priceid);
920 return $resultsupplier;
938 public function getSupplierProducts($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $supplier = 0, $sqlfilters =
'')
942 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
943 throw new RestException(403);
949 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
951 if ($supplier != $socid || empty($supplier)) {
952 throw new RestException(403,
'As an external user, you can request only for your supplier id = '.$socid);
956 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
957 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product AS t LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON (ef.fk_object = t.rowid)";
960 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
962 $sql .=
", ".$this->db->prefix().
"product_fournisseur_price as s";
964 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
967 $sql .=
" AND s.fk_soc = ".((int) $supplier);
970 $sql .=
" AND s.fk_soc = ".((int) $socid);
972 $sql .=
" AND s.fk_product = t.rowid";
975 $sql .=
" AND c.fk_categorie = ".((int) $category);
976 $sql .=
" AND c.fk_product = t.rowid";
980 $sql .=
" AND t.fk_product_type = 0";
981 } elseif ($mode == 2) {
983 $sql .=
" AND t.fk_product_type = 1";
990 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
994 $sql .= $this->db->order($sortfield, $sortorder);
999 $offset = $limit * $page;
1000 $sql .= $this->db->plimit($limit + 1, $offset);
1002 $result = $this->db->query($sql);
1004 $num = $this->db->num_rows($result);
1005 $min = min($num, ($limit <= 0 ? $num : $limit));
1008 $obj = $this->db->fetch_object($result);
1011 $product_fourn_list = $product_fourn->list_product_fournisseur_price($obj->rowid,
'',
'', 0, 0);
1012 foreach ($product_fourn_list as $tmpobj) {
1017 $obj_ret[$obj->rowid] = $product_fourn_list;
1022 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
1049 if (empty(
$id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
1050 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
1055 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1056 throw new RestException(403);
1059 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
1061 $result = $this->product->fetch(
$id, $ref, $ref_ext, $barcode);
1063 throw new RestException(404,
'Product not found');
1067 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1070 $product_fourn_list = array();
1074 $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->product->id,
'',
'', 0, 0, ($socid > 0 ? $socid : 0));
1077 foreach ($product_fourn_list as $tmpobj) {
1101 public function getAttributes($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
1103 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1104 throw new RestException(403);
1107 $sql =
"SELECT t.rowid, t.ref, t.ref_ext, t.label, t.position, t.entity";
1108 $sql .=
" FROM ".$this->db->prefix().
"product_attribute as t";
1109 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
1115 if ($errormessage) {
1116 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1120 $sql .= $this->db->order($sortfield, $sortorder);
1125 $offset = $limit * $page;
1127 $sql .= $this->db->plimit($limit, $offset);
1130 $resql = $this->db->query($sql);
1133 throw new RestException(503,
'Error when retrieving product attribute list : '.$this->db->lasterror());
1137 while ($obj = $this->db->fetch_object($resql)) {
1139 $tmp->id = $obj->rowid;
1140 $tmp->ref = $obj->ref;
1141 $tmp->ref_ext = $obj->ref_ext;
1142 $tmp->label = $obj->label;
1143 $tmp->position = $obj->position;
1144 $tmp->entity = $obj->entity;
1165 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1166 throw new RestException(403);
1170 $result = $prodattr->fetch((
int)
$id);
1173 throw new RestException(404,
"Product attribute not found");
1176 $fields = [
"id",
"ref",
"ref_ext",
"label",
"position",
"entity"];
1178 foreach ($prodattr as $field => $value) {
1179 if (!in_array($field, $fields)) {
1180 unset($prodattr->{$field});
1184 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1185 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1186 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id).
" AND pac.entity IN (".
getEntity(
'product').
")";
1188 $resql = $this->db->query($sql);
1189 $obj = $this->db->fetch_object($resql);
1190 $prodattr->is_used_by_products = (int) $obj->nb;
1208 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1209 throw new RestException(403);
1214 $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').
")";
1216 $query = $this->db->query($sql);
1218 if (!$this->db->num_rows($query)) {
1219 throw new RestException(404);
1222 $result = $this->db->fetch_object($query);
1225 $attr[
'id'] = $result->rowid;
1226 $attr[
'ref'] = $result->ref;
1227 $attr[
'ref_ext'] = $result->ref_ext;
1228 $attr[
'label'] = $result->label;
1229 $attr[
'rang'] = $result->position;
1230 $attr[
'position'] = $result->position;
1231 $attr[
'entity'] = $result->entity;
1233 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1234 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1235 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1237 $resql = $this->db->query($sql);
1238 $obj = $this->db->fetch_object($resql);
1240 $attr[
"is_used_by_products"] = (int) $obj->nb;
1258 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1259 throw new RestException(403);
1262 $ref_ext = trim($ref_ext);
1264 $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').
")";
1266 $query = $this->db->query($sql);
1268 if (!$this->db->num_rows($query)) {
1269 throw new RestException(404);
1272 $result = $this->db->fetch_object($query);
1275 $attr[
'id'] = $result->rowid;
1276 $attr[
'ref'] = $result->ref;
1277 $attr[
'ref_ext'] = $result->ref_ext;
1278 $attr[
'label'] = $result->label;
1279 $attr[
'rang'] = $result->position;
1280 $attr[
'position'] = $result->position;
1281 $attr[
'entity'] = $result->entity;
1283 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1284 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1285 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1287 $resql = $this->db->query($sql);
1288 $obj = $this->db->fetch_object($resql);
1290 $attr[
"is_used_by_products"] = (int) $obj->nb;
1310 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1311 throw new RestException(403);
1315 $prodattr->label = $label;
1316 $prodattr->ref = $ref;
1317 $prodattr->ref_ext = $ref_ext;
1319 $resid = $prodattr->create(DolibarrApiAccess::$user);
1321 throw new RestException(500,
"Error creating new attribute");
1342 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1343 throw new RestException(403);
1348 $result = $prodattr->fetch((
int)
$id);
1350 throw new RestException(404,
'Attribute not found');
1351 } elseif ($result < 0) {
1352 throw new RestException(500,
"Error fetching attribute");
1355 foreach ($request_data as $field => $value) {
1356 if ($field ==
'rowid') {
1359 if ($field ===
'caller') {
1361 $prodattr->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1365 $prodattr->$field = $this->_checkValForAPI($field, $value, $prodattr);
1368 if ($prodattr->update(DolibarrApiAccess::$user) > 0) {
1369 $result = $prodattr->fetch((
int)
$id);
1371 throw new RestException(404,
'Attribute not found');
1372 } elseif ($result < 0) {
1373 throw new RestException(500,
"Error fetching attribute");
1375 return $this->_cleanObjectDatas($prodattr);
1378 throw new RestException(500,
"Error updating attribute");
1394 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1395 throw new RestException(403);
1399 $prodattr->id = (int)
$id;
1400 $result = $prodattr->delete(DolibarrApiAccess::$user);
1403 throw new RestException(500,
"Error deleting attribute");
1422 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1423 throw new RestException(403);
1426 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value WHERE rowid = ".(int)
$id.
" AND entity IN (".
getEntity(
'product').
")";
1428 $query = $this->db->query($sql);
1431 throw new RestException(403);
1434 if (!$this->db->num_rows($query)) {
1435 throw new RestException(404,
'Attribute value not found');
1438 $result = $this->db->fetch_object($query);
1441 $attrval[
'id'] = $result->rowid;
1442 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1443 $attrval[
'ref'] = $result->ref;
1444 $attrval[
'value'] = $result->value;
1463 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1464 throw new RestException(403);
1469 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value";
1470 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int)
$id).
" AND entity IN (".
getEntity(
'product').
")";
1472 $query = $this->db->query($sql);
1475 throw new RestException(403);
1478 if (!$this->db->num_rows($query)) {
1479 throw new RestException(404,
'Attribute value not found');
1482 $result = $this->db->fetch_object($query);
1485 $attrval[
'id'] = $result->rowid;
1486 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1487 $attrval[
'ref'] = $result->ref;
1488 $attrval[
'value'] = $result->value;
1506 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1507 throw new RestException(403);
1512 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"product_attribute_value";
1513 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int)
$id).
" AND entity IN (".
getEntity(
'product').
")";
1514 $query = $this->db->query($sql);
1517 throw new RestException(403);
1520 if (!$this->db->num_rows($query)) {
1521 throw new RestException(404,
'Attribute value not found');
1524 $result = $this->db->fetch_object($query);
1527 $attrval->id = $result->rowid;
1528 $result = $attrval->delete(DolibarrApiAccess::$user);
1533 throw new RestException(500,
"Error deleting attribute value");
1549 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1550 throw new RestException(403);
1555 $return = $objectval->fetchAllByProductAttribute((
int)
$id);
1557 if (count($return) == 0) {
1558 throw new RestException(404,
'Attribute values not found');
1561 foreach ($return as $key => $val) {
1562 $return[$key] = $this->_cleanObjectDatas($return[$key]);
1580 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1581 throw new RestException(403);
1589 $sql .=
"v.fk_product_attribute, v.rowid, v.ref, v.value FROM ".$this->db->prefix().
"product_attribute_value as v";
1590 $sql .=
" WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix().
"product_attribute WHERE ref LIKE '".$this->db->escape($ref).
"')";
1592 $resql = $this->db->query($sql);
1594 while ($result = $this->db->fetch_object($resql)) {
1596 $tmp->fk_product_attribute = $result->fk_product_attribute;
1597 $tmp->id = $result->rowid;
1598 $tmp->ref = $result->ref;
1599 $tmp->value = $result->value;
1601 $return[] = $this->_cleanObjectDatas($tmp);
1622 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1623 throw new RestException(403);
1626 if (empty($ref) || empty($value)) {
1627 throw new RestException(403);
1631 $objectval->fk_product_attribute = ((int)
$id);
1632 $objectval->ref = $ref;
1633 $objectval->value = $value;
1635 if ($objectval->create(DolibarrApiAccess::$user) > 0) {
1636 return $objectval->id;
1638 throw new RestException(500,
"Error creating new attribute value");
1655 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1656 throw new RestException(403);
1660 $result = $objectval->fetch((
int)
$id);
1663 throw new RestException(404,
'Attribute value not found');
1664 } elseif ($result < 0) {
1665 throw new RestException(500,
"Error fetching attribute value");
1668 foreach ($request_data as $field => $value) {
1669 if ($field ==
'rowid') {
1672 if ($field ===
'caller') {
1674 $objectval->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1678 $objectval->$field = $this->_checkValForAPI($field, $value, $objectval);
1681 if ($objectval->update(DolibarrApiAccess::$user) > 0) {
1682 $result = $objectval->fetch((
int)
$id);
1684 throw new RestException(404,
'Attribute not found');
1685 } elseif ($result < 0) {
1686 throw new RestException(500,
"Error fetching attribute");
1688 return $this->_cleanObjectDatas($objectval);
1691 throw new RestException(500,
"Error updating attribute");
1707 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1708 throw new RestException(403);
1712 $objectval->id = (int)
$id;
1714 if ($objectval->delete(DolibarrApiAccess::$user) > 0) {
1717 throw new RestException(500,
"Error deleting attribute value");
1734 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1735 throw new RestException(403);
1739 $combinations = $prodcomb->fetchAllByFkProductParent((
int)
$id);
1741 foreach ($combinations as $key => $combination) {
1743 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1744 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1746 if (!empty($includestock) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1747 $productModel =
new Product($this->db);
1748 $productModel->fetch((
int) $combination->fk_product_child);
1749 $productModel->load_stock($includestock);
1750 $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse;
1754 return $combinations;
1770 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1771 throw new RestException(403);
1774 $result = $this->product->fetch(0, $ref);
1776 throw new RestException(404,
'Product not found');
1780 $combinations = $prodcomb->fetchAllByFkProductParent((
int) $this->product->id);
1782 foreach ($combinations as $key => $combination) {
1784 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1785 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1788 return $combinations;
1811 public function addVariant(
$id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference =
'', $ref_ext =
'')
1813 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1814 throw new RestException(403);
1818 throw new RestException(400,
'Product ID is mandatory');
1821 if (empty($features) || !is_array($features)) {
1822 throw new RestException(400,
'Features is mandatory and should be IDs of attribute values indexed by IDs of attributes');
1825 $weight_impact =
price2num($weight_impact);
1826 $price_impact =
price2num($price_impact);
1830 foreach ($features as $id_attr => $id_value) {
1831 if ($prodattr->fetch((
int) $id_attr) < 0) {
1832 throw new RestException(400,
'Invalid attribute ID: '.$id_attr);
1834 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1835 throw new RestException(400,
'Invalid attribute value ID: '.$id_value);
1839 $result = $this->product->fetch((
int)
$id);
1841 throw new RestException(404,
'Product not found');
1846 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference, $ref_ext);
1850 throw new RestException(500,
"Error creating new product variant");
1874 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1875 throw new RestException(403);
1878 if (empty($ref) || empty($features) || !is_array($features)) {
1879 throw new RestException(403);
1882 $weight_impact =
price2num($weight_impact);
1883 $price_impact =
price2num($price_impact);
1887 foreach ($features as $id_attr => $id_value) {
1888 if ($prodattr->fetch((
int) $id_attr) < 0) {
1889 throw new RestException(404);
1891 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1892 throw new RestException(404);
1896 $result = $this->product->fetch(0, trim($ref));
1898 throw new RestException(404,
'Product not found');
1902 if (!$prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) {
1903 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact);
1907 throw new RestException(500,
"Error creating new product variant");
1910 return $prodcomb->id;
1928 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1929 throw new RestException(403);
1933 $prodcomb->fetch((
int)
$id);
1935 foreach ($request_data as $field => $value) {
1936 if ($field ==
'rowid') {
1939 if ($field ===
'caller') {
1941 $prodcomb->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1945 $prodcomb->$field = $this->_checkValForAPI($field, $value, $prodcomb);
1948 $result = $prodcomb->update(DolibarrApiAccess::$user);
1952 throw new RestException(500,
"Error editing variant");
1968 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1969 throw new RestException(403);
1973 $prodcomb->id = (int)
$id;
1974 $result = $prodcomb->delete(DolibarrApiAccess::$user);
1976 throw new RestException(500,
"Error deleting variant");
1997 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire') || !DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1998 throw new RestException(403);
2002 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2005 $product_model =
new Product($this->db);
2006 $product_model->fetch(
$id);
2007 $product_model->load_stock();
2009 $stockData = $this->_cleanObjectDatas($product_model)->stock_warehouse;
2011 if ($selected_warehouse_id) {
2012 foreach ($stockData as $warehouse_id => $warehouse) {
2013 if ($warehouse_id != $selected_warehouse_id) {
2014 unset($stockData[$warehouse_id]);
2018 $obj_ret = $this->_filterObjectProperties($this->_cleanObjectDatas($product_model),
'stock_warehouses,stock_reel,stock_theorique');
2019 $obj_ret->stock_warehouses = $stockData;
2040 unset(
$object->prices_by_qty_id);
2042 unset(
$object->product_id_already_linked);
2056 unset(
$object->fourn_price_base_type);
2060 unset(
$object->product_fourn_id);
2063 unset(
$object->mode_reglement_id);
2064 unset(
$object->cond_reglement_id);
2065 unset(
$object->demand_reason_id);
2066 unset(
$object->transport_mode_id);
2067 unset(
$object->cond_reglement);
2068 unset(
$object->shipping_method_id);
2073 unset(
$object->recuperableonly);
2074 unset(
$object->multiprices_recuperableonly);
2080 unset(
$object->supplierprices);
2082 if (!DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2084 unset(
$object->stock_theorique);
2085 unset(
$object->stock_warehouse);
2101 foreach (Products::$FIELDS as $field) {
2102 if (!isset($data[$field])) {
2103 throw new RestException(400,
"$field field missing");
2105 $product[$field] = $data[$field];
2129 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $barcode =
'', $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includeifobjectisused =
false, $includetrans =
false)
2131 if (empty(
$id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
2132 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
2137 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
2138 throw new RestException(403);
2141 $result = $this->product->fetch(
$id, $ref, $ref_ext, $barcode, 0, 0, ($includetrans ? 0 : 1));
2143 throw new RestException(404,
'Product not found');
2147 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2150 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2151 $this->product->load_stock($includestockdata);
2153 if (is_array($this->product->stock_warehouse)) {
2154 foreach ($this->product->stock_warehouse as $keytmp => $valtmp) {
2155 if (isset($this->product->stock_warehouse[$keytmp]->detail_batch) && is_array($this->product->stock_warehouse[$keytmp]->detail_batch)) {
2156 foreach ($this->product->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
2157 unset($this->product->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
2164 if ($includesubproducts) {
2165 $childrenArbo = $this->product->getChildsArbo(
$id, 1);
2167 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
2168 $children = array();
2169 foreach ($childrenArbo as $values) {
2170 $children[] = array_combine($keys, $values);
2173 $this->product->sousprods = $children;
2176 if ($includeparentid) {
2178 $this->product->fk_product_parent =
null;
2179 if (($fk_product_parent = $prodcomb->fetchByFkProductChild($this->product->id)) > 0) {
2180 $this->product->fk_product_parent = $fk_product_parent;
2184 if ($includeifobjectisused) {
2185 $this->product->is_object_used = ($this->product->isObjectUsed() > 0);
2188 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=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getDolGlobalString($key, $default='')
Return a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...