dolibarr 25.0.0-alpha
Products Class Reference
Inheritance diagram for Products:
Collaboration diagram for Products:

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
 Get a product.
 
 getByRef ($ref, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
 Get product by ref.
 
 getByRefExt ($ref_ext, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
 Get product by ref_ext.
 
 getByBarcode ($barcode, $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includetrans=false)
 Get product by barcode.
 
 index ($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $mode=0, $category=0, $sqlfilters='', $ids_only=false, $variant_filter=0, $pagination_data=false, $includestockdata=0, $properties='')
 List products.
 
 post ($request_data=null)
 Create a product.
 
 put ($id, $request_data=null)
 Update a product.
 
 delete ($id)
 Delete a product.
 
 getSubproducts ($id)
 Get the list of subproducts of a product.
 
 addSubproducts ($id, $subproduct_id, $qty, $incdec=1)
 Add a subproduct.
 
 delSubproducts ($id, $subproduct_id)
 Remove a subproduct.
 
 getCategories ($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
 Get categories for a product.
 
 getCustomerPricesPerSegment ($id)
 Get prices per segment for a product.
 
 getCustomerPricesPerCustomer ($id, $thirdparty_id='')
 Get prices per customer for a product.
 
 getCustomerPricesPerQuantity ($id)
 Get prices per quantity for a product.
 
 addPurchasePrice ($id, $qty, $buyprice, $price_base_type, $fourn_id, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='', $localtaxes_array=array(), $newdefaultvatcode='', $multicurrency_buyprice=0, $multicurrency_price_base_type='HT', $multicurrency_tx=1, $multicurrency_code='', $desc_fourn='', $barcode='', $fk_barcode_type=null)
 Add/Update purchase prices for a product.
 
 deletePurchasePrice ($id, $priceid)
 Delete a purchase price for a product.
 
 getSupplierProducts ($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $mode=0, $category=0, $supplier=0, $sqlfilters='')
 Get a list of all purchase prices of products.
 
 getPurchasePrices ($id, $ref='', $ref_ext='', $barcode='')
 Get purchase prices for a product.
 
 getPurchasePriceLogs ($id, $ref='', $ref_ext='', $barcode='')
 Get the history logs for all supplier prices of a specific product.
 
 getAttributes ($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
 Get attributes.
 
 getAttributeById ($id)
 Get attribute by ID.
 
 getAttributesByRef ($ref)
 Get attributes by ref.
 
 getAttributesByRefExt ($ref_ext)
 Get attributes by ref_ext.
 
 addAttributes ($ref, $label, $ref_ext='')
 Add attributes.
 
 putAttributes ($id, $request_data=null)
 Update attributes by ID.
 
 deleteAttributes ($id)
 Delete attributes by ID.
 
 getAttributeValueById ($id)
 Get attribute value by ID.
 
 getAttributeValueByRef ($id, $ref)
 Get attribute value by ref.
 
 deleteAttributeValueByRef ($id, $ref)
 Delete attribute value by ref.
 
 getAttributeValues ($id)
 Get all values for an attribute ID.
 
 getAttributeValuesByRef ($ref)
 Get all values for an attribute ref.
 
 addAttributeValue ($id, $ref, $value)
 Add attribute value.
 
 putAttributeValue ($id, $request_data)
 Update attribute value.
 
 deleteAttributeValueById ($id)
 Delete attribute value by ID.
 
 getVariants ($id, $includestock=0)
 Get product variants.
 
 getVariantsByProdRef ($ref)
 Get product variants by Product ref.
 
 addVariant ($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference='', $ref_ext='')
 Add variant.
 
 addVariantByProductRef ($ref, $weight_impact, $price_impact, $price_impact_is_percent, $features)
 Add variant by product ref.
 
 putVariant ($id, $request_data=null)
 Update product variants.
 
 deleteVariant ($id)
 Delete product variants.
 
 getStock ($id, $selected_warehouse_id=null)
 Get stock data for a product.
 
 getContacts ($id, $type='')
 Get contacts of a given product.
 
 postContact ($id, $contactid, $type, $source="external", $notrigger=0)
 Add a contact type of given product.
 
 deleteContact ($id, $contactid, $type)
 Unlink a contact type of given product.
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor.
 

Public Attributes

const CACHE_GENERATION_KEY = 'productapicache_generation'
 Shared-cache key holding the current "generation" stamp of the product API read cache.
 

Protected Member Functions

 _cleanObjectDatas ($object)
 Clean sensitive object data @phpstan-template T.
 
- Protected Member Functions inherited from DolibarrApi
 _checkValForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _checkValExtrafieldsForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _filterObjectProperties ($object, $properties)
 Filter properties that will be returned on object.
 
 _checkFilters ($sqlfilters, &$error='')
 Return if a $sqlfilters parameter is valid Function no more used.
 

Private Member Functions

 _validate ($data)
 Validate fields before create or update object.
 
 _fetch ($id, $ref='', $ref_ext='', $barcode='', $includestockdata=0, $includesubproducts=false, $includeparentid=false, $includeifobjectisused=false, $includetrans=false)
 Get properties of 1 product object.
 
 isApiCacheEnabled ()
 Return whether the product API shared read cache is enabled.
 
 getApiCacheGeneration ()
 Return the current generation stamp of the product API read cache.
 
 getApiCacheKey ($params)
 Build a shared-cache key for a product read.
 

Additional Inherited Members

- Static Protected Member Functions inherited from DolibarrApi
static _checkAccessToResource ($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
 Check access by user to a given resource.
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria from a Generic filter string.
 

Detailed Description

Definition at line 43 of file api_products.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

Products::_cleanObjectDatas ( $object)
protected

Clean sensitive object data @phpstan-template T.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties

@phpstan-param T $object @phpstan-return T

Reimplemented from DolibarrApi.

Definition at line 2399 of file api_products.class.php.

References $object.

Referenced by getAttributes(), getPurchasePrices(), getSupplierProducts(), and index().

◆ _fetch()

Products::_fetch ( $id,
$ref = '',
$ref_ext = '',
$barcode = '',
$includestockdata = 0,
$includesubproducts = false,
$includeparentid = false,
$includeifobjectisused = false,
$includetrans = false )
private

Get properties of 1 product object.

Return an array with product information.

Parameters
int$idID of product
string$refRef of element
string$ref_extRef ext of element
string$barcodeBarcode of element
int$includestockdataLoad also information about stock (slower)
bool$includesubproductsLoad information about subproducts (if product is a virtual product)
bool$includeparentidLoad also ID of parent product (if product is a variant of a parent product)
bool$includeifobjectisusedCheck if product object is used and set property 'is_object_used' with result.
bool$includetransLoad also the translations of product label and description
Returns
array|mixed Data without useless information
Exceptions
RestException401
RestException403
RestException404

Definition at line 2542 of file api_products.class.php.

References $id, DolibarrApi\_checkAccessToResource(), dol_getcache(), dol_setcache(), and getDolGlobalInt().

Referenced by get(), getByBarcode(), getByRef(), and getByRefExt().

◆ _validate()

Products::_validate ( $data)
private

Validate fields before create or update object.

Parameters
?array<string,string>$data Data to validate
Returns
array<string,string>
Exceptions
RestException

Definition at line 2508 of file api_products.class.php.

Referenced by post().

◆ addAttributes()

Products::addAttributes ( $ref,
$label,
$ref_ext = '' )

Add attributes.

Since
11.0.0 Initial implementation
Parameters
string$refReference of Attribute
string$labelLabel of Attribute
string$ref_extReference of Attribute
Returns
int
Exceptions
RestException500 System error
RestException401

@url POST attributes

Definition at line 1477 of file api_products.class.php.

◆ addAttributeValue()

Products::addAttributeValue ( $id,
$ref,
$value )

Add attribute value.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute
string$refReference of Attribute value
string$valueValue of Attribute value
Returns
int
Exceptions
RestException500 System error
RestException401

@url POST attributes/{id}/values

Definition at line 1814 of file api_products.class.php.

References $id.

◆ addPurchasePrice()

Products::addPurchasePrice ( $id,
$qty,
$buyprice,
$price_base_type,
$fourn_id,
$availability,
$ref_fourn,
$tva_tx,
$charges = 0,
$remise_percent = 0,
$remise = 0,
$newnpr = 0,
$delivery_time_days = 0,
$supplier_reputation = '',
$localtaxes_array = array(),
$newdefaultvatcode = '',
$multicurrency_buyprice = 0,
$multicurrency_price_base_type = 'HT',
$multicurrency_tx = 1,
$multicurrency_code = '',
$desc_fourn = '',
$barcode = '',
$fk_barcode_type = null )

Add/Update purchase prices for a product.

Since
12.0.0 Initial implementation
Parameters
int$idID of Product
float$qtyMin quantity for which price is valid
float$buypricePurchase price for the quantity min
string$price_base_typeHT or TTC
int$fourn_idSupplier ID
int$availabilityProduct availability
string$ref_fournSupplier ref
float$tva_txNew VAT Rate (For example 8.5. Should not be a string)
float$chargescosts affering to product
float$remise_percentDiscount regarding qty (percent)
float$remiseDiscount regarding qty (amount)
int$newnprSet NPR or not
int$delivery_time_daysDelay in days for delivery (max). May be '' if not defined.
string$supplier_reputationReputation with this product to the defined supplier (empty, FAVORITE, NOTTHGOOD, DONOTORDER)
array$localtaxes_arrayArray with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function). @phan-param array{0:string,1:string,2:string,3:string}|array{} $localtaxes_array @phpstan-param array{0:string,1:string,2:string,3:string}|array{} $localtaxes_array
string$newdefaultvatcodeDefault vat code
float$multicurrency_buypricePurchase price for the quantity min in currency
string$multicurrency_price_base_typeHT or TTC in currency
float$multicurrency_txRate currency
string$multicurrency_codeCurrency code
string$desc_fournCustom description for product_fourn_price
string$barcodeBarcode
int$fk_barcode_typeBarcode type
Returns
int
Exceptions
RestException500 System error
RestException404
RestException403

@url POST {id}/purchase_prices

Definition at line 944 of file api_products.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and sanitizeVal().

◆ addSubproducts()

Products::addSubproducts ( $id,
$subproduct_id,
$qty,
$incdec = 1 )

Add a subproduct.

Link a product/service to a parent product/service

Since
11.0.0 Initial implementation
Parameters
int$idID of parent product/service
int$subproduct_idID of child product/service
float$qtyQuantity
int$incdec1=Increase/decrease stock of child when parent stock increases/decreases
Returns
int
Exceptions
RestException
RestException401
RestException404

@url POST {id}/subproducts/add

Definition at line 682 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ addVariant()

Products::addVariant ( $id,
$weight_impact,
$price_impact,
$price_impact_is_percent,
$features,
$reference = '',
$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, ...)

Since
11.0.0 Initial implementation
Parameters
int$idID of Product
float$weight_impactWeight impact of variant
float$price_impactPrice impact of variant
bool$price_impact_is_percentPrice impact in percent (true or false)
array$featuresList of attributes pairs id_attribute->id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) @phan-param array<string,string> $features @phpstan-param array<string,string> $features
string$referenceCustomized reference of variant
string$ref_extExternal reference of variant
Returns
int
Exceptions
RestException500 System error
RestException401
RestException404

@url POST {id}/variants

Definition at line 2023 of file api_products.class.php.

References $id, and price2num().

◆ addVariantByProductRef()

Products::addVariantByProductRef ( $ref,
$weight_impact,
$price_impact,
$price_impact_is_percent,
$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, ...)

Since
11.0.0 Initial implementation
Parameters
string$refRef of Product
float$weight_impactWeight impact of variant
float$price_impactPrice impact of variant
bool$price_impact_is_percentPrice impact in percent (true or false)
array$featuresList of attributes pairs id_attribute->id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) @phan-param array<string,string> $features @phpstan-param array<string,string> $features
Returns
int
Exceptions
RestException500 System error
RestException401
RestException404

@url POST ref/{ref}/variants

Definition at line 2090 of file api_products.class.php.

References price2num().

◆ delete()

Products::delete ( $id)

Delete a product.

Since
4.0.0 Initial implementation
Parameters
int$idProduct ID
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException400
RestException403
RestException404
RestException409
RestException500 System error

Definition at line 590 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteAttributes()

Products::deleteAttributes ( $id)

Delete attributes by ID.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute
Returns
int Result of deletion
Exceptions
RestException500 System error
RestException401

@url DELETE attributes/{id}

Definition at line 1567 of file api_products.class.php.

References $id.

◆ deleteAttributeValueById()

Products::deleteAttributeValueById ( $id)

Delete attribute value by ID.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute value
Returns
int
Exceptions
RestException500 System error
RestException401

@url DELETE attributes/values/{id}

Definition at line 1905 of file api_products.class.php.

References $id.

◆ deleteAttributeValueByRef()

Products::deleteAttributeValueByRef ( $id,
$ref )

Delete attribute value by ref.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute
string$refRef of Attribute value
Returns
int
Exceptions
RestException401

@url DELETE attributes/{id}/values/ref/{ref}

Definition at line 1688 of file api_products.class.php.

References $id, and getEntity().

◆ deleteContact()

Products::deleteContact ( $id,
$contactid,
$type )

Unlink a contact type of given product.

Parameters
int$idId of product to update
int$contactidId of contact
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER)

@url DELETE {id}/contact/{contactid}/{type}

Returns
array<string,array{code:int,message:string}>
Exceptions
RestException401
RestException404
RestException500 System error

Definition at line 2353 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deletePurchasePrice()

Products::deletePurchasePrice ( $id,
$priceid )

Delete a purchase price for a product.

Since
11.0.0 Initial implementation
Parameters
int$idProduct ID
int$priceidpurchase price ID

@url DELETE {id}/purchase_prices/{priceid}

Returns
int
Exceptions
RestException401
RestException404

Definition at line 1003 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteVariant()

Products::deleteVariant ( $id)

Delete product variants.

Since
11.0.0 Initial implementation
Parameters
int$idID of Variant
Returns
int Result of deletion
Exceptions
RestException500 System error
RestException401

@url DELETE variants/{id}

Definition at line 2192 of file api_products.class.php.

References $id.

◆ delSubproducts()

Products::delSubproducts ( $id,
$subproduct_id )

Remove a subproduct.

Unlink a product/service from a parent product/service

Since
11.0.0 Initial implementation
Parameters
int$idID of parent product/service
int$subproduct_idID of child product/service
Returns
int
Exceptions
RestException401
RestException404

@url DELETE {id}/subproducts/remove/{subproduct_id}

Definition at line 715 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ get()

Products::get ( $id,
$includestockdata = 0,
$includesubproducts = false,
$includeparentid = false,
$includetrans = false )

Get a product.

Return an array with product information

Since
4.0.0 Initial implementation
Parameters
int$idID of product
int$includestockdataLoad also information about stock (slower)
bool$includesubproductsLoad information about subproducts
bool$includeparentidLoad also ID of parent product (if product is a variant of a parent product)
bool$includetransLoad also the translations of product label and description
Returns
array|mixed Data without useless information
Exceptions
RestException400
RestException401
RestException403
RestException404

Definition at line 104 of file api_products.class.php.

References $id, and _fetch().

◆ getApiCacheGeneration()

Products::getApiCacheGeneration ( )
private

Return the current generation stamp of the product API read cache.

Any product write bumps it (see the ApiCache trigger), which invalidates every previously cached entry.

Returns
string

Definition at line 2658 of file api_products.class.php.

References dol_getcache().

◆ getApiCacheKey()

Products::getApiCacheKey ( $params)
private

Build a shared-cache key for a product read.

The key isolates every dimension that changes the returned payload or the visibility of its content: cache generation, entity, caller, caller rights, default language and the read parameters.

Parameters
array<string,int|string>$params Read parameters
Returns
string

Definition at line 2673 of file api_products.class.php.

References $conf.

◆ getAttributeById()

Products::getAttributeById ( $id)

Get attribute by ID.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute
Returns
Object Object with cleaned properties
Exceptions
RestException401
RestException404

@url GET attributes/{id}

Definition at line 1322 of file api_products.class.php.

References $id.

◆ getAttributes()

Products::getAttributes ( $sortfield = "t.ref",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$sqlfilters = '',
$properties = '' )

Get attributes.

Since
11.0.0 Initial implementation
Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:color)"
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
Returns
array @phan-return ProductAttribute[] @phpstan-return ProductAttribute[]
Exceptions
RestException401
RestException404
RestException503

