22use Luracast\Restler\RestException;
24require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
26require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductAttribute.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductAttributeValue.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination2ValuePair.class.php';
43 public static $FIELDS = array(
56 public $productsupplier;
66 $this->product =
new Product($this->db);
86 public function get(
$id, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
88 return $this->
_fetch(
$id,
'',
'',
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
110 public function getByRef($ref, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
112 return $this->
_fetch(0, $ref,
'',
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
134 public function getByRefExt($ref_ext, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
136 return $this->
_fetch(0,
'', $ref_ext,
'', $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
158 public function getByBarcode($barcode, $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includetrans =
false)
160 return $this->
_fetch(0,
'',
'', $barcode, $includestockdata, $includesubproducts, $includeparentid,
false, $includetrans);
182 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 =
'')
186 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
187 throw new RestException(403);
192 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
194 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
195 $sql .=
" FROM ".$this->db->prefix().
"product as t";
196 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON ef.fk_object = t.rowid";
198 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
200 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
202 if ($variant_filter == 1) {
203 $sql .=
' AND t.rowid not in (select distinct fk_product_parent from '.$this->db->prefix().
'product_attribute_combination)';
204 $sql .=
' AND t.rowid not in (select distinct fk_product_child from '.$this->db->prefix().
'product_attribute_combination)';
206 if ($variant_filter == 2) {
207 $sql .=
' AND t.rowid in (select distinct fk_product_parent from '.$this->db->prefix().
'product_attribute_combination)';
209 if ($variant_filter == 3) {
210 $sql .=
' AND t.rowid in (select distinct fk_product_child from '.$this->db->prefix().
'product_attribute_combination)';
215 $sql .=
" AND c.fk_categorie = ".((int) $category);
216 $sql .=
" AND c.fk_product = t.rowid";
220 $sql .=
" AND t.fk_product_type = 0";
221 } elseif ($mode == 2) {
223 $sql .=
" AND t.fk_product_type = 1";
231 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
236 $sqlTotals = str_replace(
'SELECT t.rowid, t.ref, t.ref_ext',
'SELECT count(t.rowid) as total', $sql);
238 $sql .= $this->db->order($sortfield, $sortorder);
243 $offset = $limit * $page;
245 $sql .= $this->db->plimit($limit + 1, $offset);
248 $result = $this->db->query($sql);
250 $num = $this->db->num_rows($result);
251 $min = min($num, ($limit <= 0 ? $num : $limit));
254 $obj = $this->db->fetch_object($result);
256 $product_static =
new Product($this->db);
257 if ($product_static->fetch($obj->rowid)) {
258 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
259 $product_static->load_stock();
261 if (is_array($product_static->stock_warehouse)) {
262 foreach ($product_static->stock_warehouse as $keytmp => $valtmp) {
263 if (isset($product_static->stock_warehouse[$keytmp]->detail_batch) && is_array($product_static->stock_warehouse[$keytmp]->detail_batch)) {
264 foreach ($product_static->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
265 unset($product_static->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
276 $obj_ret[] = $obj->rowid;
281 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
285 if ($pagination_data) {
286 $totalsResult = $this->db->query($sqlTotals);
287 $total = $this->db->fetch_object($totalsResult)->total;
292 $obj_ret[
'data'] = $tmp;
293 $obj_ret[
'pagination'] = array(
294 'total' => (
int) $total,
296 'page_count' => ceil((
int) $total / $limit),
310 public function post($request_data =
null)
312 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
313 throw new RestException(403);
316 $result = $this->
_validate($request_data);
318 foreach ($request_data as $field => $value) {
319 if ($field ===
'caller') {
321 $this->product->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
325 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
327 if ($this->product->create(DolibarrApiAccess::$user) < 0) {
328 throw new RestException(500,
"Error creating product", array_merge(array($this->product->error), $this->product->errors));
333 for ($key = 1; $key <= $key_max ; $key++) {
334 $newvat = $this->product->multiprices_tva_tx[$key];
336 $newvatsrccode = $this->product->default_vat_code;
337 $newprice = $this->product->multiprices[$key];
338 $newpricemin = $this->product->multiprices_min[$key];
339 $newbasetype = $this->product->multiprices_base_type[$key];
340 if (empty($newbasetype) || $newbasetype ==
'') {
341 $newbasetype = $this->product->price_base_type;
343 if ($newbasetype ==
'TTC') {
344 $newprice = $this->product->multiprices_ttc[$key];
345 $newpricemin = $this->product->multiprices_min_ttc[$key];
348 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
353 return $this->product->id;
369 public function put(
$id, $request_data =
null)
371 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
372 throw new RestException(403);
375 $result = $this->product->fetch(
$id);
377 throw new RestException(404,
'Product not found');
381 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
384 $oldproduct =
dol_clone($this->product, 2);
386 foreach ($request_data as $field => $value) {
387 if ($field ==
'id') {
390 if ($field ==
'stock_reel') {
391 throw new RestException(400,
'Stock reel cannot be updated here. Use the /stockmovements endpoint instead');
393 if ($field ===
'caller') {
395 $this->product->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
398 if ($field ==
'array_options' && is_array($value)) {
399 foreach ($value as $index => $val) {
400 $this->product->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->product);
405 $this->product->$field = $this->
_checkValForAPI($field, $value, $this->product);
409 if ($this->product->type != $oldproduct->type && ($this->product->isProduct() || $this->product->isService())) {
413 $result = $this->product->update(
$id, DolibarrApiAccess::$user, 1,
'update', $updatetype);
418 $pricemodified =
false;
419 if ($this->product->price_base_type != $oldproduct->price_base_type) {
420 $pricemodified =
true;
422 if ($this->product->tva_tx != $oldproduct->tva_tx) {
423 $pricemodified =
true;
425 if ($this->product->tva_npr != $oldproduct->tva_npr) {
426 $pricemodified =
true;
428 if (!empty($this->product->default_vat_code)) {
429 if ($this->product->default_vat_code != $oldproduct->default_vat_code) {
430 $pricemodified =
true;
434 if ($this->product->price_base_type ==
'TTC') {
435 if ($this->product->price_ttc != $oldproduct->price_ttc) {
436 $pricemodified =
true;
438 if ($this->product->price_min_ttc != $oldproduct->price_min_ttc) {
439 $pricemodified =
true;
442 if ($this->product->price != $oldproduct->price) {
443 $pricemodified =
true;
445 if ($this->product->price_min != $oldproduct->price_min) {
446 $pricemodified =
true;
451 if ($pricemodified) {
452 $newvat = $this->product->tva_tx;
453 $newnpr = $this->product->tva_npr;
454 $newvatsrccode = $this->product->default_vat_code;
456 $newprice = $this->product->price;
457 $newpricemin = $this->product->price_min;
458 if ($this->product->price_base_type ==
'TTC') {
459 $newprice = $this->product->price_ttc;
460 $newpricemin = $this->product->price_min_ttc;
463 $result = $this->product->updatePrice($newprice, $this->product->price_base_type, DolibarrApiAccess::$user, $newvat, $newpricemin, 0, $newnpr, 0, 0, array(), $newvatsrccode);
469 for ($key = 1; $key <= $key_max ; $key++) {
470 $pricemodified =
false;
471 if ($this->product->multiprices_base_type[$key] != $oldproduct->multiprices_base_type[$key]) {
472 $pricemodified =
true;
474 if ($this->product->multiprices_tva_tx[$key] != $oldproduct->multiprices_tva_tx[$key]) {
475 $pricemodified =
true;
477 if ($this->product->multiprices_base_type[$key] ==
'TTC') {
478 if ($this->product->multiprices_ttc[$key] != $oldproduct->multiprices_ttc[$key]) {
479 $pricemodified =
true;
481 if ($this->product->multiprices_min_ttc[$key] != $oldproduct->multiprices_min_ttc[$key]) {
482 $pricemodified =
true;
485 if ($this->product->multiprices[$key] != $oldproduct->multiprices[$key]) {
486 $pricemodified =
true;
488 if ($this->product->multiprices_min[$key] != $oldproduct->multiprices[$key]) {
489 $pricemodified =
true;
493 if ($pricemodified && $result > 0) {
494 $newvat = $this->product->multiprices_tva_tx[$key];
496 $newvatsrccode = $this->product->default_vat_code;
497 $newprice = $this->product->multiprices[$key];
498 $newpricemin = $this->product->multiprices_min[$key];
499 $newbasetype = $this->product->multiprices_base_type[$key];
500 if (empty($newbasetype) || $newbasetype ==
'') {
501 $newbasetype = $this->product->price_base_type;
503 if ($newbasetype ==
'TTC') {
504 $newprice = $this->product->multiprices_ttc[$key];
505 $newpricemin = $this->product->multiprices_min_ttc[$key];
508 $result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
514 throw new RestException(500,
"Error updating product", array_merge(array($this->product->error), $this->product->errors));
517 return $this->
get(
$id);
526 public function delete(
$id)
528 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
529 throw new RestException(403);
531 $result = $this->product->fetch(
$id);
533 throw new RestException(404,
'Product not found');
537 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
542 $user = DolibarrApiAccess::$user;
544 $res = $this->product->delete(DolibarrApiAccess::$user);
546 throw new RestException(500,
"Can't delete, error occurs");
547 } elseif ($res == 0) {
548 throw new RestException(409,
"Can't delete, that product is probably used");
554 'message' =>
'Object deleted'
573 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
574 throw new RestException(403);
578 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
581 $childrenArbo = $this->product->getChildsArbo(
$id, 1);
583 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
585 foreach ($childrenArbo as $values) {
586 $children[] = array_combine($keys, $values);
611 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
612 throw new RestException(403);
616 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
619 $result = $this->product->add_sousproduit(
$id, $subproduct_id, $qty, $incdec);
621 throw new RestException(500,
"Error adding product child");
641 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
642 throw new RestException(403);
646 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
649 $result = $this->product->del_sousproduit(
$id, $subproduct_id);
651 throw new RestException(500,
"Error while removing product child");
670 public function getCategories(
$id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
672 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
673 throw new RestException(403);
678 $result = $categories->getListForItem(
$id,
'product', $sortfield, $sortorder, $limit, $page);
681 throw new RestException(503,
'Error when retrieve category list : '.implode(
',', array_merge(array($categories->error), $categories->errors)));
700 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
701 throw new RestException(403);
705 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
708 $result = $this->product->fetch(
$id);
710 throw new RestException(404,
'Product not found');
714 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
718 'multiprices' => $this->product->multiprices,
719 'multiprices_inc_tax' => $this->product->multiprices_ttc,
720 'multiprices_min' => $this->product->multiprices_min,
721 'multiprices_min_inc_tax' => $this->product->multiprices_min_ttc,
722 'multiprices_vat' => $this->product->multiprices_tva_tx,
723 'multiprices_base_type' => $this->product->multiprices_base_type,
742 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
743 throw new RestException(403);
747 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
750 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
751 if ($socid > 0 && $socid != $thirdparty_id) {
752 throw new RestException(403,
'Getting prices for all customers or for the customer ID '.$thirdparty_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
755 $result = $this->product->fetch(
$id);
757 throw new RestException(404,
'Product not found');
761 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
764 $filter[
't.fk_product'] =
$id;
765 if ($thirdparty_id) {
766 $filter[
't.fk_soc'] = $thirdparty_id;
768 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
771 if (empty($prodcustprice->lines)) {
772 throw new RestException(404,
'Prices not found');
775 return $prodcustprice->lines;
791 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
792 throw new RestException(403);
796 throw new RestException(400,
'API not available: this mode of pricing is not enabled by setup');
799 $result = $this->product->fetch(
$id);
801 throw new RestException(404,
'Product not found');
805 throw new RestException(503,
'Error when retrieve prices list : '.implode(
',', array_merge(array($this->product->error), $this->product->errors)));
809 'prices_by_qty' => $this->product->prices_by_qty[0],
810 'prices_by_qty_list' => $this->product->prices_by_qty_list[0]
847 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)
849 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
850 throw new RestException(403);
853 $result = $this->productsupplier->fetch(
$id);
855 throw new RestException(404,
'Product not found');
859 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
862 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
863 if ($socid > 0 && $socid != $fourn_id) {
864 throw new RestException(403,
'Adding purchase price for the supplier ID '.$fourn_id.
' is not allowed for login '.DolibarrApiAccess::$user->login);
867 $result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
869 throw new RestException(500,
"Error adding supplier to product : ".$this->db->lasterror());
873 $result = $fourn->fetch($fourn_id);
875 throw new RestException(404,
'Supplier not found');
879 $ref_fourn =
sanitizeVal($ref_fourn,
'alphanohtml');
880 $desc_fourn =
sanitizeVal($desc_fourn,
'restricthtml');
883 $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);
886 throw new RestException(500,
"Error updating buy price : ".$this->db->lasterror());
888 return (
int) $this->productsupplier->product_fourn_price_id;
907 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
908 throw new RestException(403);
910 $result = $this->productsupplier->fetch(
$id);
912 throw new RestException(404,
'Product not found');
916 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
921 $resultsupplier = $this->productsupplier->remove_product_fournisseur_price($priceid);
924 return $resultsupplier;
942 public function getSupplierProducts($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $supplier = 0, $sqlfilters =
'')
946 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
947 throw new RestException(403);
953 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
955 if ($supplier != $socid || empty($supplier)) {
956 throw new RestException(403,
'As an external user, you can request only for your supplier id = '.$socid);
960 $sql =
"SELECT t.rowid, t.ref, t.ref_ext";
961 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product AS t LEFT JOIN ".MAIN_DB_PREFIX.
"product_extrafields AS ef ON (ef.fk_object = t.rowid)";
964 $sql .=
", ".$this->db->prefix().
"categorie_product as c";
966 $sql .=
", ".$this->db->prefix().
"product_fournisseur_price as s";
968 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
971 $sql .=
" AND s.fk_soc = ".((int) $supplier);
974 $sql .=
" AND s.fk_soc = ".((int) $socid);
976 $sql .=
" AND s.fk_product = t.rowid";
979 $sql .=
" AND c.fk_categorie = ".((int) $category);
980 $sql .=
" AND c.fk_product = t.rowid";
984 $sql .=
" AND t.fk_product_type = 0";
985 } elseif ($mode == 2) {
987 $sql .=
" AND t.fk_product_type = 1";
994 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
998 $sql .= $this->db->order($sortfield, $sortorder);
1003 $offset = $limit * $page;
1004 $sql .= $this->db->plimit($limit + 1, $offset);
1006 $result = $this->db->query($sql);
1008 $num = $this->db->num_rows($result);
1009 $min = min($num, ($limit <= 0 ? $num : $limit));
1012 $obj = $this->db->fetch_object($result);
1015 $product_fourn_list = $product_fourn->list_product_fournisseur_price($obj->rowid,
'',
'', 0, 0);
1016 foreach ($product_fourn_list as $tmpobj) {
1021 $obj_ret[$obj->rowid] = $product_fourn_list;
1026 throw new RestException(503,
'Error when retrieve product list : '.$this->db->lasterror());
1053 if (empty(
$id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
1054 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
1059 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1060 throw new RestException(403);
1063 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid :
'';
1065 $result = $this->product->fetch(
$id, $ref, $ref_ext, $barcode);
1067 throw new RestException(404,
'Product not found');
1071 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1074 $product_fourn_list = array();
1078 $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->product->id,
'',
'', 0, 0, ($socid > 0 ? $socid : 0));
1081 foreach ($product_fourn_list as $tmpobj) {
1105 public function getAttributes($sortfield =
"t.ref", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
1107 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1108 throw new RestException(403);
1111 $sql =
"SELECT t.rowid, t.ref, t.ref_ext, t.label, t.position, t.entity";
1112 $sql .=
" FROM ".$this->db->prefix().
"product_attribute as t";
1113 $sql .=
' WHERE t.entity IN ('.getEntity(
'product').
')';
1119 if ($errormessage) {
1120 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1124 $sql .= $this->db->order($sortfield, $sortorder);
1129 $offset = $limit * $page;
1131 $sql .= $this->db->plimit($limit, $offset);
1134 $resql = $this->db->query($sql);
1137 throw new RestException(503,
'Error when retrieving product attribute list : '.$this->db->lasterror());
1141 while ($obj = $this->db->fetch_object($resql)) {
1143 $tmp->id = $obj->rowid;
1144 $tmp->ref = $obj->ref;
1145 $tmp->ref_ext = $obj->ref_ext;
1146 $tmp->label = $obj->label;
1147 $tmp->position = $obj->position;
1148 $tmp->entity = $obj->entity;
1169 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1170 throw new RestException(403);
1174 $result = $prodattr->fetch((
int)
$id);
1177 throw new RestException(404,
"Product attribute not found");
1180 $fields = [
"id",
"ref",
"ref_ext",
"label",
"position",
"entity"];
1182 foreach ($prodattr as $field => $value) {
1183 if (!in_array($field, $fields)) {
1184 unset($prodattr->{$field});
1188 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1189 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1190 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id).
" AND pac.entity IN (".
getEntity(
'product').
")";
1192 $resql = $this->db->query($sql);
1193 $obj = $this->db->fetch_object($resql);
1194 $prodattr->is_used_by_products = (int) $obj->nb;
1212 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1213 throw new RestException(403);
1218 $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').
")";
1220 $query = $this->db->query($sql);
1222 if (!$this->db->num_rows($query)) {
1223 throw new RestException(404);
1226 $result = $this->db->fetch_object($query);
1229 $attr[
'id'] = $result->rowid;
1230 $attr[
'ref'] = $result->ref;
1231 $attr[
'ref_ext'] = $result->ref_ext;
1232 $attr[
'label'] = $result->label;
1233 $attr[
'rang'] = $result->position;
1234 $attr[
'position'] = $result->position;
1235 $attr[
'entity'] = $result->entity;
1237 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1238 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1239 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1241 $resql = $this->db->query($sql);
1242 $obj = $this->db->fetch_object($resql);
1244 $attr[
"is_used_by_products"] = (int) $obj->nb;
1262 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1263 throw new RestException(403);
1266 $ref_ext = trim($ref_ext);
1268 $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').
")";
1270 $query = $this->db->query($sql);
1272 if (!$this->db->num_rows($query)) {
1273 throw new RestException(404);
1276 $result = $this->db->fetch_object($query);
1279 $attr[
'id'] = $result->rowid;
1280 $attr[
'ref'] = $result->ref;
1281 $attr[
'ref_ext'] = $result->ref_ext;
1282 $attr[
'label'] = $result->label;
1283 $attr[
'rang'] = $result->position;
1284 $attr[
'position'] = $result->position;
1285 $attr[
'entity'] = $result->entity;
1287 $sql =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"product_attribute_combination2val as pac2v";
1288 $sql .=
" JOIN ".$this->db->prefix().
"product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
1289 $sql .=
" WHERE pac2v.fk_prod_attr = ".((int) $result->rowid).
" AND pac.entity IN (".
getEntity(
'product').
")";
1291 $resql = $this->db->query($sql);
1292 $obj = $this->db->fetch_object($resql);
1294 $attr[
"is_used_by_products"] = (int) $obj->nb;
1314 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1315 throw new RestException(403);
1319 $prodattr->label = $label;
1320 $prodattr->ref = $ref;
1321 $prodattr->ref_ext = $ref_ext;
1323 $resid = $prodattr->create(DolibarrApiAccess::$user);
1325 throw new RestException(500,
"Error creating new attribute");
1346 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1347 throw new RestException(403);
1352 $result = $prodattr->fetch((
int)
$id);
1354 throw new RestException(404,
'Attribute not found');
1355 } elseif ($result < 0) {
1356 throw new RestException(500,
"Error fetching attribute");
1359 foreach ($request_data as $field => $value) {
1360 if ($field ==
'rowid') {
1363 if ($field ===
'caller') {
1365 $prodattr->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1369 $prodattr->$field = $this->_checkValForAPI($field, $value, $prodattr);
1372 if ($prodattr->update(DolibarrApiAccess::$user) > 0) {
1373 $result = $prodattr->fetch((
int)
$id);
1375 throw new RestException(404,
'Attribute not found');
1376 } elseif ($result < 0) {
1377 throw new RestException(500,
"Error fetching attribute");
1379 return $this->_cleanObjectDatas($prodattr);
1382 throw new RestException(500,
"Error updating attribute");
1398 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1399 throw new RestException(403);
1403 $prodattr->id = (int)
$id;
1404 $result = $prodattr->delete(DolibarrApiAccess::$user);
1407 throw new RestException(500,
"Error deleting attribute");
1426 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1427 throw new RestException(403);
1430 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value WHERE rowid = ".(int)
$id.
" AND entity IN (".
getEntity(
'product').
")";
1432 $query = $this->db->query($sql);
1435 throw new RestException(403);
1438 if (!$this->db->num_rows($query)) {
1439 throw new RestException(404,
'Attribute value not found');
1442 $result = $this->db->fetch_object($query);
1445 $attrval[
'id'] = $result->rowid;
1446 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1447 $attrval[
'ref'] = $result->ref;
1448 $attrval[
'value'] = $result->value;
1467 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1468 throw new RestException(403);
1473 $sql =
"SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix().
"product_attribute_value";
1474 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int)
$id).
" AND entity IN (".
getEntity(
'product').
")";
1476 $query = $this->db->query($sql);
1479 throw new RestException(403);
1482 if (!$this->db->num_rows($query)) {
1483 throw new RestException(404,
'Attribute value not found');
1486 $result = $this->db->fetch_object($query);
1489 $attrval[
'id'] = $result->rowid;
1490 $attrval[
'fk_product_attribute'] = $result->fk_product_attribute;
1491 $attrval[
'ref'] = $result->ref;
1492 $attrval[
'value'] = $result->value;
1510 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1511 throw new RestException(403);
1516 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"product_attribute_value";
1517 $sql .=
" WHERE ref LIKE '".$this->db->escape($ref).
"' AND fk_product_attribute = ".((int)
$id).
" AND entity IN (".
getEntity(
'product').
")";
1518 $query = $this->db->query($sql);
1521 throw new RestException(403);
1524 if (!$this->db->num_rows($query)) {
1525 throw new RestException(404,
'Attribute value not found');
1528 $result = $this->db->fetch_object($query);
1531 $attrval->id = $result->rowid;
1532 $result = $attrval->delete(DolibarrApiAccess::$user);
1537 throw new RestException(500,
"Error deleting attribute value");
1553 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1554 throw new RestException(403);
1559 $return = $objectval->fetchAllByProductAttribute((
int)
$id);
1561 if (count($return) == 0) {
1562 throw new RestException(404,
'Attribute values not found');
1565 foreach ($return as $key => $val) {
1566 $return[$key] = $this->_cleanObjectDatas($return[$key]);
1584 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1585 throw new RestException(403);
1593 $sql .=
"v.fk_product_attribute, v.rowid, v.ref, v.value FROM ".$this->db->prefix().
"product_attribute_value as v";
1594 $sql .=
" WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix().
"product_attribute WHERE ref LIKE '".$this->db->escape($ref).
"')";
1596 $resql = $this->db->query($sql);
1598 while ($result = $this->db->fetch_object($resql)) {
1600 $tmp->fk_product_attribute = $result->fk_product_attribute;
1601 $tmp->id = $result->rowid;
1602 $tmp->ref = $result->ref;
1603 $tmp->value = $result->value;
1605 $return[] = $this->_cleanObjectDatas($tmp);
1626 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1627 throw new RestException(403);
1630 if (empty($ref) || empty($value)) {
1631 throw new RestException(403);
1635 $objectval->fk_product_attribute = ((int)
$id);
1636 $objectval->ref = $ref;
1637 $objectval->value = $value;
1639 if ($objectval->create(DolibarrApiAccess::$user) > 0) {
1640 return $objectval->id;
1642 throw new RestException(500,
"Error creating new attribute value");
1659 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1660 throw new RestException(403);
1664 $result = $objectval->fetch((
int)
$id);
1667 throw new RestException(404,
'Attribute value not found');
1668 } elseif ($result < 0) {
1669 throw new RestException(500,
"Error fetching attribute value");
1672 foreach ($request_data as $field => $value) {
1673 if ($field ==
'rowid') {
1676 if ($field ===
'caller') {
1678 $objectval->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1682 $objectval->$field = $this->_checkValForAPI($field, $value, $objectval);
1685 if ($objectval->update(DolibarrApiAccess::$user) > 0) {
1686 $result = $objectval->fetch((
int)
$id);
1688 throw new RestException(404,
'Attribute not found');
1689 } elseif ($result < 0) {
1690 throw new RestException(500,
"Error fetching attribute");
1692 return $this->_cleanObjectDatas($objectval);
1695 throw new RestException(500,
"Error updating attribute");
1711 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1712 throw new RestException(403);
1716 $objectval->id = (int)
$id;
1718 if ($objectval->delete(DolibarrApiAccess::$user) > 0) {
1721 throw new RestException(500,
"Error deleting attribute value");
1738 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1739 throw new RestException(403);
1743 $combinations = $prodcomb->fetchAllByFkProductParent((
int)
$id);
1745 foreach ($combinations as $key => $combination) {
1747 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1748 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1750 if (!empty($includestock) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
1751 $productModel =
new Product($this->db);
1752 $productModel->fetch((
int) $combination->fk_product_child);
1753 $productModel->load_stock($includestock);
1754 $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse;
1758 return $combinations;
1774 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
1775 throw new RestException(403);
1778 $result = $this->product->fetch(0, $ref);
1780 throw new RestException(404,
'Product not found');
1784 $combinations = $prodcomb->fetchAllByFkProductParent((
int) $this->product->id);
1786 foreach ($combinations as $key => $combination) {
1788 $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((
int) $combination->id);
1789 $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]);
1792 return $combinations;
1815 public function addVariant(
$id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference =
'', $ref_ext =
'')
1817 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1818 throw new RestException(403);
1822 throw new RestException(400,
'Product ID is mandatory');
1825 if (empty($features) || !is_array($features)) {
1826 throw new RestException(400,
'Features is mandatory and should be IDs of attribute values indexed by IDs of attributes');
1829 $weight_impact =
price2num($weight_impact);
1830 $price_impact =
price2num($price_impact);
1834 foreach ($features as $id_attr => $id_value) {
1835 if ($prodattr->fetch((
int) $id_attr) < 0) {
1836 throw new RestException(400,
'Invalid attribute ID: '.$id_attr);
1838 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1839 throw new RestException(400,
'Invalid attribute value ID: '.$id_value);
1843 $result = $this->product->fetch((
int)
$id);
1845 throw new RestException(404,
'Product not found');
1850 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference, $ref_ext);
1854 throw new RestException(500,
"Error creating new product variant");
1878 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1879 throw new RestException(403);
1882 if (empty($ref) || empty($features) || !is_array($features)) {
1883 throw new RestException(403);
1886 $weight_impact =
price2num($weight_impact);
1887 $price_impact =
price2num($price_impact);
1891 foreach ($features as $id_attr => $id_value) {
1892 if ($prodattr->fetch((
int) $id_attr) < 0) {
1893 throw new RestException(404);
1895 if ($prodattr_val->fetch((
int) $id_value) < 0) {
1896 throw new RestException(404);
1900 $result = $this->product->fetch(0, trim($ref));
1902 throw new RestException(404,
'Product not found');
1906 if (!$prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) {
1907 $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact);
1911 throw new RestException(500,
"Error creating new product variant");
1914 return $prodcomb->id;
1932 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'creer')) {
1933 throw new RestException(403);
1937 $prodcomb->fetch((
int)
$id);
1939 foreach ($request_data as $field => $value) {
1940 if ($field ==
'rowid') {
1943 if ($field ===
'caller') {
1945 $prodcomb->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
1949 $prodcomb->$field = $this->_checkValForAPI($field, $value, $prodcomb);
1952 $result = $prodcomb->update(DolibarrApiAccess::$user);
1956 throw new RestException(500,
"Error editing variant");
1972 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'supprimer')) {
1973 throw new RestException(403);
1977 $prodcomb->id = (int)
$id;
1978 $result = $prodcomb->delete(DolibarrApiAccess::$user);
1980 throw new RestException(500,
"Error deleting variant");
2001 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire') || !DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2002 throw new RestException(403);
2006 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2009 $product_model =
new Product($this->db);
2010 $product_model->fetch(
$id);
2011 $product_model->load_stock();
2013 $stockData = $this->_cleanObjectDatas($product_model)->stock_warehouse;
2015 if ($selected_warehouse_id) {
2016 foreach ($stockData as $warehouse_id => $warehouse) {
2017 if ($warehouse_id != $selected_warehouse_id) {
2018 unset($stockData[$warehouse_id]);
2022 $obj_ret = $this->_filterObjectProperties($this->_cleanObjectDatas($product_model),
'stock_warehouses,stock_reel,stock_theorique');
2023 $obj_ret->stock_warehouses = $stockData;
2044 unset(
$object->prices_by_qty_id);
2046 unset(
$object->product_id_already_linked);
2060 unset(
$object->fourn_price_base_type);
2064 unset(
$object->product_fourn_id);
2067 unset(
$object->mode_reglement_id);
2068 unset(
$object->cond_reglement_id);
2069 unset(
$object->demand_reason_id);
2070 unset(
$object->transport_mode_id);
2071 unset(
$object->cond_reglement);
2072 unset(
$object->shipping_method_id);
2077 unset(
$object->recuperableonly);
2078 unset(
$object->multiprices_recuperableonly);
2084 unset(
$object->supplierprices);
2086 if (!DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2088 unset(
$object->stock_theorique);
2089 unset(
$object->stock_warehouse);
2105 foreach (Products::$FIELDS as $field) {
2106 if (!isset($data[$field])) {
2107 throw new RestException(400,
"$field field missing");
2109 $product[$field] = $data[$field];
2133 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $barcode =
'', $includestockdata = 0, $includesubproducts =
false, $includeparentid =
false, $includeifobjectisused =
false, $includetrans =
false)
2135 if (empty(
$id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
2136 throw new RestException(400,
'bad value for parameter id, ref, ref_ext or barcode');
2141 if (!DolibarrApiAccess::$user->hasRight(
'produit',
'lire')) {
2142 throw new RestException(403);
2145 $result = $this->product->fetch(
$id, $ref, $ref_ext, $barcode, 0, 0, ($includetrans ? 0 : 1));
2147 throw new RestException(404,
'Product not found');
2151 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2154 if (!empty($includestockdata) && DolibarrApiAccess::$user->hasRight(
'stock',
'lire')) {
2155 $this->product->load_stock($includestockdata);
2157 if (is_array($this->product->stock_warehouse)) {
2158 foreach ($this->product->stock_warehouse as $keytmp => $valtmp) {
2159 if (isset($this->product->stock_warehouse[$keytmp]->detail_batch) && is_array($this->product->stock_warehouse[$keytmp]->detail_batch)) {
2160 foreach ($this->product->stock_warehouse[$keytmp]->detail_batch as $keytmp2 => $valtmp2) {
2161 unset($this->product->stock_warehouse[$keytmp]->detail_batch[$keytmp2]->db);
2168 if ($includesubproducts) {
2169 $childrenArbo = $this->product->getChildsArbo(
$id, 1);
2171 $keys = array(
'rowid',
'qty',
'fk_product_type',
'label',
'incdec',
'ref',
'fk_association',
'rang');
2172 $children = array();
2173 foreach ($childrenArbo as $values) {
2174 $children[] = array_combine($keys, $values);
2177 $this->product->sousprods = $children;
2180 if ($includeparentid) {
2182 $this->product->fk_product_parent =
null;
2183 if (($fk_product_parent = $prodcomb->fetchByFkProductChild($this->product->id)) > 0) {
2184 $this->product->fk_product_parent = $fk_product_parent;
2188 if ($includeifobjectisused) {
2189 $this->product->is_object_used = ($this->product->isObjectUsed() > 0);
2192 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...