server_productorservice.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 JF FERRY <jfefe@aternatik.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/webservices/server_productorservice.php
  20. * \brief File that is entry point to call Dolibarr WebServices
  21. */
  22. // This is to make Dolibarr working with Plesk
  23. set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  24. require_once '../master.inc.php';
  25. require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
  31. dol_syslog("Call Dolibarr webservices interfaces");
  32. $langs->load("main");
  33. // Enable and test if module web services is enabled
  34. if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
  35. {
  36. $langs->load("admin");
  37. dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
  38. print $langs->trans("WarningModuleNotActive",'WebServices').'.<br><br>';
  39. print $langs->trans("ToActivateModule");
  40. exit;
  41. }
  42. // Create the soap Object
  43. $server = new nusoap_server();
  44. $server->soap_defencoding='UTF-8';
  45. $server->decode_utf8=false;
  46. $ns='http://www.dolibarr.org/ns/';
  47. $server->configureWSDL('WebServicesDolibarrProductOrService',$ns);
  48. $server->wsdl->schemaTargetNamespace=$ns;
  49. // Define WSDL Authentication object
  50. $server->wsdl->addComplexType(
  51. 'authentication',
  52. 'complexType',
  53. 'struct',
  54. 'all',
  55. '',
  56. array(
  57. 'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
  58. 'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
  59. 'login' => array('name'=>'login','type'=>'xsd:string'),
  60. 'password' => array('name'=>'password','type'=>'xsd:string'),
  61. 'entity' => array('name'=>'entity','type'=>'xsd:string'),
  62. )
  63. );
  64. // Define WSDL Return object
  65. $server->wsdl->addComplexType(
  66. 'result',
  67. 'complexType',
  68. 'struct',
  69. 'all',
  70. '',
  71. array(
  72. 'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
  73. 'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
  74. )
  75. );
  76. // Define other specific objects
  77. $server->wsdl->addComplexType(
  78. 'product',
  79. 'complexType',
  80. 'struct',
  81. 'all',
  82. '',
  83. array(
  84. 'id' => array('name'=>'id','type'=>'xsd:string'),
  85. 'ref' => array('name'=>'ref','type'=>'xsd:string'),
  86. 'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
  87. 'type' => array('name'=>'type','type'=>'xsd:string'),
  88. 'label' => array('name'=>'label','type'=>'xsd:string'),
  89. 'description' => array('name'=>'description','type'=>'xsd:string'),
  90. 'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
  91. 'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
  92. 'note' => array('name'=>'note','type'=>'xsd:string'),
  93. 'status_tobuy' => array('name'=>'status_tobuy','type'=>'xsd:string'),
  94. 'status_tosell' => array('name'=>'status_tosell','type'=>'xsd:string'),
  95. 'barcode' => array('name'=>'barcode','type'=>'xsd:string'),
  96. 'barcode_type' => array('name'=>'barcode_type','type'=>'xsd:string'),
  97. 'country_id' => array('name'=>'country_id','type'=>'xsd:string'),
  98. 'country_code' => array('name'=>'country_code','type'=>'xsd:string'),
  99. 'customcode' => array('name'=>'customcode','type'=>'xsd:string'),
  100. 'price_net' => array('name'=>'price_net','type'=>'xsd:string'),
  101. 'price' => array('name'=>'price','type'=>'xsd:string'),
  102. 'price_ttc' => array('name'=>'price_ttc','type'=>'xsd:string'),
  103. 'price_base_type' => array('name'=>'price_base_type','type'=>'xsd:string'),
  104. 'stock_alert' => array('name'=>'stock_alert','type'=>'xsd:string'),
  105. 'stock_real' => array('name'=>'stock_real','type'=>'xsd:string'),
  106. 'stock_pmp' => array('name'=>'stock_pmp','type'=>'xsd:string'),
  107. 'canvas' => array('name'=>'canvas','type'=>'xsd:string'),
  108. 'import_key' => array('name'=>'import_key','type'=>'xsd:string'),
  109. 'dir' => array('name'=>'dir','type'=>'xsd:string'),
  110. 'photos' => array('name'=>'photos','type'=>'tns:PhotosArray')
  111. )
  112. );
  113. /*
  114. * Image of product
  115. */
  116. $server->wsdl->addComplexType(
  117. 'PhotosArray',
  118. 'complexType',
  119. 'array',
  120. '',
  121. 'SOAP-ENC:Array',
  122. array(),
  123. array(
  124. array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:image[]')
  125. )
  126. );
  127. /*
  128. * An image
  129. */
  130. $server->wsdl->addComplexType(
  131. 'image',
  132. 'complexType',
  133. 'array',
  134. '',
  135. 'SOAP-ENC:Array',
  136. array(),
  137. array(
  138. 'photo' => array('name'=>'photo','type'=>'xsd:string'),
  139. 'photo_vignette' => array('name'=>'photo_vignette','type'=>'xsd:string'),
  140. 'imgWidth' => array('name'=>'imgWidth','type'=>'xsd:string'),
  141. 'imgHeight' => array('name'=>'imgHeight','type'=>'xsd:string')
  142. )
  143. );
  144. // Define other specific objects
  145. $server->wsdl->addComplexType(
  146. 'filterproduct',
  147. 'complexType',
  148. 'struct',
  149. 'all',
  150. '',
  151. array(
  152. //'limit' => array('name'=>'limit','type'=>'xsd:string'),
  153. 'type' => array('name'=>'type','type'=>'xsd:string'),
  154. 'status_tobuy' => array('name'=>'status_tobuy','type'=>'xsd:string'),
  155. 'status_tosell' => array('name'=>'status_tosell','type'=>'xsd:string'),
  156. )
  157. );
  158. $server->wsdl->addComplexType(
  159. 'ProductsArray',
  160. 'complexType',
  161. 'array',
  162. '',
  163. 'SOAP-ENC:Array',
  164. array(),
  165. array(
  166. array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:product[]')
  167. ),
  168. 'tns:product'
  169. );
  170. $server->wsdl->addComplexType(
  171. 'ProductsArray2',
  172. 'complexType',
  173. 'array',
  174. 'sequence',
  175. '',
  176. array(
  177. 'product' => array(
  178. 'name' => 'product',
  179. 'type' => 'tns:product',
  180. 'minOccurs' => '0',
  181. 'maxOccurs' => 'unbounded'
  182. )
  183. )
  184. );
  185. // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
  186. // Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
  187. // http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
  188. $styledoc='rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
  189. $styleuse='encoded'; // encoded/literal/literal wrapped
  190. // Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
  191. // Register WSDL
  192. $server->register(
  193. 'getProductOrService',
  194. // Entry values
  195. array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
  196. // Exit values
  197. array('result'=>'tns:result','product'=>'tns:product'),
  198. $ns,
  199. $ns.'#getProductOrService',
  200. $styledoc,
  201. $styleuse,
  202. 'WS to get product or service'
  203. );
  204. // Register WSDL
  205. $server->register(
  206. 'createProductOrService',
  207. // Entry values
  208. array('authentication'=>'tns:authentication','product'=>'tns:product'),
  209. // Exit values
  210. array('result'=>'tns:result','id'=>'xsd:string'),
  211. $ns,
  212. $ns.'#createProductOrService',
  213. $styledoc,
  214. $styleuse,
  215. 'WS to create a product or service'
  216. );
  217. // Register WSDL
  218. $server->register(
  219. 'getListOfProductsOrServices',
  220. // Entry values
  221. array('authentication'=>'tns:authentication','filterproduct'=>'tns:filterproduct'),
  222. // Exit values
  223. array('result'=>'tns:result','products'=>'tns:ProductsArray2'),
  224. $ns,
  225. $ns.'#getListOfProductsOrServices',
  226. $styledoc,
  227. $styleuse,
  228. 'WS to get list of all products or services id and ref'
  229. );
  230. // Register WSDL
  231. $server->register(
  232. 'getProductsForCategory',
  233. // Entry values
  234. array('authentication'=>'tns:authentication','id'=>'xsd:string'),
  235. // Exit values
  236. array('result'=>'tns:result','products'=>'ProductsArray'),
  237. $ns,
  238. $ns.'#getProductsForCategory',
  239. $styledoc,
  240. $styleuse,
  241. 'WS to get list of all products or services for a category'
  242. );
  243. /**
  244. * Get produt or service
  245. *
  246. * @param array $authentication Array of authentication information
  247. * @param int $id Id of object
  248. * @param string $ref Ref of object
  249. * @param ref_ext $ref_ext Ref external of object
  250. * @return mixed
  251. */
  252. function getProductOrService($authentication,$id='',$ref='',$ref_ext='')
  253. {
  254. global $db,$conf,$langs;
  255. dol_syslog("Function: getProductOrService login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
  256. if ($authentication['entity']) $conf->entity=$authentication['entity'];
  257. // Init and check authentication
  258. $objectresp=array();
  259. $errorcode='';$errorlabel='';
  260. $error=0;
  261. $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
  262. // Check parameters
  263. if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
  264. {
  265. $error++;
  266. $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
  267. }
  268. if (! $error)
  269. {
  270. $fuser->getrights();
  271. if ($fuser->rights->produit->lire || $fuser->rights->service->lire)
  272. {
  273. $product=new Product($db);
  274. $result=$product->fetch($id,$ref,$ref_ext);
  275. if ($result > 0)
  276. {
  277. $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output);
  278. $pdir = get_exdir($product->id,2) . $product->id ."/photos/";
  279. $dir = $dir . '/'. $pdir;
  280. // Create
  281. $objectresp = array(
  282. 'result'=>array('result_code'=>'OK', 'result_label'=>''),
  283. 'product'=>array(
  284. 'id' => $product->id,
  285. 'ref' => $product->ref,
  286. 'ref_ext' => $product->ref_ext,
  287. 'label' => $product->label,
  288. 'description' => $product->description,
  289. 'date_creation' => dol_print_date($product->date_creation,'dayhourrfc'),
  290. 'date_modification' => dol_print_date($product->date_modification,'dayhourrfc'),
  291. 'note' => $product->note,
  292. 'status_tosell' => $product->status,
  293. 'status_tobuy' => $product->status_buy,
  294. 'type' => $product->type,
  295. 'barcode' => $product->barcode,
  296. 'barcode_type' => $product->barcode_type,
  297. 'country_id' => $product->country_id>0?$product->country_id:'',
  298. 'country_code' => $product->country_code,
  299. 'custom_code' => $product->customcode,
  300. 'price_net' => $product->price,
  301. 'price' => ($product->price_ttc-$product->price),
  302. 'vat_rate' => $product->tva_tx,
  303. 'price_ttc' => $product->price_ttc,
  304. 'price_base_type' => $product->price_base_type,
  305. 'stock_real' => $product->stock_reel,
  306. 'stock_alert' => $product->seuil_stock_alerte,
  307. 'pmp' => $product->pmp,
  308. 'import_key' => $product->import_key,
  309. 'dir' => $pdir,
  310. 'photos' => $product->liste_photos($dir,$nbmax=10)
  311. ));
  312. }
  313. else
  314. {
  315. $error++;
  316. $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
  317. }
  318. }
  319. else
  320. {
  321. $error++;
  322. $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
  323. }
  324. }
  325. if ($error)
  326. {
  327. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  328. }
  329. return $objectresp;
  330. }
  331. /**
  332. * Create an invoice
  333. *
  334. * @param array $authentication Array of authentication information
  335. * @param Product $product Product
  336. * @return array Array result
  337. */
  338. function createProductOrService($authentication,$product)
  339. {
  340. global $db,$conf,$langs;
  341. $now=dol_now();
  342. dol_syslog("Function: createProductOrService login=".$authentication['login']);
  343. if ($authentication['entity']) $conf->entity=$authentication['entity'];
  344. // Init and check authentication
  345. $objectresp=array();
  346. $errorcode='';$errorlabel='';
  347. $error=0;
  348. $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
  349. // Check parameters
  350. if ($product['price_net'] > 0) $product['price_base_type']='HT';
  351. if ($product['price'] > 0) $product['price_base_type']='TTC';
  352. if ($product['price_net'] > 0 && $product['price'] > 0)
  353. {
  354. $error++; $errorcode='KO'; $errorlabel="You must choose between price or price_net to provide price.";
  355. }
  356. if (! $error)
  357. {
  358. include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  359. $newobject=new Product($db);
  360. $newobject->ref=$product['ref'];
  361. $newobject->ref_ext=$product['ref_ext'];
  362. $newobject->type=$product['type'];
  363. $newobject->libelle=$product['label']; // TODO deprecated
  364. $newobject->label=$product['label'];
  365. $newobject->description=$product['description'];
  366. $newobject->note=$product['note'];
  367. $newobject->status=$product['status_tosell'];
  368. $newobject->status_buy=$product['status_tobuy'];
  369. $newobject->price=$product['price_net'];
  370. $newobject->price_ttc=$product['price'];
  371. $newobject->tva_tx=$product['vat_rate'];
  372. $newobject->price_base_type=$product['price_base_type'];
  373. $newobject->date_creation=$now;
  374. $newobject->stock_reel=$product['stock_real'];
  375. $newobject->pmp=$product['pmp'];
  376. $newobject->seuil_stock_alert=$product['stock_alert'];
  377. $newobject->country_id=$product['country_id'];
  378. if ($product['country_code']) $newobject->country_id=getCountry($product['country_code'],3);
  379. $newobject->customcode=$product['customcode'];
  380. $newobject->canvas=$product['canvas'];
  381. /*foreach($product['lines'] as $line)
  382. {
  383. $newline=new FactureLigne($db);
  384. $newline->type=$line['type'];
  385. $newline->desc=$line['desc'];
  386. $newline->fk_product=$line['fk_product'];
  387. $newline->total_ht=$line['total_net'];
  388. $newline->total_vat=$line['total_vat'];
  389. $newline->total_ttc=$line['total'];
  390. $newline->vat=$line['vat_rate'];
  391. $newline->qty=$line['qty'];
  392. $newline->fk_product=$line['product_id'];
  393. }*/
  394. //var_dump($product['ref_ext']);
  395. //var_dump($product['lines'][0]['type']);
  396. $db->begin();
  397. $result=$newobject->create($fuser,0);
  398. if ($result <= 0)
  399. {
  400. $error++;
  401. }
  402. if (! $error)
  403. {
  404. $db->commit();
  405. $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref);
  406. }
  407. else
  408. {
  409. $db->rollback();
  410. $error++;
  411. $errorcode='KO';
  412. $errorlabel=$newobject->error;
  413. }
  414. }
  415. if ($error)
  416. {
  417. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  418. }
  419. return $objectresp;
  420. }
  421. /**
  422. * getListOfProductsOrServices
  423. *
  424. * @param array $authentication Array of authentication information
  425. * @param array $filterproduct Filter fields
  426. * @return array Array result
  427. */
  428. function getListOfProductsOrServices($authentication,$filterproduct)
  429. {
  430. global $db,$conf,$langs;
  431. $now=dol_now();
  432. dol_syslog("Function: getListOfProductsOrServices login=".$authentication['login']);
  433. if ($authentication['entity']) $conf->entity=$authentication['entity'];
  434. // Init and check authentication
  435. $objectresp=array();
  436. $arrayproducts=array();
  437. $errorcode='';$errorlabel='';
  438. $error=0;
  439. $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
  440. // Check parameters
  441. if (! $error)
  442. {
  443. $sql ="SELECT rowid, ref, ref_ext";
  444. $sql.=" FROM ".MAIN_DB_PREFIX."product";
  445. $sql.=" WHERE entity=".$conf->entity;
  446. foreach($filterproduct as $key => $val)
  447. {
  448. if ($key == 'type' && $val >= 0) $sql.=" AND fk_product_type = ".$db->escape($val);
  449. if ($key == 'tosell') $sql.=" AND to_sell = ".$db->escape($val);
  450. if ($key == 'tobuy') $sql.=" AND to_buy = ".$db->escape($val);
  451. }
  452. $resql=$db->query($sql);
  453. if ($resql)
  454. {
  455. $num=$db->num_rows($resql);
  456. $i=0;
  457. while ($i < $num)
  458. {
  459. $obj=$db->fetch_object($resql);
  460. $arrayproducts[]=array('id'=>$obj->rowid,'ref'=>$obj->ref,'ref_ext'=>$obj->ref_ext);
  461. $i++;
  462. }
  463. }
  464. else
  465. {
  466. $error++;
  467. $errorcode=$db->lasterrno();
  468. $errorlabel=$db->lasterror();
  469. }
  470. }
  471. if ($error)
  472. {
  473. $objectresp = array(
  474. 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
  475. 'products'=>$arrayproducts
  476. );
  477. }
  478. else
  479. {
  480. $objectresp = array(
  481. 'result'=>array('result_code' => 'OK', 'result_label' => ''),
  482. 'products'=>$arrayproducts
  483. );
  484. }
  485. return $objectresp;
  486. }
  487. // return category infos and children
  488. function getProductsForCategory($authentication,$id)
  489. {
  490. global $db,$conf,$langs;
  491. dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id);
  492. if ($authentication['entity']) $conf->entity=$authentication['entity'];
  493. $objectresp=array();
  494. $errorcode='';$errorlabel='';
  495. $error=0;
  496. $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
  497. if (! $error && !$id)
  498. {
  499. $error++;
  500. $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id must be provided.";
  501. }
  502. if (! $error)
  503. {
  504. $fuser->getrights();
  505. if ($fuser->rights->produit->lire)
  506. {
  507. $categorie=new Categorie($db);
  508. $result=$categorie->fetch($id);
  509. if ($result > 0)
  510. {
  511. $table = "product";
  512. $field = "product";
  513. $sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table;
  514. $sql .= " WHERE fk_categorie = ".$id;
  515. $sql .= " ORDER BY fk_".$field." ASC" ;
  516. dol_syslog("GetProductsForCategory::get_type sql=".$sql);
  517. $res = $db->query($sql);
  518. if ($res)
  519. {
  520. while ($rec = $db->fetch_array ($res))
  521. {
  522. $obj = new Product ($db);
  523. $obj->fetch ($rec['fk_'.$field]);
  524. if($obj->status > 0 ) {
  525. $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output);
  526. $pdir = get_exdir($obj->id,2) . $obj->id ."/photos/";
  527. $dir = $dir . '/'. $pdir;
  528. $products[] = array(
  529. 'id' => $obj->id,
  530. 'ref' => $obj->ref,
  531. 'ref_ext' => $obj->ref_ext,
  532. 'label' => $obj->label,
  533. 'description' => $obj->description,
  534. 'date_creation' => dol_print_date($obj->date_creation,'dayhourrfc'),
  535. 'date_modification' => dol_print_date($obj->date_modification,'dayhourrfc'),
  536. 'note' => $obj->note,
  537. 'status_tosell' => $obj->status,
  538. 'status_tobuy' => $obj->status_buy,
  539. 'type' => $obj->type,
  540. 'barcode' => $obj->barcode,
  541. 'barcode_type' => $obj->barcode_type,
  542. 'country_id' => $obj->country_id>0?$obj->country_id:'',
  543. 'country_code' => $obj->country_code,
  544. 'custom_code' => $obj->customcode,
  545. 'price_net' => $obj->price,
  546. 'price' => ($obj->price_ttc-$obj->price),
  547. 'vat_rate' => $obj->tva_tx,
  548. 'price_ttc' => $obj->price_ttc,
  549. 'price_base_type' => $obj->price_base_type,
  550. 'stock_real' => $obj->stock_reel,
  551. 'stock_alert' => $obj->seuil_stock_alerte,
  552. 'pmp' => $obj->pmp,
  553. 'import_key' => $obj->import_key,
  554. 'dir' => $pdir,
  555. 'photos' => $obj->liste_photos($dir,$nbmax=10)
  556. );
  557. }
  558. }
  559. // Retour
  560. $objectresp = array(
  561. 'result'=>array('result_code'=>'OK', 'result_label'=>''),
  562. 'products'=> $products
  563. );
  564. }
  565. else
  566. {
  567. $errorcode='NORECORDS_FOR_ASSOCIATION'; $errorlabel='No products associated'.$sql;
  568. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  569. dol_syslog("getProductsForCategory:: ".$c->error, LOG_DEBUG);
  570. }
  571. }
  572. else
  573. {
  574. $error++;
  575. $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id;
  576. }
  577. }
  578. else
  579. {
  580. $error++;
  581. $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
  582. }
  583. }
  584. if ($error)
  585. {
  586. $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
  587. }
  588. return $objectresp;
  589. }
  590. // Return the results.
  591. $server->service($HTTP_RAW_POST_DATA);
  592. ?>