@url GET attributes

Definition at line 1258 of file api_products.class.php.

References _cleanObjectDatas(), DolibarrApi\_filterObjectProperties(), forgeSQLFromUniversalSearchCriteria(), and getEntity().

◆ getAttributesByRef()

Products::getAttributesByRef ( $ref)

Get attributes by ref.

Since
11.0.0 Initial implementation
Parameters
string$refReference of Attribute
Returns
array @phan-return array{id:int,ref:string,ref_ext:string,label:string,rang:int,position:int,entity:string,is_used_by_products:int} @phpstan-return array{id:int,ref:string,ref_ext:string,label:string,rang:int,position:int,entity:string,is_used_by_products:int}
Exceptions
RestException401
RestException404

@url GET attributes/ref/{ref}

Definition at line 1369 of file api_products.class.php.

References getEntity().

◆ getAttributesByRefExt()

Products::getAttributesByRefExt ( $ref_ext)

Get attributes by ref_ext.

Since
11.0.0 Initial implementation
Parameters
string$ref_extExternal reference of Attribute
Returns
array @phan-return array{id:int,ref:string,ref_ext:string,label:string,rang:int,position:int,entity:string,is_used_by_products:int} @phpstan-return array{id:int,ref:string,ref_ext:string,label:string,rang:int,position:int,entity:string,is_used_by_products:int}
Exceptions
RestException500 System error
RestException401

@url GET attributes/ref_ext/{ref_ext}

Definition at line 1423 of file api_products.class.php.

References getEntity().

◆ getAttributeValueById()

Products::getAttributeValueById ( $id)

Get attribute value by ID.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute value
Returns
array @phan-return array{id:int,fk_product_attribute:int,ref:string,value:string} @phpstan-return array{id:int,fk_product_attribute:int,ref:string,value:string}
Exceptions
RestException500 System error
RestException401

@url GET attributes/values/{id}

Definition at line 1599 of file api_products.class.php.

References $id, and getEntity().

◆ getAttributeValueByRef()

Products::getAttributeValueByRef ( $id,
$ref )

Get attribute value by ref.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute value
string$refRef of Attribute value
Returns
array @phan-return array{id:int,fk_product_attribute:int,ref:string,value:string} @phpstan-return array{id:int,fk_product_attribute:int,ref:string,value:string}
Exceptions
RestException500 System error
RestException401

@url GET attributes/{id}/values/ref/{ref}

Definition at line 1644 of file api_products.class.php.

References $id, and getEntity().

◆ getAttributeValues()

Products::getAttributeValues ( $id)

Get all values for an attribute ID.

Since
11.0.0 Initial implementation
Parameters
int$idID of an Attribute
Returns
array @phan-return ProductAttributeValue[] @phpstan-return ProductAttributeValue[]
Exceptions
RestException401
RestException500 System error

