dolibarr  13.0.2
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
Products Class Reference
+ Inheritance diagram for Products:
+ Collaboration diagram for Products:

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id, $includestockdata=0, $includesubproducts=false, $includeparentid=false)
 Get properties of a product object by id. More...
 
 getByRef ($ref, $includestockdata=0, $includesubproducts=false, $includeparentid=false)
 Get properties of a product object by ref. More...
 
 getByRefExt ($ref_ext, $includestockdata=0, $includesubproducts=false, $includeparentid=false)
 Get properties of a product object by ref_ext. More...
 
 getByBarcode ($barcode, $includestockdata=0, $includesubproducts=false, $includeparentid=false)
 Get properties of a product object by barcode. More...
 
 index ($sortfield="t.ref", $sortorder= 'ASC', $limit=100, $page=0, $mode=0, $category=0, $sqlfilters= '')
 List products. More...
 
 post ($request_data=null)
 Create product object. More...
 
 put ($id, $request_data=null)
 Update product. More...
 
 delete ($id)
 Delete product. More...
 
 getSubproducts ($id)
 Get the list of subproducts of the product. More...
 
 addSubproducts ($id, $subproduct_id, $qty, $incdec=1)
 Add subproduct. More...
 
 delSubproducts ($id, $subproduct_id)
 Remove subproduct. More...
 
 getCategories ($id, $sortfield="s.rowid", $sortorder= 'ASC', $limit=0, $page=0)
 Get categories for a product. More...
 
 getCustomerPricesPerSegment ($id)
 Get prices per segment for a product. More...
 
 getCustomerPricesPerCustomer ($id, $thirdparty_id= '')
 Get prices per customer for a product. More...
 
 getCustomerPricesPerQuantity ($id)
 Get prices per quantity for a product. More...
 
 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. More...
 
 deletePurchasePrice ($id, $priceid)
 Delete purchase price for a product. More...
 
 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. More...
 
 getPurchasePrices ($id, $ref= '', $ref_ext= '', $barcode= '')
 Get purchase prices for a product. More...
 
 getAttributes ($sortfield="t.ref", $sortorder= 'ASC', $limit=100, $page=0, $sqlfilters= '')
 Get attributes. More...
 
 getAttributeById ($id)
 Get attribute by ID. More...
 
 getAttributesByRef ($ref)
 Get attributes by ref. More...
 
 getAttributesByRefExt ($ref_ext)
 Get attributes by ref_ext. More...
 
 addAttributes ($ref, $label, $ref_ext= '')
 Add attributes. More...
 
 putAttributes ($id, $request_data=null)
 Update attributes by id. More...
 
 deleteAttributes ($id)
 Delete attributes by id. More...
 
 getAttributeValueById ($id)
 Get attribute value by id. More...
 
 getAttributeValueByRef ($id, $ref)
 Get attribute value by ref. More...
 
 deleteAttributeValueByRef ($id, $ref)
 Delete attribute value by ref. More...
 
 getAttributeValues ($id)
 Get all values for an attribute id. More...
 
 getAttributeValuesByRef ($ref)
 Get all values for an attribute ref. More...
 
 addAttributeValue ($id, $ref, $value)
 Add attribute value. More...
 
 putAttributeValue ($id, $request_data)
 Update attribute value. More...
 
 deleteAttributeValueById ($id)
 Delete attribute value by id. More...
 
 getVariants ($id)
 Get product variants. More...
 
 getVariantsByProdRef ($ref)
 Get product variants by Product ref. More...
 
 addVariant ($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference= '', $ref_ext= '')
 Add variant. More...
 
 addVariantByProductRef ($ref, $weight_impact, $price_impact, $price_impact_is_percent, $features)
 Add variant by product ref. More...
 
 putVariant ($id, $request_data=null)
 Put product variants. More...
 
 deleteVariant ($id)
 Delete product variants. More...
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir= '', $refreshCache=false)
 Constructor. More...
 

Protected Member Functions

 _cleanObjectDatas ($object)
 Clean sensible object datas. More...
 
- Protected Member Functions inherited from DolibarrApi
 _cleanObjectDatas ($object)
 Executed method when API is called without parameter. More...
 
 _checkFilters ($sqlfilters)
 Return if a $sqlfilters parameter is valid. More...
 

Private Member Functions

 _validate ($data)
 Validate fields before create or update object. More...
 
 _fetch ($id, $ref= '', $ref_ext= '', $barcode= '', $includestockdata=0, $includesubproducts=false, $includeparentid=false)
 Get properties of a product object. More...
 

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')
 Check user access to a resource. More...
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria. More...
 

