Documentation Index
Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Computed attributes create product values from other product data. You can use them for badges, tiers, tags, filters, sorting, merchandising rules, and storefront API responses. Layers supports two ways to create new computed values:- Computed attributes use JavaScript Functions. Choose this when you need custom logic, multiple inputs, templates, previewing, or typed outputs.
- Derived attributes use the visual Derive builder. Choose this when you want to map values from one source attribute to a new value without writing code.
Functions
Functions let you write JavaScript that receives selected product data and returns a typed result. They are best for calculations such as discount percentage, average margin, SKU coverage, inventory health, or multi-field outputs. Use a Function when you need to:- Combine several product fields.
- Work with variants, prices, tags, metafields, or collection titles.
- Preview the result on a real product before saving.
- Return a number, string, boolean, array, object, or multiple generated sub-fields.
Derive builder
The Derive builder provides a visual interface for deriving an attribute value from another attribute using mapping rules. Use the Derive builder when you want to map values from a source attribute (such as tags or a metafield) to new output values without writing JSONLogic manually. For example, you could derive a “Season” attribute from product tags by mapping tag values like “lightweight” and “breathable” to “Summer”, and “insulated” and “thermal” to “Winter”. How to use:Select a source attribute
Choose any indexed attribute from the Source Attribute dropdown. This is the attribute whose values you want to map from (for example,
tags).Define mapping rules
Each rule maps one or more source values to an output value:
- Match type - Choose how to compare against the source value: Contains, Equals, Starts with, or Ends with.
- Match values - Select one or more values to match against. Multiple values within a single rule use OR logic (a match on any value triggers the rule).
- Output value - Enter the derived value to assign when the rule matches.
- Case insensitive - All matching is case insensitive by default. “Summer” and “summer” are treated the same.
- First match wins - Rules are evaluated in order from top to bottom. Once a rule matches, its output value is used and remaining rules are skipped.
- Default value - When no rule matches, the attribute is excluded from the product’s computed object entirely. It will not appear in API responses for that product.
- Null and empty exclusion - Computed attributes that evaluate to null or an empty string are automatically excluded from the product data and will not appear in API responses or facet results.
- Full compatibility - Derived attributes continue to use JSONLogic behind the scenes.
Automatic product recalculation
When you create a new computed attribute or update an existing computed attribute’s logic, Layers automatically recalculates all products in your catalog in the background. This applies the computed values across your catalog without manual intervention. During recalculation, any computed attribute that evaluates to null or an empty string is automatically excluded from the product. If a previously stored attribute now evaluates to null or empty, it is removed from the product’s computed data and from any associated facet values.Recalculation is triggered when you create a computed attribute or modify its logic. Updates to other fields, such as nickname or filterable settings, do not trigger recalculation.
Data access
Functions use an input query to select the product data they can read. See Function input query. Existing JSONLogic attributes may use legacy data references.
Platform default computed attributes
The following computed attributes are available by default in the Layers platform:SKU Coverage
SKU Coverage
Description: Ratio between total number of variants and their availability status.Use case: Identify products with partial variant availability.
Days Available
Days Available
Description: The number of days since the product became available, based on the imported Published At for the product. If no available date has been imported, the system uses the date the product was created.Use case: Build freshness rules, “new arrivals” groups, and aging product reports.
Has Image
Has Image
Description: If the product has a featured image.Use case: Find products that need image cleanup before merchandising.
Age of Newest Variant
Age of Newest Variant
Description: The age of the most recently created variant.Use case: Highlight products with newly added sizes, colors, or variants.
Price Varies
Price Varies
Description: Whether a product’s variants have different prices.Use case: Identify products where variants do not all share the same price.
For current built-in Function templates, see Computed attribute recipes.