Skip to content
Snippets Groups Projects
Commit 0f789f6a authored by Jean-François Ferry's avatar Jean-François Ferry
Browse files

New webservice method to get list of product for a specific category

parent 40a37047
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
dol_syslog("Call Dolibarr webservices interfaces");
......@@ -255,6 +257,20 @@ $server->register(
'WS to get list of all products or services id and ref'
);
// Register WSDL
$server->register(
'getProductsForCategory',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','products'=>'ProductsArray'),
$ns,
$ns.'#getProductsForCategory',
$styledoc,
$styleuse,
'WS to get list of all products or services for a category'
);
/**
* Get produt or service
......@@ -541,6 +557,135 @@ function getListOfProductsOrServices($authentication,$filterproduct)
}
// return category infos and children
function getProductsForCategory($authentication,$id)
{
global $db,$conf,$langs;
dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
$objectresp=array();
$errorcode='';$errorlabel='';
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
if (! $error && !$id)
{
$error++;
$errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id must be provided.";
}
if (! $error)
{
$fuser->getrights();
if ($fuser->rights->produit->lire)
{
$categorie=new Categorie($db);
$result=$categorie->fetch($id);
if ($result > 0)
{
$table = "product";
$field = "product";
$sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table;
$sql .= " WHERE fk_categorie = ".$id;
$sql .= " ORDER BY fk_".$field." ASC" ;
dol_syslog("GetProductsForCategory::get_type sql=".$sql);
$res = $db->query($sql);
if ($res)
{
while ($rec = $db->fetch_array ($res))
{
$obj = new Product ($db);
$obj->fetch ($rec['fk_'.$field]);
if($obj->status > 0 ) {
$dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output);
$pdir = get_exdir($obj->id,2) . $obj->id ."/photos/";
$dir = $dir . '/'. $pdir;
$products[] = array(
'id' => $obj->id,
'ref' => $obj->ref,
'ref_ext' => $obj->ref_ext,
'label' => $obj->label,
'description' => $obj->description,
'date_creation' => dol_print_date($obj->date_creation,'dayhourrfc'),
'date_modification' => dol_print_date($obj->date_modification,'dayhourrfc'),
'note' => $obj->note,
'status_tosell' => $obj->status,
'status_tobuy' => $obj->status_buy,
'type' => $obj->type,
'barcode' => $obj->barcode,
'barcode_type' => $obj->barcode_type,
'country_id' => $obj->country_id>0?$obj->country_id:'',
'country_code' => $obj->country_code,
'custom_code' => $obj->customcode,
'price_net' => $obj->price,
'price' => ($obj->price_ttc-$obj->price),
'vat_rate' => $obj->tva_tx,
'price_ttc' => $obj->price_ttc,
'price_base_type' => $obj->price_base_type,
'stock_real' => $obj->stock_reel,
'stock_alert' => $obj->seuil_stock_alerte,
'pmp' => $obj->pmp,
'import_key' => $obj->import_key,
'dir' => $pdir,
'photos' => $obj->liste_photos($dir,$nbmax=10)
);
}
}
// Retour
$objectresp = array(
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'products'=> $products
);
}
else
{
$errorcode='NORECORDS_FOR_ASSOCIATION'; $errorlabel='No products associated'.$sql;
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
dol_syslog("getProductsForCategory:: ".$c->error, LOG_DEBUG);
}
}
else
{
$error++;
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id;
}
}
else
{
$error++;
$errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
// Return the results.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment