dolibarr 25.0.0-alpha
InterfaceVariantsImport Class Reference

Class of triggered functions that reconcile imported variants with the business logic of the screen. More...

Inheritance diagram for InterfaceVariantsImport:
Collaboration diagram for InterfaceVariantsImport:

Public Member Functions

 __construct ($db)
 Constructor.
 
 runTrigger ($action, $object, User $user, Translate $langs, Conf $conf)
 Function called when a Dolibarr business event is done.
 
- Public Member Functions inherited from DolibarrTriggers
 __construct (DoliDB $db)
 Constructor.
 
 getName ()
 Returns the name of the trigger file.
 
 getDesc ()
 Returns the description of trigger file.
 
 getVersion ()
 Returns the version of the trigger file.
 
 setErrorsFromObject ($object)
 setErrorsFromObject
 

Public Attributes

const VARIANTS_TABLES
 Tables of the module that need a business reconciliation after an import.
 

Private Member Functions

 refuseBulkModeOnVariants ($object, Translate $langs)
 Refuse the fast_bulk mode on the tables of the module.
 
 countCombinations ($fkproductparent=0, $fkproductchild=0, $fkproductparentnot=0)
 Count the combinations matching the given products, in the current entity.
 
 reconcileCombination ($rowid, User $user, Translate $langs)
 Check the consistency of an imported combination and propagate it to the child product.
 
 reconcileValuePair ($rowid, User $user, Translate $langs)
 Reconcile a variant from one of its attribute/value links.
 
 reconcilePriceLevel ($rowid, User $user, Translate $langs)
 Propagate an imported price level to the child product.
 

Detailed Description

Class of triggered functions that reconcile imported variants with the business logic of the screen.

The import engine only runs raw SQL: it writes a row of llx_product_attribute_combination without creating nor refreshing the child product. This trigger calls back ProductCombination\createProductCombination(), the very method used by the screen (variants/combinations.php) and by the REST API (api_products.class.php), so that an imported variant is identical to a variant entered on screen.

It never rolls back: it runs inside the transaction of the import and DoliDB\rollback() only decrements the counter when the transaction is nested. Returning a negative value is the only way to have imports/import.php roll the whole import back.

Limitation: the screen refuses two combinations of the same parent carrying the same set of attribute values, this trigger cannot. The value set of an imported variant is spread over several lines of the file and the engine offers no end of import event in strict_line mode, so a set read here is only a partial set and comparing it would reject legitimate variants (a parent declined by colour alone and by colour plus size shares a partial set). Only the weaker invariant that can be decided on a single line is enforced: a child product belongs to exactly one combination.

Definition at line 47 of file interface_50_modVariants_VariantsImport.class.php.

Constructor & Destructor Documentation

◆ __construct()

InterfaceVariantsImport::__construct ( $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 65 of file interface_50_modVariants_VariantsImport.class.php.

References description, name, and version.

Member Function Documentation

◆ countCombinations()

InterfaceVariantsImport::countCombinations ( $fkproductparent = 0,
$fkproductchild = 0,
$fkproductparentnot = 0 )
private

Count the combinations matching the given products, in the current entity.

A parameter left to 0 is not part of the filter.

Parameters
int$fkproductparentParent product to match
int$fkproductchildChild product to match
int$fkproductparentnotParent product to exclude
Returns
int Number of rows, -1 on SQL error

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

References dol_syslog().

Referenced by reconcileCombination().

◆ reconcileCombination()

InterfaceVariantsImport::reconcileCombination ( $rowid,
User $user,
Translate $langs )
private

Check the consistency of an imported combination and propagate it to the child product.

Parameters
int$rowidRow id of the combination
User$userObject user
Translate$langsObject langs
Returns
int Return integer <0 if KO, >0 if OK

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

References countCombinations(), and dol_syslog().

Referenced by runTrigger().

◆ reconcilePriceLevel()

InterfaceVariantsImport::reconcilePriceLevel ( $rowid,
User $user,
Translate $langs )
private

Propagate an imported price level to the child product.

Parameters
int$rowidRow id of the price level
User$userObject user
Translate$langsObject langs
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 451 of file interface_50_modVariants_VariantsImport.class.php.

References dol_syslog(), and getDolGlobalInt().

Referenced by runTrigger().

◆ reconcileValuePair()

InterfaceVariantsImport::reconcileValuePair ( $rowid,
User $user,
Translate $langs )
private

Reconcile a variant from one of its attribute/value links.

The value set is only complete once the last line of the variant has been read, so this runs once per line and converges. Every pass is idempotent.

Parameters
int$rowidRow id of the attribute/value link
User$userObject user
Translate$langsObject langs
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 327 of file interface_50_modVariants_VariantsImport.class.php.

References dol_syslog(), getDolGlobalInt(), and getDolGlobalString().

Referenced by runTrigger().

◆ refuseBulkModeOnVariants()

InterfaceVariantsImport::refuseBulkModeOnVariants ( $object,
Translate $langs )
private

Refuse the fast_bulk mode on the tables of the module.

In fast_bulk mode no per line trigger is emitted, so nothing would ever create the link with the child product nor propagate the prices: the import would leave combinations that are invisible on the product card.

Parameters
CommonObject | stdClass$objectObject carrying bulk_stats
Translate$langsObject langs
Returns
int 0 if not our business, -1 to abort the import

Definition at line 144 of file interface_50_modVariants_VariantsImport.class.php.

References $object, and dol_syslog().

Referenced by runTrigger().

◆ runTrigger()

InterfaceVariantsImport::runTrigger ( $action,
$object,
User $user,
Translate $langs,
Conf $conf )

Function called when a Dolibarr business event is done.

Parameters
string$actionEvent action code
CommonObject | stdClass$objectObject, a business object prototype or a stdClass when it comes from the import engine
User$userObject user
Translate$langsObject langs
Conf$confObject conf
Returns
int Return integer <0 if KO, 0 if no trigger ran, >0 if OK

Reimplemented from DolibarrTriggers.

Definition at line 87 of file interface_50_modVariants_VariantsImport.class.php.

References $object, dol_syslog(), isModEnabled(), reconcileCombination(), reconcilePriceLevel(), reconcileValuePair(), and refuseBulkModeOnVariants().


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