@url GET attributes/{id}/values

Definition at line 1735 of file api_products.class.php.

References $id.

◆ getAttributeValuesByRef()

Products::getAttributeValuesByRef ( $ref)

Get all values for an attribute ref.

Since
11.0.0 Initial implementation
Parameters
string$refRef of an Attribute
Returns
array @phan-return ProductAttributeValue[] @phpstan-return ProductAttributeValue[]
Exceptions
RestException401

@url GET attributes/ref/{ref}/values

Definition at line 1770 of file api_products.class.php.

◆ getByBarcode()

Products::getByBarcode ( $barcode,
$includestockdata = 0,
$includesubproducts = false,
$includeparentid = false,
$includetrans = false )

Get product by barcode.

Return an array with product information

Since
11.0.0 Initial implementation
Parameters
string$barcodeBarcode of element
int$includestockdataLoad also information about stock (slower)
bool$includesubproductsLoad information about subproducts
bool$includeparentidLoad also ID of parent product (if product is a variant of a parent product)
bool$includetransLoad also the translations of product label and description
Returns
array|mixed Data without useless information

@url GET barcode/{barcode}

Exceptions
RestException401
RestException403
RestException404

Definition at line 185 of file api_products.class.php.

References _fetch().

◆ getByRef()

Products::getByRef ( $ref,
$includestockdata = 0,
$includesubproducts = false,
$includeparentid = false,
$includetrans = false )

