Products
class Products extends DolibarrApi (View source)
API class for products
Properties
| protected DoliDB | $db | from DolibarrApi | |
| Restler | $r | from DolibarrApi | |
| static string[] | $FIELDS | ||
| Product | $product | ||
| ProductFournisseur | $productsupplier |
Methods
Constructor
Check and convert a string depending on its type/name.
Filter properties that will be returned on object
Clean sensitive object data
Check access by user to a given resource
Return if a $sqlfilters parameter is valid Function no more used. Kept for backward compatibility with old APIs of modules
Function to forge a SQL criteria from a Generic filter string.
Get a product
Get product by ref
Get product by ref_ext
Get product by barcode
List products
Create a product
Update a product
Delete a product
Get the list of subproducts of a product
Add a subproduct
Remove a subproduct
Get categories for a product
Get prices per segment for a product
Get prices per customer for a product
Get prices per quantity for a product
Add/Update purchase prices for a product
Delete a purchase price for a product
Get a list of all purchase prices of products
Get purchase prices for a product
Get attributes
Get attribute by ID
Get attributes by ref
Get attributes by ref_ext
Add attributes
Update attributes by ID
Delete attributes by ID
Get attribute value by ID
Get attribute value by ref
Delete attribute value by ref
Get all values for an attribute ID
Get all values for an attribute ref
Add attribute value
Update attribute value
Delete attribute value by ID
Get product variants
Get product variants by Product ref
Add variant
Add variant by product ref
Update product variants
Delete product variants
Get stock data for a product
Get contacts of a given product
Add a contact type of given product
Unlink a contact type of given product
Details
__construct()
Constructor
protected string|array<string, mixed>
_checkValForAPI(string $field, string|string[] $value, object $object)
Check and convert a string depending on its type/name.
protected object
_filterObjectProperties(object $object, string $properties)
Filter properties that will be returned on object
protected object
_cleanObjectDatas(object $object)
Clean sensitive object data
static protected bool
_checkAccessToResource(string $resource, int $resource_id = 0, string $dbtablename = '', string $feature2 = '', string $dbt_keyfield = 'fk_soc', string $dbt_select = 'rowid')
Check access by user to a given resource
protected bool|string
_checkFilters(string $sqlfilters, string $error = '')
Return if a $sqlfilters parameter is valid Function no more used. Kept for backward compatibility with old APIs of modules
static protected string
_forge_criteria_callback(string[] $matches)
Function to forge a SQL criteria from a Generic filter string.
Function no more used. Kept for backward compatibility with old APIs of modules
array|mixed
get(int $id, int $includestockdata = 0, bool $includesubproducts = false, bool $includeparentid = false, bool $includetrans = false)
Get a product
Return an array with product information
array|mixed
getByRef(string $ref, int $includestockdata = 0, bool $includesubproducts = false, bool $includeparentid = false, bool $includetrans = false)
Get product by ref
Return an array with product information
array|mixed
getByRefExt(string $ref_ext, int $includestockdata = 0, bool $includesubproducts = false, bool $includeparentid = false, bool $includetrans = false)
Get product by ref_ext
Return an array with product information
array|mixed
getByBarcode(string $barcode, int $includestockdata = 0, bool $includesubproducts = false, bool $includeparentid = false, bool $includetrans = false)
Get product by barcode
Return an array with product information
array
index(string $sortfield = "t.ref", string $sortorder = 'ASC', int $limit = 100, int $page = 0, int $mode = 0, int $category = 0, string $sqlfilters = '', bool $ids_only = false, int $variant_filter = 0, bool $pagination_data = false, int $includestockdata = 0, string $properties = '')
List products
Get a list of products
int
post(array $request_data = null)
Create a product
object
put(int $id, array $request_data = null)
Update a product
Price will be updated by this API only if option is set on "One price per product" or if PRODUIT_MULTIPRICES is set (1 price per segment) See other APIs for other price modes.
array
delete(int $id)
Delete a product
array
getSubproducts(int $id)
Get the list of subproducts of a product
int
addSubproducts(int $id, int $subproduct_id, float $qty, int $incdec = 1)
Add a subproduct
Link a product/service to a parent product/service
int
delSubproducts(int $id, int $subproduct_id)
Remove a subproduct
Unlink a product/service from a parent product/service
mixed
getCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)
Get categories for a product
mixed
getCustomerPricesPerSegment(int $id)
Get prices per segment for a product
mixed
getCustomerPricesPerCustomer(int $id, string $thirdparty_id = '')
Get prices per customer for a product
mixed
getCustomerPricesPerQuantity(int $id)
Get prices per quantity for a product
int
addPurchasePrice(int $id, float $qty, float $buyprice, string $price_base_type, int $fourn_id, int $availability, string $ref_fourn, float $tva_tx, float $charges = 0, float $remise_percent = 0, float $remise = 0, int $newnpr = 0, int $delivery_time_days = 0, string $supplier_reputation = '', array $localtaxes_array = array(), string $newdefaultvatcode = '', float $multicurrency_buyprice = 0, string $multicurrency_price_base_type = 'HT', float $multicurrency_tx = 1, string $multicurrency_code = '', string $desc_fourn = '', string $barcode = '', int $fk_barcode_type = null)
Add/Update purchase prices for a product
int
deletePurchasePrice(int $id, int $priceid)
Delete a purchase price for a product
array
getSupplierProducts(string $sortfield = "t.ref", string $sortorder = 'ASC', int $limit = 100, int $page = 0, int $mode = 0, int $category = 0, int $supplier = 0, string $sqlfilters = '')
Get a list of all purchase prices of products
array
getPurchasePrices(int $id, string $ref = '', string $ref_ext = '', string $barcode = '')
Get purchase prices for a product
Return an array with product information. TODO implement getting a product by ref or by $ref_ext
array
getAttributes(string $sortfield = "t.ref", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $sqlfilters = '', string $properties = '')
Get attributes
object
getAttributeById(int $id)
Get attribute by ID
array
getAttributesByRef(string $ref)
Get attributes by ref
array
getAttributesByRefExt(string $ref_ext)
Get attributes by ref_ext
int
addAttributes(string $ref, string $label, string $ref_ext = '')
Add attributes
object
putAttributes(int $id, array $request_data = null)
Update attributes by ID
int
deleteAttributes(int $id)
Delete attributes by ID
array
getAttributeValueById(int $id)
Get attribute value by ID
array
getAttributeValueByRef(int $id, string $ref)
Get attribute value by ref
int
deleteAttributeValueByRef(int $id, string $ref)
Delete attribute value by ref
array
getAttributeValues(int $id)
Get all values for an attribute ID
array
getAttributeValuesByRef(string $ref)
Get all values for an attribute ref
int
addAttributeValue(int $id, string $ref, string $value)
Add attribute value
object
putAttributeValue(int $id, array $request_data)
Update attribute value
int
deleteAttributeValueById(int $id)
Delete attribute value by ID
array
getVariants(int $id, int $includestock = 0)
Get product variants
array
getVariantsByProdRef(string $ref)
Get product variants by Product ref
int
addVariant(int $id, float $weight_impact, float $price_impact, bool $price_impact_is_percent, array $features, string $reference = '', string $ref_ext = '')
Add variant
"features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...)
int
addVariantByProductRef(string $ref, float $weight_impact, float $price_impact, bool $price_impact_is_percent, array $features)
Add variant by product ref
"features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...)
int
putVariant(int $id, array $request_data = null)
Update product variants
int
deleteVariant(int $id)
Delete product variants
array|mixed
getStock(int $id, int $selected_warehouse_id = null)
Get stock data for a product
Optionally with $selected_warehouse_id parameter user can get stock of a specific warehouse
array|mixed
getContacts(int $id, string $type = '')
Get contacts of a given product
Return an array with contact information
array<string, array{code: int, message: string}>
postContact(int $id, int $contactid, string $type, string $source = "external", int $notrigger = 0)
Add a contact type of given product
array<string, array{code: int, message: string}>
deleteContact(int $id, int $contactid, string $type)
Unlink a contact type of given product