Fluent Commerce Logo
Docs
Sign In

General Principles for Rules

Essential knowledge

Author:

Randy Chan

Changed on:

3 Nov 2023

Overview

Understand what are some general Rule principles.

Key points

  • Fluent uses jsonPath, which is a period-separated string that describes a "path" between the entity being processed and a field on it or a related entity.
  • In essence, this category of rules understands how to generate dynamic queries. 
  • There are some helpers for traversing connection types, edges, and node fields, which will be automatically skipped, for example,
    `items.0.currency`
      is equivalent to 
    `items.edges.0.node.currency`
     

JsonPath Props

Many of the rules in the core module accept a prop typed as a jsonPath, which is a period-separated string that describes a "path" between the entity being processed and a field on it or a related entity.

In essence, this category of rules understands how to generate dynamic queries to maximize flexibility across domains and use cases. In most cases, the value/s loaded via this dynamic query will be compared against another rule prop as described by the rule name and description.

For example, fields on or related to the Order entity could be accessed with the following paths:

Path

Description

`status`

Use the state field of the Order.

`fulfilmentChoice.deliveryType`

Use the delivery type field of the Fulfillment Choice related to the Order.

`items.0.currency`

Use the currency value of the first item of the Order.

`attributes.byName.promoCode`

Use the value of a custom attribute of the Order.

Additionally, properties of the event can be referenced with the

`event.`
prefix:

Path

Description

`event.entitySubType`

Use the entity subtype from the event.

`event.attributes.myCustomAttribute`

Use the value of a custom event attribute.

`event.myCustomAttribute`

As above, as long as the attribute name doesn't clash with a standard attribute field.

Finally, there are some helpers to simplify specific use cases: - when traversing connection types, edges, and node fields will be automatically skipped over even if they're not added to the path, e.g., the 

`items.0.currency`
 sample above is equivalent to 
`items.edges.0.node.currency`
 - all array types, including connection edges, support first and last values in place of the index, e.g. 
`items.first.currency`
 or 
`items.last.currency`
 - since entity attributes are an array, the 
`byName`
 shorthand is available to access them by name, e.g. 
`attributes.byName.promoCode`
.

Copyright © 2024 Fluent Retail Pty Ltd (trading as Fluent Commerce). All rights reserved. No materials on this docs.fluentcommerce.com site may be used in any way and/or for any purpose without prior written authorisation from Fluent Commerce. Current customers and partners shall use these materials strictly in accordance with the terms and conditions of their written agreements with Fluent Commerce or its affiliates.

Fluent Logo