|
dolibarr 25.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, $ref_product_child='') | |
| Retrieves a ProductCombination by its rowid or by the ref of its child product. | |
| 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. | |
| deleteLinksByProduct ($fk_product) | |
| Delete every combination row referencing a product, without deleting any product. | |
| 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. | |
| resolveAttributeValueId (&$arrayrecord, $arrayfield, $pos) | |
| Resolves the id of an attribute value from its ref, for the 'compute' rule of the import of the attribute/value links. | |
| 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='', $clone_categories=false, $forcedcombination=null) | |
| 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 42 of file ProductCombination.class.php.
| ProductCombination::__construct | ( | DoliDB | $db | ) |
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 1301 of file ProductCombination.class.php.
References createProductCombination(), fetchAllByFkProductParent(), and getDolGlobalInt().
| 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 402 of file ProductCombination.class.php.
References getEntity().
| ProductCombination::create | ( | $user | ) |
Creates a product attribute combination.
| User | $user | Object user |
Definition at line 424 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 = '', | |||
| $clone_categories = false, | |||
| $forcedcombination = null ) |
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 |
| bool | $clone_categories | Add parent product categories to the created variant |
| ?ProductCombination | $forcedcombination | Combination to reconcile. Without it, the combination is looked up from its value set, which is ambiguous as long as the set is partial. |
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 942 of file ProductCombination.class.php.
References $conf, dol_syslog(), getDolGlobalInt(), getDolGlobalString(), and price2num().
Referenced by copyAll().
| ProductCombination::delete | ( | User | $user | ) |
Deletes a product combination.
| User | $user | Object user |
Definition at line 499 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 584 of file ProductCombination.class.php.
References fetchAllByFkProductParent().
| ProductCombination::deleteLinksByProduct | ( | $fk_product | ) |
Delete every combination row referencing a product, without deleting any product.
Used when the product is removed while the variants module is disabled: the rows would otherwise be refused by the foreign key on fk_product_parent.
| int | $fk_product | Id of the product, as a parent or as a child |
Definition at line 532 of file ProductCombination.class.php.
References dol_syslog().
| ProductCombination::fetch | ( | $rowid, | |
| $ref_product_child = '' ) |
Retrieves a ProductCombination by its rowid or by the ref of its child product.
Note: $rowid must not be typed as int. The import engine resolves a foreign key by calling fetch('', $ref) and an empty string is not a numeric string in PHP 8.
| int | string | $rowid | ID of the ProductCombination |
| string | $ref_product_child | Ref of the child (variant) product, used when $rowid is empty |
Definition at line 155 of file ProductCombination.class.php.
References dol_syslog(), fetchCombinationPriceLevels(), and getDolGlobalString().
| 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 356 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 316 of file ProductCombination.class.php.
References $conf, fetchCombinationPriceLevels(), getDolGlobalString(), and getEntity().
| ProductCombination::fetchByProductCombination2ValuePairs | ( | $prodid, | |
| array | $features ) |
Retrieves the combination that matches the given features.
| int | $prodid | Id of parent product |
| array<int|string,int|string> | $features Format: [$attr] => $attr_val |
| mixed | $v | Feature information of a product. |
Definition at line 744 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 223 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 1356 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 867 of file ProductCombination.class.php.
| ProductCombination::resolveAttributeValueId | ( | & | $arrayrecord, |
| $arrayfield, | |||
| $pos ) |
Resolves the id of an attribute value from its ref, for the 'compute' rule of the import of the attribute/value links.
A value ref is only unique for a given attribute, and the fetchidfromref rule of the import engine resolves every column without any context, so the attribute ref has to be read from the same file line. The 'pac2v.fk_prod_attr' alias is hard coded here on purpose: it is the alias declared by the import dataset of modVariants, and the engine has no way to pass it.
| array<int,array{val:string,type:int}> | $arrayrecord Line read from the file, by reference (the signature of the engine requires it) | |
| array<string,int> | $arrayfield Field alias => column index of the line | |
| int | $pos | Column index of the value ref |
Definition at line 801 of file ProductCombination.class.php.
References dol_syslog().
| ProductCombination::saveCombinationPriceLevels | ( | $clean = 1 | ) |
Retrieves combination price levels.
| int | $clean | Levels of PRODUIT_MULTIPRICES_LIMIT |
Definition at line 270 of file ProductCombination.class.php.
References $conf.
| ProductCombination::update | ( | User | $user | ) |
Updates a product combination.
| User | $user | Object user |
Definition at line 458 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 624 of file ProductCombination.class.php.
References getCombinationLabel(), getDolGlobalInt(), and getDolGlobalString().
Referenced by update().