Detailed Description

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

Member Function Documentation

Products::_cleanObjectDatas (   $object)
protected

Clean sensible object datas.

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

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

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

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

Get properties of a 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)
Returns
array|mixed Data without useless information
Exceptions
RestException401
RestException403
RestException404

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

References DolibarrApi\_checkAccessToResource(), and db.

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

Products::_validate (   $data)
private

Validate fields before create or update object.

Parameters
array$dataDatas to validate
Returns
array
Exceptions
RestException

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

Referenced by post().

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

Add attributes.

Parameters
string$refReference of Attribute
string$labelLabel of Attribute
string$ref_extReference of Attribute
Returns
int
Exceptions
RestException500
RestException401

POST attributes

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

References db.

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

Add attribute value.

Parameters
int$idID of Attribute
string$refReference of Attribute value
string$valueValue of Attribute value
Returns
int
Exceptions
RestException500
RestException401

POST attributes/{id}/values

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

References db.

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.

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)
string$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, DONOTORDER)
array$localtaxes_arrayArray with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function).
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
RestException401

POST {id}/purchase_prices

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

References DolibarrApi\_checkAccessToResource(), and db.

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

Add subproduct.

Link a product/service to a parent product/service

Parameters
int$idId of parent product/service
int$subproduct_idId of child product/service
int$qtyQuantity
int$incdec1=Increase/decrease stock of child when parent stock increase/decrease
Returns
int
Exceptions
RestException
RestException401
RestException404

POST {id}/subproducts/add

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

References DolibarrApi\_checkAccessToResource().

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, ...)

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, ...)
string$referenceCustomized reference of variant
string$ref_extExternal reference of variant
Returns
int
Exceptions
RestException500
RestException401
RestException404

POST {id}/variants

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

References db, and price2num().

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, ...)

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, ...)
Returns
int
Exceptions
RestException500
RestException401
RestException404

POST ref/{ref}/variants

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

References db, and price2num().

Products::delete (   $id)

Delete product.

Parameters
int$idProduct ID
Returns
array

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

References DolibarrApi\_checkAccessToResource().

Products::deleteAttributes (   $id)

Delete attributes by id.

Parameters
int$idID of Attribute
Returns
int Result of deletion
Exceptions
RestException500
RestException401

DELETE attributes/{id}

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

References db.

Products::deleteAttributeValueById (   $id)

Delete attribute value by id.

Parameters
int$idID of Attribute value
Returns
int
Exceptions
RestException500
RestException401

DELETE attributes/values/{id}

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

References db.

Products::deleteAttributeValueByRef (   $id,
  $ref 
)

Delete attribute value by ref.

Parameters
int$idID of Attribute
string$refRef of Attribute value
Returns
int
Exceptions
RestException401

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

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

References db, and getEntity().

Products::deletePurchasePrice (   $id,
  $priceid 
)

Delete purchase price for a product.

Parameters
int$idProduct ID
int$priceidpurchase price ID

DELETE {id}/purchase_prices/{priceid}

Returns
int
Exceptions
RestException401
RestException404

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

References DolibarrApi\_checkAccessToResource().

Products::deleteVariant (   $id)

Delete product variants.

Parameters
int$idID of Variant
Returns
int Result of deletion
Exceptions
RestException500
RestException401

DELETE variants/{id}

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

References db.

Products::delSubproducts (   $id,
  $subproduct_id 
)

Remove subproduct.

Unlink a product/service from a parent product/service

Parameters
int$idId of parent product/service
int$subproduct_idId of child product/service
Returns
int
Exceptions
RestException401
RestException404

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

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

References DolibarrApi\_checkAccessToResource().

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

Get properties of a product object by id.

Return an array with product information.

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)
Returns
array|mixed Data without useless information
Exceptions
RestException401
RestException403
RestException404

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

References _fetch().

Products::getAttributeById (   $id)

Get attribute by ID.

Parameters
int$idID of Attribute
Returns
array
Exceptions
RestException
RestException401
RestException404

GET attributes/{id}

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

References db.

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

Get attributes.

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)"
Returns
array
Exceptions
RestExceptionGET attributes

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

References DolibarrApi\_checkFilters(), _cleanObjectDatas(), and db.

Products::getAttributesByRef (   $ref)

Get attributes by ref.

Parameters
string$refReference of Attribute
Returns
array
Exceptions
RestException500
RestException401

GET attributes/ref/{ref}

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

References $resql, db, and getEntity().

Products::getAttributesByRefExt (   $ref_ext)

Get attributes by ref_ext.

Parameters
string$ref_extExternal reference of Attribute
Returns
array
Exceptions
RestException500
RestException401

GET attributes/ref_ext/{ref_ext}

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

References $resql, db, and getEntity().

Products::getAttributeValueById (   $id)

Get attribute value by id.

Parameters
int$idID of Attribute value
Returns
array
Exceptions
RestException500
RestException401

GET attributes/values/{id}

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

References db, and getEntity().

Products::getAttributeValueByRef (   $id,
  $ref 
)

Get attribute value by ref.

Parameters
int$idID of Attribute value
string$refRef of Attribute value
Returns
array
Exceptions
RestException500
RestException401

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

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

References db, and getEntity().

Products::getAttributeValues (   $id)

Get all values for an attribute id.

Parameters
int$idID of an Attribute
Returns
array
Exceptions
RestException401
RestException500

GET attributes/{id}/values

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

References db.

Products::getAttributeValuesByRef (   $ref)

Get all values for an attribute ref.

Parameters
string$refRef of an Attribute
Returns
array
Exceptions
RestException401

GET attributes/ref/{ref}/values

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

References $resql, and db.

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

Get properties of a product object by barcode.

Return an array with product information.

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)
Returns
array|mixed Data without useless information

GET barcode/{barcode}

Exceptions
RestException401
RestException403
RestException404

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

References _fetch().

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

Get properties of a product object by ref.

Return an array with product information.

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)
Returns
array|mixed Data without useless information

GET ref/{ref}

Exceptions
RestException401
RestException403
RestException404

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

References _fetch().

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

Get properties of a product object by ref_ext.

Return an array with product information.

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)
Returns
array|mixed Data without useless information

GET ref_ext/{ref_ext}

Exceptions
RestException401
RestException403
RestException404

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

References _fetch().

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

Get categories for a product.

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

GET {id}/categories

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

References db.

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

Get prices per customer for a product.

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

GET {id}/selling_multiprices/per_customer

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

References db.

Products::getCustomerPricesPerQuantity (   $id)

Get prices per quantity for a product.

Parameters
int$idID of product
Returns
mixed

GET {id}/selling_multiprices/per_quantity

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

Products::getCustomerPricesPerSegment (   $id)

Get prices per segment for a product.

Parameters
int$idID of product
Returns
mixed

GET {id}/selling_multiprices/per_segment

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

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

Parameters
int$idID of product
string$refRef of element
string$ref_extRef ext of element
string$barcodeBarcode of element
Returns
array|mixed Data without useless information

GET {id}/purchase_prices

Exceptions
RestException401
RestException403
RestException404

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

References DolibarrApi\_checkAccessToResource(), _cleanObjectDatas(), and db.

Products::getSubproducts (   $id)

Get the list of subproducts of the product.

Parameters
int$idId of parent product/service
Returns
array
Exceptions
RestException
RestException401
RestException404

GET {id}/subproducts

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

References DolibarrApi\_checkAccessToResource().

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.

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

GET purchase_prices

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

References DolibarrApi\_checkFilters(), _cleanObjectDatas(), and db.

Products::getVariants (   $id)

Get product variants.

Parameters
int$idID of Product
Returns
array
Exceptions
RestException500
RestException401

GET {id}/variants

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

References db.

Products::getVariantsByProdRef (   $ref)

Get product variants by Product ref.

Parameters
string$refRef of Product
Returns
array
Exceptions
RestException500
RestException401

GET ref/{ref}/variants

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

References db.

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

List products.

Get a list of products

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)"
Returns
array Array of product objects

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

References DolibarrApi\_checkFilters(), _cleanObjectDatas(), and db.

Products::post (   $request_data = null)

Create product object.

Parameters
array$request_dataRequest data
Returns
int ID of product

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

References _validate().

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

Update product.

Price will be updated by this API only if option is set on "One price per product". See other APIs for other price modes.

Parameters
int$idId of product to update
array$request_dataDatas
Returns
int
Exceptions
RestException401
RestException404

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

References DolibarrApi\_checkAccessToResource(), and dol_clone().

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

Update attributes by id.

Parameters
int$idID of Attribute
array$request_dataDatas
Returns
array
Exceptions
RestException
RestException401
RestException404

PUT attributes/{id}

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

References db.

Products::putAttributeValue (   $id,
  $request_data 
)

Update attribute value.

Parameters
int$idID of Attribute
array$request_dataDatas
Returns
array
Exceptions
RestException401
RestException500

PUT attributes/values/{id}

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

References db.

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

Put product variants.

Parameters
int$idID of Variant
array$request_dataDatas
Returns
int
Exceptions
RestException500
RestException401

PUT variants/{id}

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

References db.


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