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");
66if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
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 : (empty($conf->global->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'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
391 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
392 $langs->setDefaultLang($langcode);
397 if ($fuser->rights->produit->lire || $fuser->rights->service->lire) {
399 $result = $product->fetch($id, $ref, $ref_ext);
402 $product->load_stock();
404 $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
405 $pdir =
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->ref.
"/";
406 $dir = $dir.
'/'.$pdir;
408 if (!empty($product->multilangs[$langs->defaultlang][
"label"])) {
409 $product->label = $product->multilangs[$langs->defaultlang][
"label"];
411 if (!empty($product->multilangs[$langs->defaultlang][
"description"])) {
412 $product->description = $product->multilangs[$langs->defaultlang][
"description"];
414 if (!empty($product->multilangs[$langs->defaultlang][
"note"])) {
415 $product->note = $product->multilangs[$langs->defaultlang][
"note"];
418 $productorservice_result_fields = array(
419 'id' => $product->id,
420 'ref' => $product->ref,
421 'ref_ext' => $product->ref_ext,
422 'label' => $product->label,
423 'description' => $product->description,
424 'date_creation' =>
dol_print_date($product->date_creation,
'dayhourrfc'),
425 'date_modification' =>
dol_print_date($product->date_modification,
'dayhourrfc'),
426 'note' => $product->note,
427 'status_tosell' => $product->status,
428 'status_tobuy' => $product->status_buy,
429 'type' => $product->type,
430 'barcode' => $product->barcode,
431 'barcode_type' => $product->barcode_type,
432 'country_id' => $product->country_id > 0 ? $product->country_id :
'',
433 'country_code' => $product->country_code,
434 'custom_code' => $product->customcode,
436 'price_net' => $product->price,
437 'price' => $product->price_ttc,
438 'price_min_net' => $product->price_min,
439 'price_min' => $product->price_min_ttc,
440 'price_base_type' => $product->price_base_type,
441 'vat_rate' => $product->tva_tx,
443 'vat_npr' => $product->tva_npr,
445 'localtax1_tx' => $product->localtax1_tx,
446 'localtax2_tx' => $product->localtax2_tx,
448 'stock_real' => $product->stock_reel,
449 'stock_virtual' => $product->stock_theorique,
450 'stock_alert' => $product->seuil_stock_alerte,
451 'pmp' => $product->pmp,
452 'import_key' => $product->import_key,
454 'images' => $product->liste_photos($dir, $nbmax)
457 $elementtype =
'product';
462 $extrafields->fetch_name_optionals_label($elementtype,
true);
464 $product->fetch_optionals();
466 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
467 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
468 $productorservice_result_fields = array_merge($productorservice_result_fields, array(
'options_'.$key => $product->array_options[
'options_'.$key]));
474 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
475 'product'=>$productorservice_result_fields
479 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
483 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
488 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
508 dol_syslog(
"Function: createProductOrService login=".$authentication[
'login']);
510 if ($authentication[
'entity']) {
511 $conf->entity = $authentication[
'entity'];
515 $objectresp = array();
521 if (empty($product[
'price_base_type'])) {
522 if (isset($product[
'price_net']) && $product[
'price_net'] > 0) {
523 $product[
'price_base_type'] =
'HT';
525 if (isset($product[
'price']) && $product[
'price'] > 0) {
526 $product[
'price_base_type'] =
'TTC';
530 if (isset($product[
'price_net']) && $product[
'price_net'] > 0 && isset($product[
'price']) && $product[
'price'] > 0) {
531 $error++; $errorcode =
'KO'; $errorlabel =
"You must choose between price or price_net to provide price.";
534 if (!empty($product[
'barcode']) && empty($product[
'barcode_type'])) {
535 $error++; $errorcode =
'KO'; $errorlabel =
"You must set a barcode type when setting a barcode.";
539 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
542 $newobject->ref = $product[
'ref'];
543 $newobject->ref_ext = empty($product[
'ref_ext']) ?
'' : $product[
'ref_ext'];
544 $newobject->type = empty($product[
'type']) ? 0 : $product[
'type'];
545 $newobject->label = empty($product[
'label']) ?
'' : $product[
'label'];
546 $newobject->description = empty($product[
'description']) ?
'' : $product[
'description'];
547 $newobject->note_public = empty($product[
'note_public']) ?
'' : $product[
'note_public'];
548 $newobject->note_private = empty($product[
'note_private']) ?
'' : $product[
'note_private'];
549 $newobject->status = empty($product[
'status_tosell']) ? 0 : $product[
'status_tosell'];
550 $newobject->status_buy = empty($product[
'status_tobuy']) ? 0 : $product[
'status_tobuy'];
551 $newobject->price = isset($product[
'price_net']) ? $product[
'price_net'] : 0;
552 $newobject->price_ttc = isset($product[
'price']) ? $product[
'price'] : 0;
553 $newobject->tva_tx = empty($product[
'vat_rate']) ? 0 : $product[
'vat_rate'];
554 $newobject->price_base_type = $product[
'price_base_type'];
555 $newobject->date_creation = $now;
557 if (!empty($product[
'barcode'])) {
558 $newobject->barcode = $product[
'barcode'];
559 $newobject->barcode_type = $product[
'barcode_type'];
562 $newobject->stock_reel = isset($product[
'stock_real']) ? $product[
'stock_real'] :
null;
563 $newobject->pmp = isset($product[
'pmp']) ? $product[
'pmp'] :
null;
564 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? $product[
'stock_alert'] :
null;
566 $newobject->country_id = isset($product[
'country_id']) ? $product[
'country_id'] : 0;
567 if (!empty($product[
'country_code'])) {
568 $newobject->country_id =
getCountry($product[
'country_code'], 3);
570 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
572 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
589 $elementtype =
'product';
592 $extrafields->fetch_name_optionals_label($elementtype,
true);
593 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
594 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
595 $key =
'options_'.$key;
596 $newobject->array_options[$key] = $product[$key];
602 $result = $newobject->create($fuser, 0);
609 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && !empty($conf->global->stock->enabled)) {
610 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
612 $savstockreal = $newobject->stock_reel;
613 $newobject->load_stock(
'novirtual,nobatch');
614 $getstockreal = $newobject->stock_reel;
616 if ($savstockreal != $getstockreal) {
618 $warehouse->fetch(0, $product[
'warehouse_ref']);
619 if ($warehouse->id > 0) {
620 if (($savstockreal - $getstockreal) > 0) {
621 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
623 if (($savstockreal - $getstockreal) > 0) {
624 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
628 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
632 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
640 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
645 $errorlabel = $newobject->error;
650 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
670 dol_syslog(
"Function: updateProductOrService login=".$authentication[
'login']);
672 if ($authentication[
'entity']) {
673 $conf->entity = $authentication[
'entity'];
677 $objectresp = array();
683 if ($product[
'price_net'] > 0) {
684 $product[
'price_base_type'] =
'HT';
686 if ($product[
'price'] > 0) {
687 $product[
'price_base_type'] =
'TTC';
690 if ($product[
'price_net'] > 0 && $product[
'price'] > 0) {
691 $error++; $errorcode =
'KO'; $errorlabel =
"You must choose between price or price_net to provide price.";
695 if ($product[
'barcode'] && !$product[
'barcode_type']) {
696 $error++; $errorcode =
'KO'; $errorlabel =
"You must set a barcode type when setting a barcode.";
700 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
703 $newobject->fetch($product[
'id']);
705 if (isset($product[
'ref'])) {
706 $newobject->ref = $product[
'ref'];
708 if (isset($product[
'ref_ext'])) {
709 $newobject->ref_ext = $product[
'ref_ext'];
711 $newobject->type = $product[
'type'];
712 $newobject->label = $product[
'label'];
713 $newobject->description = $product[
'description'];
714 $newobject->note = $product[
'note'];
715 $newobject->status = $product[
'status_tosell'];
716 $newobject->status_buy = $product[
'status_tobuy'];
717 $newobject->price = $product[
'price_net'];
718 $newobject->price_ttc = $product[
'price'];
719 $newobject->tva_tx = $product[
'vat_rate'];
720 $newobject->price_base_type = $product[
'price_base_type'];
721 $newobject->date_creation = $now;
723 if ($product[
'barcode']) {
724 $newobject->barcode = $product[
'barcode'];
725 $newobject->barcode_type = $product[
'barcode_type'];
728 $newobject->stock_reel = isset($product[
'stock_real']) ? $product[
'stock_real'] :
null;
729 $newobject->pmp = isset($product[
'pmp']) ? $product[
'pmp'] :
null;
730 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? $product[
'stock_alert'] :
null;
732 $newobject->country_id = isset($product[
'country_id']) ? $product[
'country_id'] : 0;
733 if (!empty($product[
'country_code'])) {
734 $newobject->country_id =
getCountry($product[
'country_code'], 3);
736 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
738 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
740 $elementtype =
'product';
743 $extrafields->fetch_name_optionals_label($elementtype,
true);
744 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
745 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
746 $key =
'options_'.$key;
747 $newobject->array_options[$key] = $product[$key];
753 $result = $newobject->update($newobject->id, $fuser);
758 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && !empty($conf->global->stock->enabled)) {
759 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
761 $savstockreal = $newobject->stock_reel;
762 $newobject->load_stock(
'novirtual,nobatch');
763 $getstockreal = $newobject->stock_reel;
765 if ($savstockreal != $getstockreal) {
767 $warehouse->fetch(0, $product[
'warehouse_ref']);
768 if ($warehouse->id > 0) {
769 if (($savstockreal - $getstockreal) > 0) {
770 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
772 if (($savstockreal - $getstockreal) > 0) {
773 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
777 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
781 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
788 if ($newobject->price_base_type ==
'HT') {
789 $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
793 } elseif ($newobject->price_base_type ==
'TTC') {
794 $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser);
803 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
808 $errorlabel = $newobject->error;
813 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
831 dol_syslog(
"Function: deleteProductOrService login=".$authentication[
'login']);
833 if ($authentication[
'entity']) {
834 $conf->entity = $authentication[
'entity'];
838 $objectresp = array();
848 $listofid = explode(
',', trim($listofidstring));
849 $listofiddeleted = array();
852 if (count($listofid) == 0 || empty($listofid[0])) {
853 $error++; $errorcode =
'KO'; $errorlabel =
"List of Id of products or services to delete are required.";
861 foreach ($listofid as $id) {
863 $result = $newobject->fetch($id);
867 $firsterror =
'Product or service with id '.$id.
' not found';
870 $result = $newobject->delete($user);
873 $firsterror = $newobject->error;
877 $listofiddeleted[] = $id;
884 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'nbdeleted'=>count($listofiddeleted));
889 $errorlabel = $firsterror;
895 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
'nbdeleted'=>0);
896 } elseif (count($listofiddeleted) == 0) {
898 $objectresp = array(
'result'=>array(
'result_code'=>
'NOT_FOUND',
'result_label'=>
'No product or service with id '.join(
',', $listofid).
' found'),
'nbdeleted'=>0);
916 dol_syslog(
"Function: getListOfProductsOrServices login=".$authentication[
'login']);
918 if ($authentication[
'entity']) {
919 $conf->entity = $authentication[
'entity'];
923 $objectresp = array();
924 $arrayproducts = array();
932 $sql =
"SELECT rowid, ref, ref_ext";
933 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
934 $sql .=
" WHERE entity=".$conf->entity;
935 foreach ($filterproduct as $key => $val) {
936 if ($key ==
'type' && $val >= 0) {
937 $sql .=
" AND fk_product_type = ".((int) $val);
939 if ($key ==
'status_tosell') {
940 $sql .=
" AND tosell = ".((int) $val);
942 if ($key ==
'status_tobuy') {
943 $sql .=
" AND tobuy = ".((int) $val);
946 $resql = $db->query($sql);
948 $num = $db->num_rows($resql);
952 $obj = $db->fetch_object($resql);
953 $arrayproducts[] = array(
'id'=>$obj->rowid,
'ref'=>$obj->ref,
'ref_ext'=>$obj->ref_ext);
958 $errorcode = $db->lasterrno();
959 $errorlabel = $db->lasterror();
965 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
966 'products'=>$arrayproducts
970 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
971 'products'=>$arrayproducts
989 global $db, $conf, $langs;
991 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
992 $langs->setDefaultLang($langcode);
994 dol_syslog(
"Function: getProductsForCategory login=".$authentication[
'login'].
" id=".$id);
996 if ($authentication[
'entity']) {
997 $conf->entity = $authentication[
'entity'];
1000 $objectresp = array();
1001 $errorcode =
''; $errorlabel =
'';
1007 if (!$error && !$id) {
1009 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id must be provided.";
1014 $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT));
1015 $langs->setDefaultLang($langcode);
1017 $fuser->getrights();
1020 if ($fuser->rights->produit->lire) {
1022 $result = $categorie->fetch($id);
1026 $sql =
"SELECT fk_".$field.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$table;
1027 $sql .=
" WHERE fk_categorie = ".((int) $id);
1028 $sql .=
" ORDER BY fk_".$field.
" ASC";
1031 dol_syslog(
"getProductsForCategory get id of product into category", LOG_DEBUG);
1032 $res = $db->query($sql);
1035 $tmpproduct =
new Product($db);
1036 $products = array();
1037 while ($rec = $db->fetch_array($res)) {
1038 $tmpproduct->fetch($rec[
'fk_'.$field]);
1039 if ($tmpproduct->status > 0) {
1040 $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
1041 $pdir =
get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct,
'product').$tmpproduct->id.
"/photos/";
1042 $dir = $dir.
'/'.$pdir;
1044 $products[] = array(
1045 'id' => $tmpproduct->id,
1046 'ref' => $tmpproduct->ref,
1047 'ref_ext' => $tmpproduct->ref_ext,
1048 'label' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"label"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"label"] : $tmpproduct->label,
1049 'description' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"description"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"description"] : $tmpproduct->description,
1050 'date_creation' =>
dol_print_date($tmpproduct->date_creation,
'dayhourrfc'),
1051 'date_modification' =>
dol_print_date($tmpproduct->date_modification,
'dayhourrfc'),
1052 'note' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"note"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"note"] : $tmpproduct->note,
1053 'status_tosell' => $tmpproduct->status,
1054 'status_tobuy' => $tmpproduct->status_buy,
1055 'type' => $tmpproduct->type,
1056 'barcode' => $tmpproduct->barcode,
1057 'barcode_type' => $tmpproduct->barcode_type,
1058 'country_id' => $tmpproduct->country_id > 0 ? $tmpproduct->country_id :
'',
1059 'country_code' => $tmpproduct->country_code,
1060 'custom_code' => $tmpproduct->customcode,
1062 'price_net' => $tmpproduct->price,
1063 'price' => $tmpproduct->price_ttc,
1064 'vat_rate' => $tmpproduct->tva_tx,
1066 'price_base_type' => $tmpproduct->price_base_type,
1068 'stock_real' => $tmpproduct->stock_reel,
1069 'stock_alert' => $tmpproduct->seuil_stock_alerte,
1070 'pmp' => $tmpproduct->pmp,
1071 'import_key' => $tmpproduct->import_key,
1073 'images' => $tmpproduct->liste_photos($dir, $nbmax)
1076 $elementtype =
'product';
1081 $extrafields->fetch_name_optionals_label($elementtype,
true);
1083 $tmpproduct->fetch_optionals();
1085 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
1086 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
1087 $products[$iProduct] = array_merge($products[$iProduct], array(
'options_'.$key => $tmpproduct->array_options[
'options_'.$key]));
1096 $objectresp = array(
1097 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
1098 'products'=> $products
1101 $errorcode =
'NORECORDS_FOR_ASSOCIATION'; $errorlabel =
'No products associated'.$sql;
1102 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1103 dol_syslog(
"getProductsForCategory:: ".$errorcode, LOG_DEBUG);
1107 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id;
1111 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
1116 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1123$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.
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.
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.
getProductOrService($authentication, $id='', $ref='', $ref_ext='', $lang='')
Get produt or service.
deleteProductOrService($authentication, $listofidstring)
Delete a product or service.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.