Get product by ref.

Return an array with product information

Since
11.0.0 Initial implementation
Parameters
string$refRef of element
int$includestockdataLoad also information about stock (slower)
bool$includesubproductsLoad information about subproducts
bool$includeparentidLoad also ID of parent product (if product is a variant of a parent product)
bool$includetransLoad also the translations of product label and description
Returns
array|mixed Data without useless information

@url GET ref/{ref}

Exceptions
RestException401
RestException403
RestException404

Definition at line 133 of file api_products.class.php.

References _fetch().

◆ getByRefExt()

Products::getByRefExt ( $ref_ext,
$includestockdata = 0,
$includesubproducts = false,
$includeparentid = false,
$includetrans = false )

Get product by ref_ext.

Return an array with product information

Since
11.0.0 Initial implementation
Parameters
string$ref_extRef_ext of element
int$includestockdataLoad also information about stock (slower)
bool$includesubproductsLoad information about subproducts
bool$includeparentidLoad also ID of parent product (if product is a variant of a parent product)
bool$includetransLoad also the translations of product label and description
Returns
array|mixed Data without useless information

@url GET ref_ext/{ref_ext}

Exceptions
RestException401
RestException403
RestException404

Definition at line 159 of file api_products.class.php.

References _fetch().

◆ getCategories()

