dolibarr 19.0.3
ProductCombination Class Reference

Class ProductCombination Used to represent a product combination. More...

Public Member Functions

 __construct (DoliDB $db)
 Constructor.
 
 fetch ($rowid)
 Retrieves a combination by its rowid.
 
 fetchCombinationPriceLevels ($fk_price_level=0, $useCache=true)
 Retrieves combination price levels.
 
 saveCombinationPriceLevels ($clean=1)
 Retrieves combination price levels.
 
 fetchByFkProductChild ($productid, $donotloadpricelevel=0)
 Retrieves information of a variant product and ID of its parent product.
 
 fetchAllByFkProductParent ($fk_product_parent)
 Retrieves all product combinations by the product parent row id.
 
 countNbOfCombinationForFkProductParent ($fk_product_parent)
 Retrieves all product combinations by the product parent row id.
 
 create ($user)
 Creates a product attribute combination.
 
 update (User $user)
 Updates a product combination.
 
 delete (User $user)
 Deletes a product combination.
 
 deleteByFkProductParent ($user, $fk_product_parent)
 Deletes all product combinations of a parent product.
 
 updateProperties (Product $parent, User $user)
 Updates the weight of the child product.
 
 fetchByProductCombination2ValuePairs ($prodid, array $features)
 Retrieves the combination that matches the given features.
 
 getUniqueAttributesAndValuesByFkProductParent ($productid)
 Retrieves all unique attributes for a parent product.
 
 createProductCombination (User $user, Product $product, array $combinations, array $variations, $price_var_percent=false, $forced_pricevar=false, $forced_weightvar=false, $forced_refvar=false, $ref_ext='')
 Creates a product combination.
 
 copyAll (User $user, $origProductId, Product $destProduct)
 Copies all product combinations from the origin product to the destination product.
 
 getCombinationLabel ($prod_child)
 Return label for combinations.
 

Detailed Description

Class ProductCombination Used to represent a product combination.

Definition at line 24 of file ProductCombination.class.php.

Constructor & Destructor Documentation

◆ __construct()

ProductCombination::__construct ( DoliDB $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 101 of file ProductCombination.class.php.

Member Function Documentation

◆ copyAll()

ProductCombination::copyAll ( User $user,
$origProductId,
Product $destProduct )

Copies all product combinations from the origin product to the destination product.

Parameters
User$userObject user
int$origProductIdOrigin product id
Product$destProductDestination product
Returns
int >0 OK <0 KO

Definition at line 937 of file ProductCombination.class.php.

References createProductCombination(), and fetchAllByFkProductParent().

◆ countNbOfCombinationForFkProductParent()

ProductCombination::countNbOfCombinationForFkProductParent ( $fk_product_parent)

Retrieves all product combinations by the product parent row id.

Parameters
int$fk_product_parentId of parent product
Returns
int Nb of record

Definition at line 331 of file ProductCombination.class.php.

References getEntity().

◆ create()

ProductCombination::create ( $user)

Creates a product attribute combination.

Parameters
User$userObject user
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 353 of file ProductCombination.class.php.

References getDolGlobalString(), and saveCombinationPriceLevels().

◆ createProductCombination()

ProductCombination::createProductCombination ( User $user,
Product $product,
array $combinations,
array $variations,
$price_var_percent = false,
$forced_pricevar = false,
$forced_weightvar = false,
$forced_refvar = false,
$ref_ext = '' )

Creates a product combination.

Check usages to find more about its use Format of $combinations array: array( 0 => array( attr => value, attr2 => value [...] ), [...] )

Parameters
User$userObject user
Product$productParent product
array$combinationsAttribute and value combinations.
array$variationsPrice and weight variations
bool | array$price_var_percentIs the price variation a relative variation?
bool | float$forced_pricevarIf the price variation is forced
bool | float$forced_weightvarIf the weight variation is forced
bool | string$forced_refvarIf the reference is forced
string$ref_extExternal reference
Returns
int Return integer <0 KO, >0 OK

If there is an existing combination, then we update the prices and weight Otherwise, we try adding a random number to the ref

Definition at line 716 of file ProductCombination.class.php.

References getDolGlobalString(), and price2num().

Referenced by copyAll().

◆ delete()

ProductCombination::delete ( User $user)

Deletes a product combination.

Parameters
User$userObject user
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 425 of file ProductCombination.class.php.

◆ deleteByFkProductParent()

ProductCombination::deleteByFkProductParent ( $user,
$fk_product_parent )

Deletes all product combinations of a parent product.

Parameters
User$userObject user
int$fk_product_parentRowid of parent product
Returns
int Return integer <0 KO >0 OK

Definition at line 456 of file ProductCombination.class.php.

References fetchAllByFkProductParent().

◆ fetch()

ProductCombination::fetch ( $rowid)

Retrieves a combination by its rowid.

Parameters
int$rowidRow id
Returns
int Return integer <0 KO, >0 OK

Definition at line 115 of file ProductCombination.class.php.

References fetchCombinationPriceLevels(), getDolGlobalString(), and getEntity().

◆ fetchAllByFkProductParent()

ProductCombination::fetchAllByFkProductParent ( $fk_product_parent)

Retrieves all product combinations by the product parent row id.

Parameters
int$fk_product_parentRowid of parent product
Returns
int|ProductCombination[] Return integer <0 KO

Definition at line 289 of file ProductCombination.class.php.

References getDolGlobalString(), and getEntity().

Referenced by copyAll(), and deleteByFkProductParent().

◆ fetchByFkProductChild()

ProductCombination::fetchByFkProductChild ( $productid,
$donotloadpricelevel = 0 )

Retrieves information of a variant product and ID of its parent product.

Parameters
int$productidProduct ID of variant
int$donotloadpricelevelAvoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect.
Returns
int Return integer <0 if KO, 0 if product ID is not ID of a variant product (so parent not found), >0 if OK (ID of parent)

Definition at line 250 of file ProductCombination.class.php.

References fetchCombinationPriceLevels(), getDolGlobalString(), and getEntity().

◆ fetchByProductCombination2ValuePairs()

ProductCombination::fetchByProductCombination2ValuePairs ( $prodid,
array $features )

Retrieves the combination that matches the given features.

Parameters
int$prodidId of parent product
array$featuresFormat: [$attr] => $attr_val
Returns
false|ProductCombination False if not found

Definition at line 613 of file ProductCombination.class.php.

◆ fetchCombinationPriceLevels()

ProductCombination::fetchCombinationPriceLevels ( $fk_price_level = 0,
$useCache = true )

Retrieves combination price levels.

Parameters
int$fk_price_levelThe price level to fetch, use 0 for all
bool$useCacheTo use cache or not
Returns
int Return integer <0 KO, >0 OK

for auto retrocompatibility with last behavior

Definition at line 156 of file ProductCombination.class.php.

References ProductCombinationLevel\createFromParent().

Referenced by fetch(), and fetchByFkProductChild().

◆ getCombinationLabel()

ProductCombination::getCombinationLabel ( $prod_child)

Return label for combinations.

Parameters
int$prod_childid of child
Returns
string combination label

Definition at line 979 of file ProductCombination.class.php.

Referenced by updateProperties().

◆ getUniqueAttributesAndValuesByFkProductParent()

ProductCombination::getUniqueAttributesAndValuesByFkProductParent ( $productid)

Retrieves all unique attributes for a parent product.

Parameters
int$productidProduct rowid
Returns
ProductAttribute[] Array of attributes

Definition at line 654 of file ProductCombination.class.php.

◆ saveCombinationPriceLevels()

ProductCombination::saveCombinationPriceLevels ( $clean = 1)

Retrieves combination price levels.

Parameters
int$cleanLevels of PRODUIT_MULTIPRICES_LIMIT
Returns
int Return integer <0 KO, >0 OK

Definition at line 204 of file ProductCombination.class.php.

Referenced by create(), and update().

◆ update()

ProductCombination::update ( User $user)

Updates a product combination.

Parameters
User$userObject user
Returns
int Return integer <0 KO, >0 OK

Definition at line 389 of file ProductCombination.class.php.

References getDolGlobalString(), saveCombinationPriceLevels(), and updateProperties().

◆ updateProperties()

ProductCombination::updateProperties ( Product $parent,
User $user )

Updates the weight of the child product.

The price must be updated using Product\updatePrices. This method is called by the update() of a product.

Parameters
Product$parentParent product
User$userObject user
Returns
int >0 if OK, <0 if KO

Definition at line 491 of file ProductCombination.class.php.

References getCombinationLabel(), and getDolGlobalString().

Referenced by update().


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