27if (!defined(
'NOCSRFCHECK')) {
28 define(
'NOCSRFCHECK',
'1');
30if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL',
'1');
33if (!defined(
'NOREQUIREMENU')) {
34 define(
'NOREQUIREMENU',
'1');
36if (!defined(
'NOREQUIREHTML')) {
37 define(
'NOREQUIREHTML',
'1');
39if (!defined(
'NOREQUIREAJAX')) {
40 define(
'NOREQUIREAJAX',
'1');
42if (!defined(
"NOLOGIN")) {
43 define(
"NOLOGIN",
'1');
45if (!defined(
"NOSESSION")) {
46 define(
"NOSESSION",
'1');
49require
'../main.inc.php';
50require_once NUSOAP_PATH.
'/nusoap.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
56require_once DOL_DOCUMENT_ROOT.
"/categories/class/categorie.class.php";
57require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
61dol_syslog(
"Call Dolibarr webservices interfaces");
67 $langs->load(
"admin");
68 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
69 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
70 print $langs->trans(
"ToActivateModule");
75$server =
new nusoap_server();
76$server->soap_defencoding =
'UTF-8';
77$server->decode_utf8 =
false;
78$ns =
'http://www.dolibarr.org/ns/';
79$server->configureWSDL(
'WebServicesDolibarrProductOrService', $ns);
80$server->wsdl->schemaTargetNamespace = $ns;
84$server->wsdl->addComplexType(
91 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
92 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
93 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
94 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
95 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string')
99$server->wsdl->addComplexType(
106 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
107 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string')
111$productorservice_fields = array(
112 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
113 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
114 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
115 'type' => array(
'name'=>
'type',
'type'=>
'xsd:string'),
116 'label' => array(
'name'=>
'label',
'type'=>
'xsd:string'),
117 'description' => array(
'name'=>
'description',
'type'=>
'xsd:string'),
118 'date_creation' => array(
'name'=>
'date_creation',
'type'=>
'xsd:dateTime'),
119 'date_modification' => array(
'name'=>
'date_modification',
'type'=>
'xsd:dateTime'),
120 'note' => array(
'name'=>
'note',
'type'=>
'xsd:string'),
121 'status_tobuy' => array(
'name'=>
'status_tobuy',
'type'=>
'xsd:string'),
122 'status_tosell' => array(
'name'=>
'status_tosell',
'type'=>
'xsd:string'),
123 'barcode' => array(
'name'=>
'barcode',
'type'=>
'xsd:string'),
124 'barcode_type' => array(
'name'=>
'barcode_type',
'type'=>
'xsd:string'),
125 'country_id' => array(
'name'=>
'country_id',
'type'=>
'xsd:string'),
126 'country_code' => array(
'name'=>
'country_code',
'type'=>
'xsd:string'),
127 'customcode' => array(
'name'=>
'customcode',
'type'=>
'xsd:string'),
129 'price_net' => array(
'name'=>
'price_net',
'type'=>
'xsd:string'),
130 'price' => array(
'name'=>
'price',
'type'=>
'xsd:string'),
131 'price_min_net' => array(
'name'=>
'price_min_net',
'type'=>
'xsd:string'),
132 'price_min' => array(
'name'=>
'price_min',
'type'=>
'xsd:string'),
134 'price_base_type' => array(
'name'=>
'price_base_type',
'type'=>
'xsd:string'),
136 'vat_rate' => array(
'name'=>
'vat_rate',
'type'=>
'xsd:string'),
137 'vat_npr' => array(
'name'=>
'vat_npr',
'type'=>
'xsd:string'),
138 'localtax1_tx' => array(
'name'=>
'localtax1_tx',
'type'=>
'xsd:string'),
139 'localtax2_tx' => array(
'name'=>
'localtax2_tx',
'type'=>
'xsd:string'),
141 'stock_alert' => array(
'name'=>
'stock_alert',
'type'=>
'xsd:string'),
142 'stock_real' => array(
'name'=>
'stock_real',
'type'=>
'xsd:string'),
143 'stock_pmp' => array(
'name'=>
'stock_pmp',
'type'=>
'xsd:string'),
144 'warehouse_ref' => array(
'name'=>
'warehouse_ref',
'type'=>
'xsd:string'),
146 'canvas' => array(
'name'=>
'canvas',
'type'=>
'xsd:string'),
147 'import_key' => array(
'name'=>
'import_key',
'type'=>
'xsd:string'),
149 'dir' => array(
'name'=>
'dir',
'type'=>
'xsd:string'),
150 'images' => array(
'name'=>
'images',
'type'=>
'tns:ImagesArray')
154$elementtype =
'product';
160$extrafields->fetch_name_optionals_label($elementtype,
true);
161$extrafield_array =
null;
162if (is_array($extrafields) && count($extrafields) > 0) {
163 $extrafield_array = array();
165if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
166 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
167 $type = $extrafields->attributes[$elementtype][
'type'][$key];
168 if ($type ==
'date' || $type ==
'datetime') {
169 $type =
'xsd:dateTime';
171 $type =
'xsd:string';
174 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
178if (!empty($extrafield_array) && is_array($extrafield_array)) {
179 $productorservice_fields = array_merge($productorservice_fields, $extrafield_array);
183$server->wsdl->addComplexType(
189 $productorservice_fields
196$server->wsdl->addComplexType(
205 'type' =>
'tns:image',
207 'maxOccurs' =>
'unbounded'
215$server->wsdl->addComplexType(
222 'photo' => array(
'name'=>
'photo',
'type'=>
'xsd:string'),
223 'photo_vignette' => array(
'name'=>
'photo_vignette',
'type'=>
'xsd:string'),
224 'imgWidth' => array(
'name'=>
'imgWidth',
'type'=>
'xsd:string'),
225 'imgHeight' => array(
'name'=>
'imgHeight',
'type'=>
'xsd:string')
231$server->wsdl->addComplexType(
239 'type' => array(
'name'=>
'type',
'type'=>
'xsd:string'),
240 'status_tobuy' => array(
'name'=>
'status_tobuy',
'type'=>
'xsd:string'),
241 'status_tosell' => array(
'name'=>
'status_tosell',
'type'=>
'xsd:string'),
245$server->wsdl->addComplexType(
254 'type' =>
'tns:product',
256 'maxOccurs' =>
'unbounded'
266$styleuse =
'encoded';
272 'getProductOrService',
274 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string',
'lang'=>
'xsd:string'),
276 array(
'result'=>
'tns:result',
'product'=>
'tns:product'),
278 $ns.
'#getProductOrService',
281 'WS to get product or service'
286 'createProductOrService',
288 array(
'authentication'=>
'tns:authentication',
'product'=>
'tns:product'),
290 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
292 $ns.
'#createProductOrService',
295 'WS to create a product or service'
300 'updateProductOrService',
302 array(
'authentication'=>
'tns:authentication',
'product'=>
'tns:product'),
304 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
306 $ns.
'#updateProductOrService',
309 'WS to update a product or service'
314 'deleteProductOrService',
316 array(
'authentication'=>
'tns:authentication',
'listofid'=>
'xsd:string'),
318 array(
'result'=>
'tns:result',
'nbdeleted'=>
'xsd:int'),
320 $ns.
'#deleteProductOrService',
323 'WS to delete a product or service'
328 'getListOfProductsOrServices',
330 array(
'authentication'=>
'tns:authentication',
'filterproduct'=>
'tns:filterproduct'),
332 array(
'result'=>
'tns:result',
'products'=>
'tns:ProductsArray2'),
334 $ns.
'#getListOfProductsOrServices',
337 'WS to get list of all products or services id and ref'
342 'getProductsForCategory',
344 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'lang'=>
'xsd:string'),
346 array(
'result'=>
'tns:result',
'products'=>
'tns:ProductsArray2'),
348 $ns.
'#getProductsForCategory',
351 'WS to get list of all products or services for a category'
367 global $db, $conf, $langs;
369 dol_syslog(
"Function: getProductOrService login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
371 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
372 $langs->setDefaultLang($langcode);
374 if ($authentication[
'entity']) {
375 $conf->entity = $authentication[
'entity'];
379 $objectresp = array();
385 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
387 $errorcode =
'BAD_PARAMETERS';
388 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
392 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
393 $langs->setDefaultLang($langcode);
398 if ($fuser->hasRight(
'produit',
'lire') || $fuser->hasRight(
'service',
'lire')) {
400 $result = $product->fetch($id, $ref, $ref_ext);
403 $product->load_stock();
405 $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
406 $pdir =
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->ref.
"/";
407 $dir = $dir.
'/'.$pdir;
409 if (!empty($product->multilangs[$langs->defaultlang][
"label"])) {
410 $product->label = $product->multilangs[$langs->defaultlang][
"label"];
412 if (!empty($product->multilangs[$langs->defaultlang][
"description"])) {
413 $product->description = $product->multilangs[$langs->defaultlang][
"description"];
415 if (!empty($product->multilangs[$langs->defaultlang][
"note"])) {
416 $product->note = $product->multilangs[$langs->defaultlang][
"note"];
419 $productorservice_result_fields = array(
420 'id' => $product->id,
421 'ref' => $product->ref,
422 'ref_ext' => $product->ref_ext,
423 'label' => $product->label,
424 'description' => $product->description,
425 'date_creation' =>
dol_print_date($product->date_creation,
'dayhourrfc'),
426 'date_modification' =>
dol_print_date($product->date_modification,
'dayhourrfc'),
427 'note' => $product->note,
428 'status_tosell' => $product->status,
429 'status_tobuy' => $product->status_buy,
430 'type' => $product->type,
431 'barcode' => $product->barcode,
432 'barcode_type' => $product->barcode_type,
433 'country_id' => $product->country_id > 0 ? $product->country_id :
'',
434 'country_code' => $product->country_code,
435 'custom_code' => $product->customcode,
437 'price_net' => $product->price,
438 'price' => $product->price_ttc,
439 'price_min_net' => $product->price_min,
440 'price_min' => $product->price_min_ttc,
441 'price_base_type' => $product->price_base_type,
442 'vat_rate' => $product->tva_tx,
444 'vat_npr' => $product->tva_npr,
446 'localtax1_tx' => $product->localtax1_tx,
447 'localtax2_tx' => $product->localtax2_tx,
449 'stock_real' => $product->stock_reel,
450 'stock_virtual' => $product->stock_theorique,
451 'stock_alert' => $product->seuil_stock_alerte,
452 'pmp' => $product->pmp,
453 'import_key' => $product->import_key,
455 'images' => $product->liste_photos($dir, $nbmax)
458 $elementtype =
'product';
463 $extrafields->fetch_name_optionals_label($elementtype,
true);
465 $product->fetch_optionals();
467 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
468 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
469 $productorservice_result_fields = array_merge($productorservice_result_fields, array(
'options_'.$key => $product->array_options[
'options_'.$key]));
475 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
476 'product'=>$productorservice_result_fields
480 $errorcode =
'NOT_FOUND';
481 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
485 $errorcode =
'PERMISSION_DENIED';
486 $errorlabel =
'User does not have permission for this request';
491 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
511 dol_syslog(
"Function: createProductOrService login=".$authentication[
'login']);
513 if ($authentication[
'entity']) {
514 $conf->entity = $authentication[
'entity'];
518 $objectresp = array();
524 if (empty($product[
'price_base_type'])) {
525 if (isset($product[
'price_net']) && $product[
'price_net'] > 0) {
526 $product[
'price_base_type'] =
'HT';
528 if (isset($product[
'price']) && $product[
'price'] > 0) {
529 $product[
'price_base_type'] =
'TTC';
533 if (isset($product[
'price_net']) && $product[
'price_net'] > 0 && isset($product[
'price']) && $product[
'price'] > 0) {
536 $errorlabel =
"You must choose between price or price_net to provide price.";
539 if (!empty($product[
'barcode']) && empty($product[
'barcode_type'])) {
542 $errorlabel =
"You must set a barcode type when setting a barcode.";
546 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
549 $newobject->ref = $product[
'ref'];
550 $newobject->ref_ext = empty($product[
'ref_ext']) ?
'' : $product[
'ref_ext'];
551 $newobject->type = empty($product[
'type']) ? 0 : $product[
'type'];
552 $newobject->label = empty($product[
'label']) ?
'' : $product[
'label'];
553 $newobject->description = empty($product[
'description']) ?
'' : $product[
'description'];
554 $newobject->note_public = empty($product[
'note_public']) ?
'' : $product[
'note_public'];
555 $newobject->note_private = empty($product[
'note_private']) ?
'' : $product[
'note_private'];
556 $newobject->status = empty($product[
'status_tosell']) ? 0 : $product[
'status_tosell'];
557 $newobject->status_buy = empty($product[
'status_tobuy']) ? 0 : $product[
'status_tobuy'];
558 $newobject->price = isset($product[
'price_net']) ? $product[
'price_net'] : 0;
559 $newobject->price_ttc = isset($product[
'price']) ? $product[
'price'] : 0;
560 $newobject->tva_tx = empty($product[
'vat_rate']) ? 0 : $product[
'vat_rate'];
561 $newobject->price_base_type = $product[
'price_base_type'];
562 $newobject->date_creation = $now;
564 if (!empty($product[
'barcode'])) {
565 $newobject->barcode = $product[
'barcode'];
566 $newobject->barcode_type = $product[
'barcode_type'];
569 $newobject->stock_reel = isset($product[
'stock_real']) ? $product[
'stock_real'] :
null;
570 $newobject->pmp = isset($product[
'pmp']) ? $product[
'pmp'] :
null;
571 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? $product[
'stock_alert'] :
null;
573 $newobject->country_id = isset($product[
'country_id']) ? $product[
'country_id'] : 0;
574 if (!empty($product[
'country_code'])) {
575 $newobject->country_id =
getCountry($product[
'country_code'], 3);
577 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
579 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
596 $elementtype =
'product';
599 $extrafields->fetch_name_optionals_label($elementtype,
true);
600 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
601 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
602 $key =
'options_'.$key;
603 $newobject->array_options[$key] = $product[$key];
609 $result = $newobject->create($fuser, 0);
616 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && !empty($conf->global->stock->enabled)) {
617 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
619 $savstockreal = $newobject->stock_reel;
620 $newobject->load_stock(
'novirtual,nobatch');
621 $getstockreal = $newobject->stock_reel;
623 if ($savstockreal != $getstockreal) {
625 $warehouse->fetch(0, $product[
'warehouse_ref']);
626 if ($warehouse->id > 0) {
627 if (($savstockreal - $getstockreal) > 0) {
628 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
630 if (($savstockreal - $getstockreal) > 0) {
631 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
635 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
639 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
647 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
652 $errorlabel = $newobject->error;
657 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
677 dol_syslog(
"Function: updateProductOrService login=".$authentication[
'login']);
679 if ($authentication[
'entity']) {
680 $conf->entity = $authentication[
'entity'];
684 $objectresp = array();
690 if ($product[
'price_net'] > 0) {
691 $product[
'price_base_type'] =
'HT';
693 if ($product[
'price'] > 0) {
694 $product[
'price_base_type'] =
'TTC';
697 if ($product[
'price_net'] > 0 && $product[
'price'] > 0) {
700 $errorlabel =
"You must choose between price or price_net to provide price.";
704 if ($product[
'barcode'] && !$product[
'barcode_type']) {
707 $errorlabel =
"You must set a barcode type when setting a barcode.";
711 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
714 $newobject->fetch($product[
'id']);
716 if (isset($product[
'ref'])) {
717 $newobject->ref = $product[
'ref'];
719 if (isset($product[
'ref_ext'])) {
720 $newobject->ref_ext = $product[
'ref_ext'];
722 $newobject->type = $product[
'type'];
723 $newobject->label = $product[
'label'];
724 $newobject->description = $product[
'description'];
725 $newobject->note = $product[
'note'];
726 $newobject->status = $product[
'status_tosell'];
727 $newobject->status_buy = $product[
'status_tobuy'];
728 $newobject->price = $product[
'price_net'];
729 $newobject->price_ttc = $product[
'price'];
730 $newobject->tva_tx = $product[
'vat_rate'];
731 $newobject->price_base_type = $product[
'price_base_type'];
732 $newobject->date_creation = $now;
734 if ($product[
'barcode']) {
735 $newobject->barcode = $product[
'barcode'];
736 $newobject->barcode_type = $product[
'barcode_type'];
739 $newobject->stock_reel = isset($product[
'stock_real']) ? $product[
'stock_real'] :
null;
740 $newobject->pmp = isset($product[
'pmp']) ? $product[
'pmp'] :
null;
741 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? $product[
'stock_alert'] :
null;
743 $newobject->country_id = isset($product[
'country_id']) ? $product[
'country_id'] : 0;
744 if (!empty($product[
'country_code'])) {
745 $newobject->country_id =
getCountry($product[
'country_code'], 3);
747 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
749 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
751 $elementtype =
'product';
754 $extrafields->fetch_name_optionals_label($elementtype,
true);
755 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
756 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
757 $key =
'options_'.$key;
758 $newobject->array_options[$key] = $product[$key];
764 $result = $newobject->update($newobject->id, $fuser);
769 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && !empty($conf->global->stock->enabled)) {
770 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
772 $savstockreal = $newobject->stock_reel;
773 $newobject->load_stock(
'novirtual,nobatch');
774 $getstockreal = $newobject->stock_reel;
776 if ($savstockreal != $getstockreal) {
778 $warehouse->fetch(0, $product[
'warehouse_ref']);
779 if ($warehouse->id > 0) {
780 if (($savstockreal - $getstockreal) > 0) {
781 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
783 if (($savstockreal - $getstockreal) > 0) {
784 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
788 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
792 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
799 if ($newobject->price_base_type ==
'HT') {
800 $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
804 } elseif ($newobject->price_base_type ==
'TTC') {
805 $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser);
814 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
819 $errorlabel = $newobject->error;
824 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
842 dol_syslog(
"Function: deleteProductOrService login=".$authentication[
'login']);
844 if ($authentication[
'entity']) {
845 $conf->entity = $authentication[
'entity'];
849 $objectresp = array();
859 $listofid = explode(
',', trim($listofidstring));
860 $listofiddeleted = array();
863 if (count($listofid) == 0 || empty($listofid[0])) {
866 $errorlabel =
"List of Id of products or services to delete are required.";
874 foreach ($listofid as $id) {
876 $result = $newobject->fetch($id);
880 $firsterror =
'Product or service with id '.$id.
' not found';
883 $result = $newobject->delete($user);
886 $firsterror = $newobject->error;
890 $listofiddeleted[] = $id;
897 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'nbdeleted'=>count($listofiddeleted));
902 $errorlabel = $firsterror;
908 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
'nbdeleted'=>0);
909 } elseif (count($listofiddeleted) == 0) {
911 $objectresp = array(
'result'=>array(
'result_code'=>
'NOT_FOUND',
'result_label'=>
'No product or service with id '.join(
',', $listofid).
' found'),
'nbdeleted'=>0);
929 dol_syslog(
"Function: getListOfProductsOrServices login=".$authentication[
'login']);
931 if ($authentication[
'entity']) {
932 $conf->entity = $authentication[
'entity'];
936 $objectresp = array();
937 $arrayproducts = array();
945 $sql =
"SELECT rowid, ref, ref_ext";
946 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
947 $sql .=
" WHERE entity=".$conf->entity;
948 foreach ($filterproduct as $key => $val) {
949 if ($key ==
'type' && $val >= 0) {
950 $sql .=
" AND fk_product_type = ".((int) $val);
952 if ($key ==
'status_tosell') {
953 $sql .=
" AND tosell = ".((int) $val);
955 if ($key ==
'status_tobuy') {
956 $sql .=
" AND tobuy = ".((int) $val);
959 $resql = $db->query($sql);
961 $num = $db->num_rows($resql);
965 $obj = $db->fetch_object($resql);
966 $arrayproducts[] = array(
'id'=>$obj->rowid,
'ref'=>$obj->ref,
'ref_ext'=>$obj->ref_ext);
971 $errorcode = $db->lasterrno();
972 $errorlabel = $db->lasterror();
978 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
979 'products'=>$arrayproducts
983 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
984 'products'=>$arrayproducts
1002 global $db, $conf, $langs;
1004 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
1005 $langs->setDefaultLang($langcode);
1007 dol_syslog(
"Function: getProductsForCategory login=".$authentication[
'login'].
" id=".$id);
1009 if ($authentication[
'entity']) {
1010 $conf->entity = $authentication[
'entity'];
1013 $objectresp = array();
1021 if (!$error && !$id) {
1023 $errorcode =
'BAD_PARAMETERS';
1024 $errorlabel =
"Parameter id must be provided.";
1029 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
1030 $langs->setDefaultLang($langcode);
1032 $fuser->getrights();
1035 if ($fuser->hasRight(
'produit',
'lire')) {
1037 $result = $categorie->fetch($id);
1041 $sql =
"SELECT fk_".$field.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$table;
1042 $sql .=
" WHERE fk_categorie = ".((int) $id);
1043 $sql .=
" ORDER BY fk_".$field.
" ASC";
1046 dol_syslog(
"getProductsForCategory get id of product into category", LOG_DEBUG);
1047 $res = $db->query($sql);
1050 $tmpproduct =
new Product($db);
1051 $products = array();
1052 while ($rec = $db->fetch_array($res)) {
1053 $tmpproduct->fetch($rec[
'fk_'.$field]);
1054 if ($tmpproduct->status > 0) {
1055 $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
1056 $pdir =
get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct,
'product').$tmpproduct->id.
"/photos/";
1057 $dir = $dir.
'/'.$pdir;
1059 $products[] = array(
1060 'id' => $tmpproduct->id,
1061 'ref' => $tmpproduct->ref,
1062 'ref_ext' => $tmpproduct->ref_ext,
1063 'label' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"label"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"label"] : $tmpproduct->label,
1064 'description' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"description"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"description"] : $tmpproduct->description,
1065 'date_creation' =>
dol_print_date($tmpproduct->date_creation,
'dayhourrfc'),
1066 'date_modification' =>
dol_print_date($tmpproduct->date_modification,
'dayhourrfc'),
1067 'note' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"note"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"note"] : $tmpproduct->note,
1068 'status_tosell' => $tmpproduct->status,
1069 'status_tobuy' => $tmpproduct->status_buy,
1070 'type' => $tmpproduct->type,
1071 'barcode' => $tmpproduct->barcode,
1072 'barcode_type' => $tmpproduct->barcode_type,
1073 'country_id' => $tmpproduct->country_id > 0 ? $tmpproduct->country_id :
'',
1074 'country_code' => $tmpproduct->country_code,
1075 'custom_code' => $tmpproduct->customcode,
1077 'price_net' => $tmpproduct->price,
1078 'price' => $tmpproduct->price_ttc,
1079 'vat_rate' => $tmpproduct->tva_tx,
1081 'price_base_type' => $tmpproduct->price_base_type,
1083 'stock_real' => $tmpproduct->stock_reel,
1084 'stock_alert' => $tmpproduct->seuil_stock_alerte,
1085 'pmp' => $tmpproduct->pmp,
1086 'import_key' => $tmpproduct->import_key,
1088 'images' => $tmpproduct->liste_photos($dir, $nbmax)
1091 $elementtype =
'product';
1096 $extrafields->fetch_name_optionals_label($elementtype,
true);
1098 $tmpproduct->fetch_optionals();
1100 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
1101 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
1102 $products[$iProduct] = array_merge($products[$iProduct], array(
'options_'.$key => $tmpproduct->array_options[
'options_'.$key]));
1111 $objectresp = array(
1112 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
1113 'products'=> $products
1116 $errorcode =
'NORECORDS_FOR_ASSOCIATION';
1117 $errorlabel =
'No products associated'.$sql;
1118 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1119 dol_syslog(
"getProductsForCategory:: ".$errorcode, LOG_DEBUG);
1123 $errorcode =
'NOT_FOUND';
1124 $errorlabel =
'Object not found for id='.$id;
1128 $errorcode =
'PERMISSION_DENIED';
1129 $errorlabel =
'User does not have permission for this request';
1134 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1141$server->service(file_get_contents(
"php://input"));
Class to manage categories.
Class to manage warehouses.
Class to manage products or services.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getProductOrService($authentication, $id=0, $ref='', $ref_ext='', $lang='')
Get produt or service.
getProductsForCategory($authentication, $id, $lang='')
Get list of products for a category.
getListOfProductsOrServices($authentication, $filterproduct)
getListOfProductsOrServices
updateProductOrService($authentication, $product)
Update a product or service.
createProductOrService($authentication, $product)
Create an invoice.
deleteProductOrService($authentication, $listofidstring)
Delete a product or service.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.