Skip to main content
Version: 3.x

Calculation

Version
3.x
Updated
View markdown

A reference to a calculation, picked from the calculations of the relevant product.

Storage kind: column · Column: int unsigned, nullable by default

Use it for any field that points at a calculation — an answer's price calculation, a question's maximum-value calculation, a shipping rule's cost. It extends join, so it is a join with the extras this one case needs: a "no calculation" placeholder, product grouping, a link through to the referenced calculation, and copy semantics that follow the calculation.

Settings​

SettingMeaning
modelClass / modelMethodWhere the pickable calculations come from
propNameKey / propNameDisplayKey and label fields, as for a join
defaultlabelPlaceholder — conventionally "No Calculation"
groupbyGroup the options, typically by product
dropdownOrderingOrder of the option list
showLinksRender a link through to the referenced calculation
isPseudoJoinSuppress the SQL join

It inherits everything else join accepts.

Nullable by default​

"No calculation assigned" is the normal state for most fields carrying one, so this type declares getDefaultNullable() as true — the only type besides datetime that defaults nullable.

Several of these columns also have ON DELETE SET NULL foreign keys — answers.calcmodel, questions.calcmodel_id_max_val — which makes NOT NULL impossible regardless of preference: the database will write NULL into them when a calculation is deleted. Treat NULL as the normal absent value and read it as "no calculation", never as an error.

Copying follows the calculation​

copyCalculation() runs during a record copy, so a copied record points at a copy of the calculation rather than sharing the original. That is what keeps a duplicated product's pricing independent — edit the copy's calculation and the original is untouched.

It is the same shape as rule's copyRule() and calculationOverride's copyOverrides(): a reference that would otherwise alias shared state across a copy.

copyCalculation() honours storeExternally, writing the new reference to the foreign table when the property lives there.

Notes​

It behaves as a join for query building — it extends the join type — but exists separately because a calculation reference is a distinct thing to pick, order and link to. showLinks in particular only makes sense here: it renders a link from the referencing form straight into the calculation editor, which is how an operator gets from "this answer is priced somehow" to the formula.

@see join.md @see calculationoverride.md — per-customer-group overrides of a reference like this @see ../com_configbox_calculation_engine.md @see ../../admin-guide/pricing/build-a-calculation.md — what the operator sees