class ProductCombination (View source)

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:

  • One for "shirt XL white":
    • $object->fk_product_parent ID of the Product object "shirt"
    • $object->fk_product_child ID of the Product object "shirt XL white"
  • Another for "shirt XL grey":
    • $object->fk_product_parent ID of the Product object "shirt"
    • $object->fk_product_child ID of the Product object "shirt XL grey"

Properties

DoliDB $db

Database handler

int $id

Rowid of this ProductCombination

int $fk_product_parent

Rowid of the parent Product

int $fk_product_child

Rowid of the variant Product

float $variation_price

Price variation

bool|array $variation_price_percentage

Is the price variation a relative variation? Can be an array if multiprice feature per level is enabled.

float $variation_weight

Weight variation

int $entity

Combination entity

ProductCombinationLevel[] $combination_price_levels

Combination price level

string $variation_ref_ext

External ref

string $error

Error message

string[] $errors

Array of error messages

Methods

__construct(DoliDB $db)

Constructor

int<-1, 1>
fetch(int $rowid)

Retrieves a ProductCombination by its rowid

int<-1, 1>
fetchCombinationPriceLevels(int $fk_price_level = 0, bool $useCache = true)

Retrieves combination price levels

int
saveCombinationPriceLevels(int $clean = 1)

Retrieves combination price levels

int
fetchByFkProductChild(int $productid, int $donotloadpricelevel = 0)

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

fetchAllByFkProductParent(int $fk_product_parent, bool $sort_by_ref = false)

Retrieves all product combinations by the product parent row id

int
countNbOfCombinationForFkProductParent(int $fk_product_parent)

Retrieves all product combinations by the product parent row id

int
create(User $user)

Creates a product attribute combination

int
update(User $user)

Updates a product combination

int
delete(User $user)

Deletes a product combination

int
deleteByFkProductParent(User $user, int $fk_product_parent)

Deletes all product combinations of a parent product

int
updateProperties(Product $parent, User $user)

Updates the weight of the child product. The price must be updated using Product::updatePrices.

fetchByProductCombination2ValuePairs(int $prodid, array $features)

Retrieves the combination that matches the given features.

ProductAttributeValue[]}>
getUniqueAttributesAndValuesByFkProductParent(int $productid)

Retrieves all unique attributes for a parent product (filtered on its 'to sell' variants)

int<-1, 1>
createProductCombination(User $user, Product $product, array $combinations, array $variations, bool|bool[] $price_var_percent = false, false|float|float[] $forced_pricevar = false, false|float $forced_weightvar = false, false|string $forced_refvar = false, string $ref_ext = '', bool $clone_categories = false)

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

int
copyAll(User $user, int $origProductId, Product $destProduct)

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

string
getCombinationLabel(int $prod_child)

Return label for combinations

Details

__construct(DoliDB $db)

Constructor

Parameters

DoliDB $db

Database handler

int<-1, 1> fetch(int $rowid)

Retrieves a ProductCombination by its rowid

Parameters

int $rowid

ID of the ProductCombination

Return Value

int<-1, 1>

-1 if KO, 1 if OK

int<-1, 1> fetchCombinationPriceLevels(int $fk_price_level = 0, bool $useCache = true)

Retrieves combination price levels

Parameters

int $fk_price_level

The price level to fetch, use 0 for all

bool $useCache

To use cache or not

Return Value

int<-1, 1>

-1 if KO, 1 if OK

int saveCombinationPriceLevels(int $clean = 1)

Retrieves combination price levels

Parameters

int $clean

Levels of PRODUIT_MULTIPRICES_LIMIT

Return Value

int

Return integer <0 KO, >0 OK

int fetchByFkProductChild(int $productid, int $donotloadpricelevel = 0)

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

Parameters

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.

Return Value

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)

int|ProductCombination[] fetchAllByFkProductParent(int $fk_product_parent, bool $sort_by_ref = false)

Retrieves all product combinations by the product parent row id

Parameters

int $fk_product_parent

Rowid of parent product

bool $sort_by_ref

Sort result by product child reference

Return Value

int|ProductCombination[]

Return integer <0 KO

int countNbOfCombinationForFkProductParent(int $fk_product_parent)

Retrieves all product combinations by the product parent row id

Parameters

int $fk_product_parent

Id of parent product

Return Value

int

Nb of record

int create(User $user)

Creates a product attribute combination

Parameters

User $user

Object user

Return Value

int

Return integer <0 if KO, >0 if OK

int update(User $user)

Updates a product combination

Parameters

User $user

Object user

Return Value

int

Return integer <0 KO, >0 OK

int delete(User $user)

Deletes a product combination

Parameters

User $user

Object user

Return Value

int

Return integer <0 if KO, >0 if OK

int deleteByFkProductParent(User $user, int $fk_product_parent)

Deletes all product combinations of a parent product

Parameters

User $user

Object user

int $fk_product_parent

Rowid of parent product

Return Value

int

Return integer <0 if KO, >0 if OK

int 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 $parent

Parent product

User $user

Object user

Return Value

int

0 if OK, <0 if KO

false|ProductCombination fetchByProductCombination2ValuePairs(int $prodid, array $features)

Retrieves the combination that matches the given features.

Parameters

int $prodid

Id of parent product

array $features

Format: [$attr] => $attr_val

Return Value

false|ProductCombination

False if not found

ProductAttributeValue[]}> getUniqueAttributesAndValuesByFkProductParent(int $productid)

Retrieves all unique attributes for a parent product (filtered on its 'to sell' variants)

Parameters

int $productid

Parent Product rowid

Return Value

ProductAttributeValue[]}>

Array of attributes

int<-1, 1> createProductCombination(User $user, Product $product, array $combinations, array $variations, bool|bool[] $price_var_percent = false, false|float|float[] $forced_pricevar = false, false|float $forced_weightvar = false, false|string $forced_refvar = false, string $ref_ext = '', bool $clone_categories = false)

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 $user User
Product $product

Parent Product

array $combinations

Attribute and value combinations.

array $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

Return Value

int<-1, 1>

Return integer <0 KO, >0 OK

int copyAll(User $user, int $origProductId, Product $destProduct)

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

Parameters

User $user

Object user

int $origProductId

Origin product id

Product $destProduct

Destination product

Return Value

int

0 OK <0 KO

string getCombinationLabel(int $prod_child)

Return label for combinations

Parameters

int $prod_child

id of child

Return Value

string

combination label