Merge pull request #1552 from aternatik/ws_prodlang

Add multilang support into product webservice
This commit is contained in:
Laurent Destailleur 2014-04-28 02:36:11 +02:00
commit c600003807

View File

@ -303,7 +303,7 @@ $server->register(
* @param int $id Id of object
* @param string $ref Ref of object
* @param ref_ext $ref_ext Ref external of object
* @param $lang $lang Force lang
* @param string $lang Lang to force
* @return mixed
*/
function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang='')
@ -312,6 +312,9 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang=''
dol_syslog("Function: getProductOrService login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
$langcode=($lang?$lang:(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
// Init and check authentication
@ -347,6 +350,10 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang=''
$pdir = get_exdir($product->id,2) . $product->id ."/photos/";
$dir = $dir . '/'. $pdir;
if (! empty($product->multilangs[$langs->defaultlang]["label"])) $product->label = $product->multilangs[$langs->defaultlang]["label"];
if (! empty($product->multilangs[$langs->defaultlang]["description"])) $product->description = $product->multilangs[$langs->defaultlang]["description"];
if (! empty($product->multilangs[$langs->defaultlang]["note"])) $product->note = $product->multilangs[$langs->defaultlang]["note"];
// Create
$objectresp = array(
'result'=>array('result_code'=>'OK', 'result_label'=>''),
@ -707,16 +714,20 @@ function getListOfProductsOrServices($authentication,$filterproduct)
/**
* getProductsForCategory
* Get list of products for a category
*
* @param array $authentication Array of authentication information
* @param array $id Category id
* @param $lang $lang Force lang
* @return array Array result
*/function getProductsForCategory($authentication,$id,$lang='')
*/
function getProductsForCategory($authentication,$id,$lang='')
{
global $db,$conf,$langs;
$langcode=($lang?$lang:(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
@ -773,11 +784,11 @@ function getListOfProductsOrServices($authentication,$filterproduct)
'id' => $obj->id,
'ref' => $obj->ref,
'ref_ext' => $obj->ref_ext,
'label' => $obj->label,
'description' => $obj->description,
'label' => ! empty($obj->multilangs[$langs->defaultlang]["label"]) ? $obj->multilangs[$langs->defaultlang]["label"] : $obj->label,
'description' => ! empty($obj->multilangs[$langs->defaultlang]["description"]) ? $obj->multilangs[$langs->defaultlang]["description"] : $obj->description,
'date_creation' => dol_print_date($obj->date_creation,'dayhourrfc'),
'date_modification' => dol_print_date($obj->date_modification,'dayhourrfc'),
'note' => $obj->note,
'note' => ! empty($obj->multilangs[$langs->defaultlang]["note"]) ? $obj->multilangs[$langs->defaultlang]["note"] : $obj->note,
'status_tosell' => $obj->status,
'status_tobuy' => $obj->status_buy,
'type' => $obj->type,