Products::getCategories ( $id,
$sortfield = "s.rowid",
$sortorder = 'ASC',
$limit = 0,
$page = 0 )

Get categories for a product.

Since
5.0.0 Initial implementation
Parameters
int$idID of product
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
Returns
mixed

@url GET {id}/categories

Exceptions
RestException

Definition at line 750 of file api_products.class.php.

References $id.

◆ getContacts()

Products::getContacts ( $id,
$type = '' )

Get contacts of a given product.

Return an array with contact information

Parameters
int$idID of product
string$typeType of the contact ('BILLING', 'SHIPPING', 'CUSTOMER', ...)
Returns
array|mixed Array of contacts

@url GET {id}/contacts

Exceptions
RestException

Definition at line 2266 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ getCustomerPricesPerCustomer()

Products::getCustomerPricesPerCustomer ( $id,
$thirdparty_id = '' )

Get prices per customer for a product.

Since
7.0.0 Initial implementation
Parameters
int$idID of product
string$thirdparty_idThirdparty id to filter orders of (example '1') {@pattern /^[0-9,]*$/i}
Returns
mixed

@url GET {id}/selling_multiprices/per_customer

Exceptions
RestException

Definition at line 826 of file api_products.class.php.

References $conf, $id, and getDolGlobalString().

◆ getCustomerPricesPerQuantity()

Products::getCustomerPricesPerQuantity ( $id)

Get prices per quantity for a product.

Since
7.0.0 Initial implementation
Parameters
int$idID of product
Returns
mixed

@url GET {id}/selling_multiprices/per_quantity

Exceptions
RestException

Definition at line 879 of file api_products.class.php.

References $conf, $id, and getDolGlobalString().

◆ getCustomerPricesPerSegment()

Products::getCustomerPricesPerSegment ( $id)

Get prices per segment for a product.

Since
7.0.0 Initial implementation
Parameters
int$idID of product
Returns
mixed

@url GET {id}/selling_multiprices/per_segment

Exceptions
RestException

Definition at line 780 of file api_products.class.php.

References $conf, $id, and getDolGlobalString().

◆ getPurchasePriceLogs()

Products::getPurchasePriceLogs ( $id,
$ref = '',
$ref_ext = '',
$barcode = '' )

Get the history logs for all supplier prices of a specific product.

