28if (!defined(
'NOCSRFCHECK')) {
29 define(
'NOCSRFCHECK',
'1');
31if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL',
'1');
34if (!defined(
'NOREQUIREMENU')) {
35 define(
'NOREQUIREMENU',
'1');
37if (!defined(
'NOREQUIREHTML')) {
38 define(
'NOREQUIREHTML',
'1');
40if (!defined(
'NOREQUIREAJAX')) {
41 define(
'NOREQUIREAJAX',
'1');
43if (!defined(
"NOLOGIN")) {
44 define(
"NOLOGIN",
'1');
46if (!defined(
"NOSESSION")) {
47 define(
"NOSESSION",
'1');
50require
'../main.inc.php';
51require_once NUSOAP_PATH.
'/nusoap.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
57require_once DOL_DOCUMENT_ROOT.
"/categories/class/categorie.class.php";
58require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
65dol_syslog(
"Call Dolibarr webservices interfaces");
71 $langs->load(
"admin");
72 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
73 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
74 print $langs->trans(
"ToActivateModule");
79$server =
new nusoap_server();
80$server->soap_defencoding =
'UTF-8';
81$server->decode_utf8 =
false;
82$ns =
'http://www.dolibarr.org/ns/';
83$server->configureWSDL(
'WebServicesDolibarrProductOrService', $ns);
84$server->wsdl->schemaTargetNamespace = $ns;
88$server->wsdl->addComplexType(
95 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
96 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
97 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
98 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
99 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string')
103$server->wsdl->addComplexType(
110 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
111 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string')
115$productorservice_fields = array(
116 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
117 'ref' => array(
'name' =>
'ref',
'type' =>
'xsd:string'),
118 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
119 'type' => array(
'name' =>
'type',
'type' =>
'xsd:string'),
120 'label' => array(
'name' =>
'label',
'type' =>
'xsd:string'),
121 'description' => array(
'name' =>
'description',
'type' =>
'xsd:string'),
122 'date_creation' => array(
'name' =>
'date_creation',
'type' =>
'xsd:dateTime'),
123 'date_modification' => array(
'name' =>
'date_modification',
'type' =>
'xsd:dateTime'),
124 'note' => array(
'name' =>
'note',
'type' =>
'xsd:string'),
125 'status_tobuy' => array(
'name' =>
'status_tobuy',
'type' =>
'xsd:string'),
126 'status_tosell' => array(
'name' =>
'status_tosell',
'type' =>
'xsd:string'),
127 'barcode' => array(
'name' =>
'barcode',
'type' =>
'xsd:string'),
128 'barcode_type' => array(
'name' =>
'barcode_type',
'type' =>
'xsd:string'),
129 'country_id' => array(
'name' =>
'country_id',
'type' =>
'xsd:string'),
130 'country_code' => array(
'name' =>
'country_code',
'type' =>
'xsd:string'),
131 'customcode' => array(
'name' =>
'customcode',
'type' =>
'xsd:string'),
133 'price_net' => array(
'name' =>
'price_net',
'type' =>
'xsd:string'),
134 'price' => array(
'name' =>
'price',
'type' =>
'xsd:string'),
135 'price_min_net' => array(
'name' =>
'price_min_net',
'type' =>
'xsd:string'),
136 'price_min' => array(
'name' =>
'price_min',
'type' =>
'xsd:string'),
138 'price_base_type' => array(
'name' =>
'price_base_type',
'type' =>
'xsd:string'),
140 'vat_rate' => array(
'name' =>
'vat_rate',
'type' =>
'xsd:string'),
141 'vat_npr' => array(
'name' =>
'vat_npr',
'type' =>
'xsd:string'),
142 'localtax1_tx' => array(
'name' =>
'localtax1_tx',
'type' =>
'xsd:string'),
143 'localtax2_tx' => array(
'name' =>
'localtax2_tx',
'type' =>
'xsd:string'),
145 'stock_alert' => array(
'name' =>
'stock_alert',
'type' =>
'xsd:string'),
146 'stock_real' => array(
'name' =>
'stock_real',
'type' =>
'xsd:string'),
147 'stock_pmp' => array(
'name' =>
'stock_pmp',
'type' =>
'xsd:string'),
148 'warehouse_ref' => array(
'name' =>
'warehouse_ref',
'type' =>
'xsd:string'),
150 'canvas' => array(
'name' =>
'canvas',
'type' =>
'xsd:string'),
151 'import_key' => array(
'name' =>
'import_key',
'type' =>
'xsd:string'),
153 'dir' => array(
'name' =>
'dir',
'type' =>
'xsd:string'),
154 'images' => array(
'name' =>
'images',
'type' =>
'tns:ImagesArray')
158$elementtype =
'product';
164$extrafields->fetch_name_optionals_label($elementtype,
true);
165$extrafield_array =
null;
166if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype][
'count'] > 0) {
167 $extrafield_array = array();
169if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
170 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
171 $type = $extrafields->attributes[$elementtype][
'type'][$key];
172 if ($type ==
'date' || $type ==
'datetime') {
173 $type =
'xsd:dateTime';
175 $type =
'xsd:string';
178 $extrafield_array[
'options_'.$key] = array(
'name' =>
'options_'.$key,
'type' => $type);
182if (!empty($extrafield_array) && is_array($extrafield_array)) {
183 $productorservice_fields = array_merge($productorservice_fields, $extrafield_array);
187$server->wsdl->addComplexType(
193 $productorservice_fields
200$server->wsdl->addComplexType(
209 'type' =>
'tns:image',
211 'maxOccurs' =>
'unbounded'
219$server->wsdl->addComplexType(
226 'photo' => array(
'name' =>
'photo',
'type' =>
'xsd:string'),
227 'photo_vignette' => array(
'name' =>
'photo_vignette',
'type' =>
'xsd:string'),
228 'imgWidth' => array(
'name' =>
'imgWidth',
'type' =>
'xsd:string'),
229 'imgHeight' => array(
'name' =>
'imgHeight',
'type' =>
'xsd:string')
235$server->wsdl->addComplexType(
243 'type' => array(
'name' =>
'type',
'type' =>
'xsd:string'),
244 'status_tobuy' => array(
'name' =>
'status_tobuy',
'type' =>
'xsd:string'),
245 'status_tosell' => array(
'name' =>
'status_tosell',
'type' =>
'xsd:string'),
249$server->wsdl->addComplexType(
258 'type' =>
'tns:product',
260 'maxOccurs' =>
'unbounded'
270$styleuse =
'encoded';
276 'getProductOrService',
278 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string',
'lang' =>
'xsd:string'),
280 array(
'result' =>
'tns:result',
'product' =>
'tns:product'),
282 $ns.
'#getProductOrService',
285 'WS to get product or service'
290 'createProductOrService',
292 array(
'authentication' =>
'tns:authentication',
'product' =>
'tns:product'),
294 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
296 $ns.
'#createProductOrService',
299 'WS to create a product or service'
304 'updateProductOrService',
306 array(
'authentication' =>
'tns:authentication',
'product' =>
'tns:product'),
308 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
310 $ns.
'#updateProductOrService',
313 'WS to update a product or service'
318 'deleteProductOrService',
320 array(
'authentication' =>
'tns:authentication',
'listofid' =>
'xsd:string'),
322 array(
'result' =>
'tns:result',
'nbdeleted' =>
'xsd:int'),
324 $ns.
'#deleteProductOrService',
327 'WS to delete a product or service'
332 'getListOfProductsOrServices',
334 array(
'authentication' =>
'tns:authentication',
'filterproduct' =>
'tns:filterproduct'),
336 array(
'result' =>
'tns:result',
'products' =>
'tns:ProductsArray2'),
338 $ns.
'#getListOfProductsOrServices',
341 'WS to get list of all products or services id and ref'
346 'getProductsForCategory',
348 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'lang' =>
'xsd:string'),
350 array(
'result' =>
'tns:result',
'products' =>
'tns:ProductsArray2'),
352 $ns.
'#getProductsForCategory',
355 'WS to get list of all products or services for a category'
371 global $db,
$conf, $langs;
373 dol_syslog(
"Function: getProductOrService login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
375 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' :
$conf->global->MAIN_LANG_DEFAULT));
376 $langs->setDefaultLang($langcode);
378 if ($authentication[
'entity']) {
379 $conf->entity = $authentication[
'entity'];
383 $objectresp = array();
389 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
391 $errorcode =
'BAD_PARAMETERS';
392 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
396 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' :
$conf->global->MAIN_LANG_DEFAULT));
397 $langs->setDefaultLang($langcode);
399 $fuser->loadRights();
402 if ($fuser->hasRight(
'produit',
'lire') || $fuser->hasRight(
'service',
'lire')) {
404 $result = $product->fetch(
$id, $ref, $ref_ext);
407 $product->load_stock();
409 $dir = (!empty(
$conf->product->dir_output) ?
$conf->product->dir_output :
$conf->service->dir_output);
410 $pdir =
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->ref.
"/";
411 $dir = $dir.
'/'.$pdir;
413 if (!empty($product->multilangs[$langs->defaultlang][
"label"])) {
414 $product->label = $product->multilangs[$langs->defaultlang][
"label"];
416 if (!empty($product->multilangs[$langs->defaultlang][
"description"])) {
417 $product->description = $product->multilangs[$langs->defaultlang][
"description"];
419 if (!empty($product->multilangs[$langs->defaultlang][
"note"])) {
420 $product->note = $product->multilangs[$langs->defaultlang][
"note"];
423 $productorservice_result_fields = array(
424 'id' => $product->id,
425 'ref' => $product->ref,
426 'ref_ext' => $product->ref_ext,
427 'label' => $product->label,
428 'description' => $product->description,
429 'date_creation' =>
dol_print_date($product->date_creation,
'dayhourrfc'),
430 'date_modification' =>
dol_print_date($product->date_modification,
'dayhourrfc'),
431 'note' => $product->note,
432 'status_tosell' => $product->status,
433 'status_tobuy' => $product->status_buy,
434 'type' => $product->type,
435 'barcode' => $product->barcode,
436 'barcode_type' => $product->barcode_type,
437 'country_id' => $product->country_id > 0 ? $product->country_id :
'',
438 'country_code' => $product->country_code,
439 'custom_code' => $product->customcode,
441 'price_net' => $product->price,
442 'price' => $product->price_ttc,
443 'price_min_net' => $product->price_min,
444 'price_min' => $product->price_min_ttc,
445 'price_base_type' => $product->price_base_type,
446 'vat_rate' => $product->tva_tx,
448 'vat_npr' => $product->tva_npr,
450 'localtax1_tx' => $product->localtax1_tx,
451 'localtax2_tx' => $product->localtax2_tx,
453 'stock_real' => $product->stock_reel,
454 'stock_virtual' => $product->stock_theorique,
455 'stock_alert' => $product->seuil_stock_alerte,
456 'pmp' => $product->pmp,
457 'import_key' => $product->import_key,
459 'images' => $product->liste_photos($dir, $nbmax)
462 $elementtype =
'product';
467 $extrafields->fetch_name_optionals_label($elementtype,
true);
469 $product->fetch_optionals();
471 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
472 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
473 $productorservice_result_fields = array_merge($productorservice_result_fields, array(
'options_'.$key => $product->array_options[
'options_'.$key]));
479 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
480 'product' => $productorservice_result_fields
484 $errorcode =
'NOT_FOUND';
485 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
489 $errorcode =
'PERMISSION_DENIED';
490 $errorlabel =
'User does not have permission for this request';
495 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
515 dol_syslog(
"Function: createProductOrService login=".$authentication[
'login']);
517 if ($authentication[
'entity']) {
518 $conf->entity = $authentication[
'entity'];
522 $objectresp = array();
528 if (empty($product[
'price_base_type'])) {
529 if (isset($product[
'price_net']) && $product[
'price_net'] > 0) {
530 $product[
'price_base_type'] =
'HT';
532 if (isset($product[
'price']) && $product[
'price'] > 0) {
533 $product[
'price_base_type'] =
'TTC';
537 if (isset($product[
'price_net']) && $product[
'price_net'] > 0 && isset($product[
'price']) && $product[
'price'] > 0) {
540 $errorlabel =
"You must choose between price or price_net to provide price.";
543 if (!empty($product[
'barcode']) && empty($product[
'barcode_type'])) {
546 $errorlabel =
"You must set a barcode type when setting a barcode.";
550 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
553 $newobject->ref = $product[
'ref'];
554 $newobject->ref_ext = empty($product[
'ref_ext']) ?
'' : $product[
'ref_ext'];
555 $newobject->type = empty($product[
'type']) ? 0 : $product[
'type'];
556 $newobject->label = empty($product[
'label']) ?
'' : $product[
'label'];
557 $newobject->description = empty($product[
'description']) ?
'' : $product[
'description'];
558 $newobject->note_public = empty($product[
'note_public']) ?
'' : $product[
'note_public'];
559 $newobject->note_private = empty($product[
'note_private']) ?
'' : $product[
'note_private'];
560 $newobject->status = empty($product[
'status_tosell']) ? 0 : $product[
'status_tosell'];
561 $newobject->status_buy = empty($product[
'status_tobuy']) ? 0 : $product[
'status_tobuy'];
562 $newobject->price = isset($product[
'price_net']) ? (float) $product[
'price_net'] : 0;
563 $newobject->price_ttc = isset($product[
'price']) ? (float) $product[
'price'] : 0;
564 $newobject->tva_tx = empty($product[
'vat_rate']) ? 0 : $product[
'vat_rate'];
565 $newobject->price_base_type = $product[
'price_base_type'];
566 $newobject->date_creation = $now;
568 if (!empty($product[
'barcode'])) {
569 $newobject->barcode = $product[
'barcode'];
570 $newobject->barcode_type = (int) $product[
'barcode_type'];
573 $newobject->stock_reel = isset($product[
'stock_real']) ? (int) $product[
'stock_real'] :
null;
574 $newobject->pmp = isset($product[
'pmp']) ? (float) $product[
'pmp'] : 0;
575 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? (float) $product[
'stock_alert'] :
null;
577 $newobject->country_id = isset($product[
'country_id']) ? (int) $product[
'country_id'] : 0;
578 if (!empty($product[
'country_code'])) {
579 $newobject->country_id =
getCountry($product[
'country_code'],
'3');
581 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
583 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
600 $elementtype =
'product';
603 $extrafields->fetch_name_optionals_label($elementtype,
true);
604 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
605 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
606 $key =
'options_'.$key;
607 $newobject->array_options[$key] = $product[$key];
613 $result = $newobject->create($fuser, 0);
620 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && isModEnabled(
'stock')) {
621 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
623 $savstockreal = $newobject->stock_reel;
624 $newobject->load_stock(
'novirtual,nobatch');
625 $getstockreal = $newobject->stock_reel;
627 if ($savstockreal != $getstockreal) {
629 $warehouse->fetch(0, $product[
'warehouse_ref']);
630 if ($warehouse->id > 0) {
631 if (($savstockreal - $getstockreal) > 0) {
632 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
634 if (($savstockreal - $getstockreal) > 0) {
635 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
639 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
643 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
651 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
656 $errorlabel = $newobject->error;
661 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
681 dol_syslog(
"Function: updateProductOrService login=".$authentication[
'login']);
683 if ($authentication[
'entity']) {
684 $conf->entity = $authentication[
'entity'];
688 $objectresp = array();
694 if ($product[
'price_net'] > 0) {
695 $product[
'price_base_type'] =
'HT';
697 if ($product[
'price'] > 0) {
698 $product[
'price_base_type'] =
'TTC';
701 if ($product[
'price_net'] > 0 && $product[
'price'] > 0) {
704 $errorlabel =
"You must choose between price or price_net to provide price.";
708 if ($product[
'barcode'] && !$product[
'barcode_type']) {
711 $errorlabel =
"You must set a barcode type when setting a barcode.";
715 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
718 $newobject->fetch($product[
'id']);
720 if (isset($product[
'ref'])) {
721 $newobject->ref = $product[
'ref'];
723 if (isset($product[
'ref_ext'])) {
724 $newobject->ref_ext = $product[
'ref_ext'];
726 $newobject->type = (int) $product[
'type'];
727 $newobject->label = $product[
'label'];
728 $newobject->description = $product[
'description'];
729 $newobject->note = $product[
'note'];
730 $newobject->status = (int) $product[
'status_tosell'];
731 $newobject->status_buy = (int) $product[
'status_tobuy'];
732 $newobject->price = (float) $product[
'price_net'];
733 $newobject->price_ttc = (float) $product[
'price'];
734 $newobject->tva_tx = $product[
'vat_rate'];
735 $newobject->price_base_type = $product[
'price_base_type'];
736 $newobject->date_creation = $now;
738 if ($product[
'barcode']) {
739 $newobject->barcode = $product[
'barcode'];
740 $newobject->barcode_type = (int) $product[
'barcode_type'];
743 $newobject->stock_reel = isset($product[
'stock_real']) ? (int) $product[
'stock_real'] :
null;
744 $newobject->pmp = isset($product[
'pmp']) ? (float) $product[
'pmp'] : 0;
745 $newobject->seuil_stock_alerte = isset($product[
'stock_alert']) ? (float) $product[
'stock_alert'] :
null;
747 $newobject->country_id = isset($product[
'country_id']) ? (int) $product[
'country_id'] : 0;
748 if (!empty($product[
'country_code'])) {
749 $newobject->country_id =
getCountry($product[
'country_code'],
'3');
751 $newobject->customcode = isset($product[
'customcode']) ? $product[
'customcode'] :
'';
753 $newobject->canvas = isset($product[
'canvas']) ? $product[
'canvas'] :
'';
755 $elementtype =
'product';
758 $extrafields->fetch_name_optionals_label($elementtype,
true);
759 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
760 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
761 $key =
'options_'.$key;
762 $newobject->array_options[$key] = $product[$key];
768 $result = $newobject->update($newobject->id, $fuser);
773 if (isset($product[
'stock_real']) && $product[
'stock_real'] !=
'' && isModEnabled(
'stock')) {
774 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
776 $savstockreal = $newobject->stock_reel;
777 $newobject->load_stock(
'novirtual,nobatch');
778 $getstockreal = $newobject->stock_reel;
780 if ($savstockreal != $getstockreal) {
782 $warehouse->fetch(0, $product[
'warehouse_ref']);
783 if ($warehouse->id > 0) {
784 if (($savstockreal - $getstockreal) > 0) {
785 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
787 if (($savstockreal - $getstockreal) > 0) {
788 $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1,
'Correction from external call (Web Service)', 0,
'WS'.dol_print_date($now,
'dayhourlog'));
792 $newobject->error =
'You set a different value for stock, but correction of stock count (before='.$getstockreal.
', after='.$savstockreal.
') fails with error '.$newobject->error;
796 $newobject->error =
'You set a different value for stock but we failed to find warehouse '.$product[
'warehouse_ref'].
' to make correction.';
803 if ($newobject->price_base_type ==
'HT') {
804 $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
808 } elseif ($newobject->price_base_type ==
'TTC') {
809 $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser);
818 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
823 $errorlabel = $newobject->error;
828 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
846 dol_syslog(
"Function: deleteProductOrService login=".$authentication[
'login']);
848 if ($authentication[
'entity']) {
849 $conf->entity = $authentication[
'entity'];
853 $objectresp = array();
863 $listofid = explode(
',', trim($listofidstring));
864 $listofiddeleted = array();
867 if (count($listofid) == 0 || empty($listofid[0])) {
870 $errorlabel =
"List of Id of products or services to delete are required.";
878 foreach ($listofid as
$id) {
880 $result = $newobject->fetch(
$id);
884 $firsterror =
'Product or service with id '.$id.
' not found';
887 $result = $newobject->delete($user);
890 $firsterror = $newobject->error;
894 $listofiddeleted[] =
$id;
901 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'nbdeleted' => count($listofiddeleted));
906 $errorlabel = $firsterror;
912 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
'nbdeleted' => 0);
913 } elseif (count($listofiddeleted) == 0) {
915 $objectresp = array(
'result' => array(
'result_code' =>
'NOT_FOUND',
'result_label' =>
'No product or service with id '.implode(
',', $listofid).
' found'),
'nbdeleted' => 0);
933 dol_syslog(
"Function: getListOfProductsOrServices login=".$authentication[
'login']);
935 if ($authentication[
'entity']) {
936 $conf->entity = $authentication[
'entity'];
940 $objectresp = array();
941 $arrayproducts = array();
949 $sql =
"SELECT rowid, ref, ref_ext";
950 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
951 $sql .=
" WHERE entity=".$conf->entity;
952 foreach ($filterproduct as $key => $val) {
953 if ($key ==
'type' && $val >= 0) {
954 $sql .=
" AND fk_product_type = ".((int) $val);
956 if ($key ==
'status_tosell') {
957 $sql .=
" AND tosell = ".((int) $val);
959 if ($key ==
'status_tobuy') {
960 $sql .=
" AND tobuy = ".((int) $val);
963 $resql = $db->query($sql);
965 $num = $db->num_rows($resql);
969 $obj = $db->fetch_object($resql);
970 $arrayproducts[] = array(
'id' => $obj->rowid,
'ref' => $obj->ref,
'ref_ext' => $obj->ref_ext);
975 $errorcode = $db->lasterrno();
976 $errorlabel = $db->lasterror();
982 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
983 'products' => $arrayproducts
987 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
988 'products' => $arrayproducts
1006 global $db,
$conf, $langs;
1008 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' :
$conf->global->MAIN_LANG_DEFAULT));
1009 $langs->setDefaultLang($langcode);
1011 dol_syslog(
"Function: getProductsForCategory login=".$authentication[
'login'].
" id=".
$id);
1013 if ($authentication[
'entity']) {
1014 $conf->entity = $authentication[
'entity'];
1017 $objectresp = array();
1025 if (!$error && !
$id) {
1027 $errorcode =
'BAD_PARAMETERS';
1028 $errorlabel =
"Parameter id must be provided.";
1033 $langcode = ($lang ? $lang : (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' :
$conf->global->MAIN_LANG_DEFAULT));
1034 $langs->setDefaultLang($langcode);
1036 $fuser->loadRights();
1039 if ($fuser->hasRight(
'produit',
'lire')) {
1041 $result = $categorie->fetch(
$id);
1045 $sql =
"SELECT fk_".$field.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$table;
1046 $sql .=
" WHERE fk_categorie = ".((int)
$id);
1047 $sql .=
" ORDER BY fk_".$field.
" ASC";
1050 dol_syslog(
"getProductsForCategory get id of product into category", LOG_DEBUG);
1051 $res = $db->query($sql);
1054 $tmpproduct =
new Product($db);
1055 $products = array();
1056 while ($rec = $db->fetch_array($res)) {
1057 $tmpproduct->fetch($rec[
'fk_'.$field]);
1058 if ($tmpproduct->status > 0) {
1059 $dir = (!empty(
$conf->product->dir_output) ?
$conf->product->dir_output :
$conf->service->dir_output);
1060 $pdir =
get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct,
'product').$tmpproduct->id.
"/photos/";
1061 $dir = $dir.
'/'.$pdir;
1063 $products[] = array(
1064 'id' => $tmpproduct->id,
1065 'ref' => $tmpproduct->ref,
1066 'ref_ext' => $tmpproduct->ref_ext,
1067 'label' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"label"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"label"] : $tmpproduct->label,
1068 'description' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"description"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"description"] : $tmpproduct->description,
1069 'date_creation' =>
dol_print_date($tmpproduct->date_creation,
'dayhourrfc'),
1070 'date_modification' =>
dol_print_date($tmpproduct->date_modification,
'dayhourrfc'),
1071 'note' => !empty($tmpproduct->multilangs[$langs->defaultlang][
"note"]) ? $tmpproduct->multilangs[$langs->defaultlang][
"note"] : $tmpproduct->note,
1072 'status_tosell' => $tmpproduct->status,
1073 'status_tobuy' => $tmpproduct->status_buy,
1074 'type' => $tmpproduct->type,
1075 'barcode' => $tmpproduct->barcode,
1076 'barcode_type' => $tmpproduct->barcode_type,
1077 'country_id' => $tmpproduct->country_id > 0 ? $tmpproduct->country_id :
'',
1078 'country_code' => $tmpproduct->country_code,
1079 'custom_code' => $tmpproduct->customcode,
1081 'price_net' => $tmpproduct->price,
1082 'price' => $tmpproduct->price_ttc,
1083 'vat_rate' => $tmpproduct->tva_tx,
1085 'price_base_type' => $tmpproduct->price_base_type,
1087 'stock_real' => $tmpproduct->stock_reel,
1088 'stock_alert' => $tmpproduct->seuil_stock_alerte,
1089 'pmp' => $tmpproduct->pmp,
1090 'import_key' => $tmpproduct->import_key,
1092 'images' => $tmpproduct->liste_photos($dir, $nbmax)
1095 $elementtype =
'product';
1100 $extrafields->fetch_name_optionals_label($elementtype,
true);
1102 $tmpproduct->fetch_optionals();
1104 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
1105 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
1106 $products[$iProduct] = array_merge($products[$iProduct], array(
'options_'.$key => $tmpproduct->array_options[
'options_'.$key]));
1115 $objectresp = array(
1116 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
1117 'products' => $products
1120 $errorcode =
'NORECORDS_FOR_ASSOCIATION';
1121 $errorlabel =
'No products associated'.$sql;
1122 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1123 dol_syslog(
"getProductsForCategory:: ".$errorcode, LOG_DEBUG);
1127 $errorcode =
'NOT_FOUND';
1128 $errorlabel =
'Object not found for id='.$id;
1132 $errorcode =
'PERMISSION_DENIED';
1133 $errorlabel =
'User does not have permission for this request';
1138 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
1145$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=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.