Create a calculated field
Open custom data settings
In Shopify Admin, head to Supercycle > Settings > Custom data and choose Items, Cycles, or Consignors.
Configure the field
Set up your calculated field:
- Name: Display name shown on the record (e.g., “Total rental cost”).
- Key: Auto-generated identifier based on the name (can be manually edited).
- Result type: The type of value the formula produces. Choose from single line text, multi line text, money, integer, boolean, date, or date and time.
- Formula: A Liquid expression that computes the value.
The result type cannot be changed after creation. Choose the appropriate type when creating the definition.
Writing formulas
Formulas use Liquid, the same templating language Shopify themes and notifications use. A formula is any Liquid expression that renders to a value matching the field’s result type. The form lists the available variables as clickable pills. Click one to insert it into your formula.General rules
- Formulas are evaluated in strict mode. Referencing an undefined variable causes the formula to fail.
- Only scalar custom fields are referenceable. Reference fields (customer, cycle, item, return), color, URL, and JSON custom fields are not available in formulas.
- A calculated field cannot reference another calculated field.
- Money values are always in cents (integer). For example,
$15.00is1500. A money-typed formula must also produce cents.
100:
Liquid basics
Liquid has two kinds of markup:- Output:
{{ ... }}renders a value. Everything a formula produces has to end up inside output tags. - Tags:
{% ... %}control logic and don’t render anything themselves (e.g.{% if %},{% assign %},{% case %}).
|:
Arithmetic
Arithmetic
plus, minus, times, divided_by, moduloRounding
Rounding
round, ceil, floorFallback
Fallback
default substitutes a value when the input is empty.Text
Text
upcase, downcase, capitalize, append, prependDates
Dates
date formats a date with a strftime string.Conditional logic
Use{% if %} to branch. The formula still has to render a value that matches the result type, so return one on every branch:
{% case %} is often cleaner:
Working with intermediate values
{% assign %} lets you name intermediate values so complex formulas stay readable:
Liquid variable reference
The variables available in a formula depend on the calculated field’s owner. Custom field keys are shop-defined; below they are shown asfields.<key> and metafields.<key>.
Scalar custom field types
Everyfields.<key> variable takes its Liquid type from the underlying scalar custom field definition:
| Custom field type | Liquid type | Example | Notes |
|---|---|---|---|
money | integer | 1500 | Cents |
integer | integer | 3 | |
boolean | boolean | true / false | |
single_line_text_field | string | "hello" | |
multi_line_text_field | string | "hello\nworld" | |
date | string | "2024-01-15" | ISO 8601 date |
date_time | string | "2024-01-15T12:30:00" | ISO 8601 datetime |
Liquid references by owner
The variables available in a formula depend on the calculated field’s owner. Expand an owner below to see every variable it exposes, along with its Liquid type and where the value comes from.Item
Item
One entry per scalar custom field defined on items, keyed by the definition’s key. The Liquid type mirrors the custom field type:
money and integer are integers (money in cents), boolean is a boolean, and text, date, and date_time are strings.The item’s linked Shopify variant. Only available when the item has a linked variant.
Cycle
Cycle
One entry per scalar custom field defined on cycles, keyed by the definition’s key. The Liquid type mirrors the custom field type:
money and integer are integers (money in cents), boolean is a boolean, and text, date, and date_time are strings.The rented item. Includes the item’s own fields and, when the item has a linked Shopify variant, its variant data.
Consignor
Consignor
One entry per scalar custom field defined on consignors, keyed by the definition’s key. The Liquid type mirrors the custom field type:
money and integer are integers (money in cents), boolean is a boolean, and text, date, and date_time are strings.Allowed result types
A calculated field’s output must match its declared result type. Result types are the same scalar set as the referenceable custom field types:money(stored as cents, e.g."4500")integerbooleansingle_line_text_fieldmulti_line_text_fielddatedate_time
Example formulas
Miles completed during a cycle (integer)
Set on a cycle. Record the item’s odometer reading at drop-off and return, and store the difference as the miles completed on this cycle.Total miles completed on an item (integer)
Set on an item. Accumulate miles across cycles by adding this cycle’s contribution to the running total already stored on the item.Because calculated fields recalculate on demand, click Recalculate on the item’s
total_miles field after each cycle to roll its value forward.Time to breakeven, in cycles (integer)
Set on an item. Divide the remaining cost to recover (acquisition cost minus revenue collected so far) by the average revenue per cycle, using the Shopify variant’sunit_cost as the acquisition cost and a merchant-managed average_revenue_per_cycle metafield on the product.
Has broken even (boolean)
Set on an item. Flag items whose total revenue has met or exceeded their acquisition cost.Recalculating values
Calculated fields don’t update automatically when the fields they depend on change. To update a value:Find the calculated field
Scroll to the Custom fields section and locate the calculated field you want to update.