Since
26.0.0 Initial implementation
Parameters
int$idID of product
string$refRef of element
string$ref_extRef ext of element
string$barcodeBarcode of element
Returns
array<int, stdClass> Array of price logs @phan-return array<int, stdClass> @phpstan-return array<int, stdClass>

@url GET {id}/purchase_prices/logs

Exceptions
RestException400
RestException403
RestException404

Definition at line 1213 of file api_products.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and dol_syslog().

◆ getPurchasePrices()

Products::getPurchasePrices ( $id,
$ref = '',
$ref_ext = '',
$barcode = '' )

Get purchase prices for a product.

Return an array with product information. TODO implement getting a product by ref or by $ref_ext

Since
11.0.0 Initial implementation
Parameters
int$idID of product
string$refRef of element
string$ref_extRef ext of element
string$barcodeBarcode of element
Returns
array Data without useless information @phan-return ProductFournisseur[] @phpstan-return ProductFournisseur[]

@url GET {id}/purchase_prices

Exceptions
RestException401
RestException403
RestException404

Definition at line 1157 of file api_products.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and _cleanObjectDatas().

◆ getStock()

Products::getStock ( $id,
$selected_warehouse_id = null )

Get stock data for a product.

Optionally with $selected_warehouse_id parameter user can get stock of a specific warehouse

Since
14.0.0 Initial implementation
Parameters
int$idID of Product
int$selected_warehouse_idID of warehouse
Returns
array|mixed Data without useless information
Exceptions
RestException500 System error
RestException403
RestException404

@url GET {id}/stock

Definition at line 2224 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ getSubproducts()

Products::getSubproducts ( $id)

Get the list of subproducts of a product.

Since
11.0.0 Initial implementation
Parameters
int$idID of parent product/service
Returns
array @phan-return array<array{rowid:int,qty:float,fkproduct_type:int,label:string,incdec:int,ref:string,fk_association:int,rang:int}> @phpstan-return array<array{rowid:int,qty:float,fkproduct_type:int,label:string,incdec:int,ref:string,fk_association:int,rang:int}>
Exceptions
RestException
RestException401
RestException404

@url GET {id}/subproducts

Definition at line 642 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ getSupplierProducts()

Products::getSupplierProducts ( $sortfield = "t.ref",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$mode = 0,
$category = 0,
$supplier = 0,
$sqlfilters = '' )

Get a list of all purchase prices of products.

Since
11.0.0 Initial implementation
Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
int$modeUse this param to filter list (0 for all, 1 for only product, 2 for only service)
int$categoryUse this param to filter list by category of product
int$supplierUse this param to filter list by supplier
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)"
Returns
array Array of product objects @phan-return array<ProductFournisseur[]|int> @phpstan-return array<ProductFournisseur[]|int>

@url GET purchase_prices

Exceptions
RestException

Definition at line 1046 of file api_products.class.php.

References $conf, _cleanObjectDatas(), forgeSQLFromUniversalSearchCriteria(), and getEntity().

◆ getVariants()

Products::getVariants ( $id,
$includestock = 0 )

Get product variants.

Since
11.0.0 Initial implementation
Parameters
int$idID of Product
int$includestockDefault value 0. If parameter is set to 1 the response will contain stock data of each variant
Returns
array @phan-return ProductCombination[] @phpstan-return ProductCombination[]
Exceptions
RestException500 System error
RestException401

@url GET {id}/variants

Definition at line 1936 of file api_products.class.php.

References $id.

◆ getVariantsByProdRef()

Products::getVariantsByProdRef ( $ref)

Get product variants by Product ref.

Since
11.0.0 Initial implementation
Parameters
string$refRef of Product
Returns
array @phan-return ProductCombination[] @phpstan-return ProductCombination[]
Exceptions
RestException500 System error
RestException401

@url GET ref/{ref}/variants

Definition at line 1976 of file api_products.class.php.

◆ index()

Products::index ( $sortfield = "t.ref",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$mode = 0,
$category = 0,
$sqlfilters = '',
$ids_only = false,
$variant_filter = 0,
$pagination_data = false,
$includestockdata = 0,
$properties = '' )

List products.

Get a list of products

