Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
0f789f6a
Commit
0f789f6a
authored
12 years ago
by
Jean-François Ferry
Browse files
Options
Downloads
Patches
Plain Diff
New webservice method to get list of product for a specific category
parent
40a37047
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/webservices/server_productorservice.php
+145
-0
145 additions, 0 deletions
htdocs/webservices/server_productorservice.php
with
145 additions
and
0 deletions
htdocs/webservices/server_productorservice.php
+
145
−
0
View file @
0f789f6a
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment