dolibarr 21.0.0-alpha
|
Class ProductCombination Used to represent the relation between a product and one of its variants. More...
Public Member Functions | |
__construct (DoliDB $db) | |
Constructor. | |
fetch ($rowid) | |
Retrieves a ProductCombination 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, $sort_by_ref=false) | |
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 (filtered on its 'to sell' variants) | |
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. | |
Class ProductCombination Used to represent the relation between a product and one of its variants.
Example: a product "shirt" has two variants "shirt XL white" and "shirt XL grey". This is represented with two ProductCombination objects:
Definition at line 41 of file ProductCombination.class.php.
ProductCombination::__construct | ( | DoliDB | $db | ) |
Constructor.
Definition at line 121 of file ProductCombination.class.php.
Copies all product combinations from the origin product to the destination product.
User | $user | Object user |
int | $origProductId | Origin product id |
Product | $destProduct | Destination product |
Definition at line 977 of file ProductCombination.class.php.
References createProductCombination(), and fetchAllByFkProductParent().
ProductCombination::countNbOfCombinationForFkProductParent | ( | $fk_product_parent | ) |
Retrieves all product combinations by the product parent row id.
int | $fk_product_parent | Id of parent product |
Definition at line 355 of file ProductCombination.class.php.
References getEntity().
ProductCombination::create | ( | $user | ) |
Creates a product attribute combination.
User | $user | Object user |
Definition at line 377 of file ProductCombination.class.php.
References getDolGlobalString(), and saveCombinationPriceLevels().
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 [...] ), [...] )
User | $user | User |
Product | $product | Parent Product |
array<int,int> | $combinations Attribute and value combinations. | |
array<int,array<int,array{weight:string|float,price:string|float}>> | $variations Price and weight variations (example: $variations[fk_product_attribute][fk_product_attribute_value]['weight']) | |
bool | bool[] | $price_var_percent | Is the price variation value a relative variation (in %)? (it is an array if global constant "PRODUIT_MULTIPRICES" is on) |
false | float | float[] | $forced_pricevar | Value of the price variation if it is forced ; in currency or percent. (it is an array if global constant "PRODUIT_MULTIPRICES" is on) |
false | float | $forced_weightvar | Value of the weight variation if it is forced |
false | string | $forced_refvar | Value of the reference if it is forced |
string | $ref_ext | External reference |
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 756 of file ProductCombination.class.php.
References getDolGlobalString(), and price2num().
Referenced by copyAll().
ProductCombination::delete | ( | User | $user | ) |
Deletes a product combination.
User | $user | Object user |
Definition at line 449 of file ProductCombination.class.php.
ProductCombination::deleteByFkProductParent | ( | $user, | |
$fk_product_parent ) |
Deletes all product combinations of a parent product.
User | $user | Object user |
int | $fk_product_parent | Rowid of parent product |
Definition at line 480 of file ProductCombination.class.php.
References fetchAllByFkProductParent().
ProductCombination::fetch | ( | $rowid | ) |
Retrieves a ProductCombination by its rowid.
int | $rowid | ID of the ProductCombination |
Definition at line 135 of file ProductCombination.class.php.
References fetchCombinationPriceLevels(), getDolGlobalString(), and getEntity().
ProductCombination::fetchAllByFkProductParent | ( | $fk_product_parent, | |
$sort_by_ref = false ) |
Retrieves all product combinations by the product parent row id.
int | $fk_product_parent | Rowid of parent product |
bool | $sort_by_ref | Sort result by product child reference |
Definition at line 307 of file ProductCombination.class.php.
References getDolGlobalString(), and getEntity().
Referenced by copyAll(), and deleteByFkProductParent().
ProductCombination::fetchByFkProductChild | ( | $productid, | |
$donotloadpricelevel = 0 ) |
Retrieves information of a variant product and ID of its parent product.
int | $productid | Product ID of variant |
int | $donotloadpricelevel | Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect. |
Definition at line 267 of file ProductCombination.class.php.
References fetchCombinationPriceLevels(), getDolGlobalString(), and getEntity().
ProductCombination::fetchByProductCombination2ValuePairs | ( | $prodid, | |
array | $features ) |
Retrieves the combination that matches the given features.
int | $prodid | Id of parent product |
array<string,string> | $features Format: [$attr] => $attr_val |
mixed | $v | Feature information of a product. |
Definition at line 638 of file ProductCombination.class.php.
ProductCombination::fetchCombinationPriceLevels | ( | $fk_price_level = 0, | |
$useCache = true ) |
Retrieves combination price levels.
int | $fk_price_level | The price level to fetch, use 0 for all |
bool | $useCache | To use cache or not |
for auto retrocompatibility with last behavior
Definition at line 174 of file ProductCombination.class.php.
References ProductCombinationLevel\createFromParent(), and getDolGlobalString().
Referenced by fetch(), and fetchByFkProductChild().
ProductCombination::getCombinationLabel | ( | $prod_child | ) |
Return label for combinations.
int | $prod_child | id of child |
Definition at line 1019 of file ProductCombination.class.php.
Referenced by updateProperties().
ProductCombination::getUniqueAttributesAndValuesByFkProductParent | ( | $productid | ) |
Retrieves all unique attributes for a parent product (filtered on its 'to sell' variants)
int | $productid | Parent Product rowid |
Definition at line 687 of file ProductCombination.class.php.
ProductCombination::saveCombinationPriceLevels | ( | $clean = 1 | ) |
Retrieves combination price levels.
int | $clean | Levels of PRODUIT_MULTIPRICES_LIMIT |
Definition at line 221 of file ProductCombination.class.php.
ProductCombination::update | ( | User | $user | ) |
Updates a product combination.
User | $user | Object user |
Definition at line 413 of file ProductCombination.class.php.
References getDolGlobalString(), saveCombinationPriceLevels(), and updateProperties().
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.
Definition at line 515 of file ProductCombination.class.php.
References getCombinationLabel(), and getDolGlobalString().
Referenced by update().