Since
4.0.0 Initial implementation
Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
int$modeUse this param to filter list (0 for all, 1 for only product, 2 for only service)
int$categoryUse this param to filter list by category
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)"
bool$ids_onlyReturn only IDs of product instead of all properties (faster, above all if list is long)
int$variant_filterUse this param to filter list (0 = all, 1=products without variants, 2=parent of variants, 3=variants only)
bool$pagination_dataIf this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0
int$includestockdataLoad also information about stock (slower)
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
Returns
array Array of product objects @phan-return Product[]|array{data:Product[],pagination:array{total:int,page:int,page_count:int,limit:int}} @phpstan-return Product[]|array{data:Product[],pagination:array{total:int,page:int,page_count:int,limit:int}}
Exceptions
RestException

Definition at line 215 of file api_products.class.php.

References _cleanObjectDatas(), DolibarrApi\_filterObjectProperties(), forgeSQLFromUniversalSearchCriteria(), and getEntity().

◆ isApiCacheEnabled()

Products::isApiCacheEnabled ( )
private

Return whether the product API shared read cache is enabled.

Returns
bool

Definition at line 2646 of file api_products.class.php.

References getDolGlobalString().

◆ post()

Products::post ( $request_data = null)

Create a product.

Since
4.0.0 Initial implementation
Parameters
array$request_dataRequest data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
int ID of product
Exceptions
RestException

Definition at line 347 of file api_products.class.php.

References DolibarrApi\_checkValForAPI(), _validate(), getDolGlobalString(), and sanitizeVal().

◆ postContact()

Products::postContact ( $id,
$contactid,
$type,
$source = "external",
$notrigger = 0 )

Add a contact type of given product.

Parameters
int$idId of product to update
int$contactidId of contact to add
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER)
string$sourceexternal=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
int$notriggerDisable all triggers
Returns
array<string,array{code:int,message:string}>

@url POST {id}/contact/{contactid}/{type}

Exceptions
RestException401
RestException404

Definition at line 2305 of file api_products.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ put()

Products::put ( $id,
$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.

Since
4.0.0 Initial implementation
Parameters
int$idId of product to update
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
Object Updated object
Exceptions
RestException400
RestException401
RestException404

Definition at line 412 of file api_products.class.php.

References $id, DolibarrApi\_checkAccessToResource(), DolibarrApi\_checkValExtrafieldsForAPI(), DolibarrApi\_checkValForAPI(), dol_clone(), getDolGlobalString(), and sanitizeVal().

◆ putAttributes()

Products::putAttributes ( $id,
$request_data = null )

Update attributes by ID.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
Object Object with cleaned properties
Exceptions
RestException
RestException401
RestException404

@url PUT attributes/{id}

Definition at line 1513 of file api_products.class.php.

References $id, and sanitizeVal().

◆ putAttributeValue()

Products::putAttributeValue ( $id,
$request_data )

Update attribute value.

Since
11.0.0 Initial implementation
Parameters
int$idID of Attribute
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
Object Object with cleaned properties
Exceptions
RestException401
RestException500 System error

@url PUT attributes/values/{id}

Definition at line 1851 of file api_products.class.php.

References $id, and sanitizeVal().

◆ putVariant()

Products::putVariant ( $id,
$request_data = null )

Update product variants.

Since
11.0.0 Initial implementation
Parameters
int$idID of Variant
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
int
Exceptions
RestException500 System error
RestException401

@url PUT variants/{id}

Definition at line 2150 of file api_products.class.php.

References $id, and sanitizeVal().

Member Data Documentation

◆ CACHE_GENERATION_KEY

const Products::CACHE_GENERATION_KEY = 'productapicache_generation'

Shared-cache key holding the current "generation" stamp of the product API read cache.

It is bumped by the trigger core/triggers/interface_99_modProduct_ApiCache.class.php on every product write (PRODUCT_CREATE / PRODUCT_MODIFY / PRODUCT_DELETE / PRODUCT_PRICE_MODIFY), which transparently invalidates every cached entry at once (memcached/shmop offer no delete-by-pattern).

Definition at line 61 of file api_products.class.php.


The documentation for this class was generated from the following file: