Attributes
Introduction
Rules are the basic unit of price adjustment in Price Rules. Each rule is tested against each product or variant they may operate on. A ruleset is a set of rules matched up with a selection of products.
If all conditions pass then the actions are applied and may adjust the price.
Although conditions
is required it can be set to []
.
Ruleset Attributes
Attribute | Type | Default |
---|---|---|
id | int | n/a |
external_id | string | n/a |
active | bool | true |
internal_name | string | "" |
public_name | string | "" |
rules | array | required |
product_selection | object | required |
start_date | date (UTC) | starts immediately |
expiry_date | date (UTC) | never expires |
priority | int | 0 |
id
- the ruleset id. Provided when saving a ruleset.
external_id
- max length:128 - an external reference id for this rule set. Can be any string that is unique for the provided app code.
active
- whether these rules are active or not. Can be used to create an inactive ruleset or to turn off a ruleset after creation.
internal_name
- max length:255 - an internal name for this ruleset. Not currently displayed or used anywhere but likely will be in future.
Can be filled in with any internal name used for this set of rules in the app.
public_name
- max length:255 - a public name for this ruleset. In future a customization will be available to display this on the storefront.
product_selection
- see Product Selection.
start_date
- UTC - the date these discounts should begin to apply. If not provided they will apply as soon as possible.
expiry_date
- UTC - the date these discounts should expire. If not provided they will apply until they are deleted.
priority
- the priority of this ruleset relative to others created by the same app.
Rule Attributes
Attribute | Type | Default | Description |
---|---|---|---|
type | string | "DISCOUNT" | The discount type. Defaults to DISCOUNT . |
conditions | array | required | The set of conditions for this rule. |
actions | array | required | The set of actions for this rule. |
conditions
- see Conditions.
actions
- see Actions.
Rule Type and Layers
Price Rules has 4 Layers of rules and will stack rules starting from Layer 0 to Layer 3.
Type | Layer | Priority | Stack Order | Best Price |
---|---|---|---|---|
BASE_PRICE | 0 | Yes | No | Yes |
DISCOUNTABLE_ADDITION | 1 | Yes | Yes | No |
DISCOUNT | 2 | No | No | Yes |
STACKABLE_DISCOUNT | 3 | Yes | Yes | No |
ADDITION | 3 | Yes | Yes | No |
ROUNDING | 3 | Yes | Yes | No |
CART_LEVEL_DISCOUNT | 4 | No | No | No |
Priority
Applies to Layer 1 and 3, with all rules having a priority of 0 (highest) by default unless it's specified upon creation.
Layer 0 and 2's priority is per application. Price Rules figures out top priority rules among each individual applications.
This means Price Rules will apply pick the best deal by default. Unless there is priority specified.
{
"rules": [
{
"conditions": [],
"actions": [
{
"type": "PRICE_ADJUST_ABSOLUTE_BASE_PRICE",
"value": 12000
}
],
"type": "BASE_PRICE"
},
{
"conditions": [],
"actions": [
{
"type": "PRICE_ADJUST_ABSOLUTE_BASE_PRICE",
"value": 11000
}
],
"priority": 1,
"type": "BASE_PRICE"
}
]
}
In the above example, first rule has priority of 0 while second has 1. Even if the second rule gives a better price, Price Rules will choose the first one because of its higher priority.
Stack Order
Applies to Layer 1 and Layer 3, where Price Rules applies all rules in sequence by default. You can use priority
described above to alter this behaviour. You can also define stack_order
for rules. It's not available in Layer 0 and Layer 2 because Price Rules figures out best price among those two layers.
{
"rules": [
{
"conditions": [],
"actions": [
{
"type": "PRICE_ADJUST_PERCENT",
"value": -50
}
],
"stack_order": 2,
"type": "STACKABLE_DISCOUNT"
},
{
"conditions": [],
"actions": [
{
"type": "ADD_FEE",
"value": 10000
}
],
"stack_order": 1,
"type": "ADDITION"
}
]
}
Money Tags
Money tags help Price Rules find prices on the page and determine what they belong to. They are also where Price Rules will output the price for this product based on rules saved by apps. In this way money tags are both an important point of both input and output for Price Rules. Money tags are simply html tags with the class "money" and with an identification attribute that identifies what that price belongs to. Price Rules will search for these tags during page load and will also watch for any being injected into the DOM.
The wrapped value for each example is a place holder, the attributes applied to each DOM element can be used verbatim.
Attributes
data-product-id
- this attribute should be used for any non-cart price on the site. It will output the price for the lowest priced variant in this product or if on the product page then the currently selected variant.
Shopify Example:
<span class="money" data-product-id="{{ product.id }}">{{ product price }}</span>
BigCommerce Example:
<span class="money" data-product-id="{{#if product}}{{ product.id }}{{else}}6110d110-5ec4-4bff-8c67-cd47ca3e2698{{/if}}">{{ product price }}</span>
data-variant-id
- this attribute can be used to output the price for a variant in a way that will not update if the variant changes.
Shopify Example:
<span class="money" data-variant-id="{{ variant.id }}">{{ variant price }}</span>
data-line-index
- this attribute indicates that the money tag belongs to the price of a cart line item.
Shopify Example:
This can be used with Shopify’s liquid tag {{ forloop.index0 }}
to output the current cart line index:
<span class="money" data-line-index="{{ forloop.index0 }}">{{ cart line item price }}</span>
BigCommerce Example:
This can be used with Big Commerce’s {{{@index}}}
handlebar tag
<span class="money" data-line-index="{{{@index}}}">{{ cart line item price }}</span>
data-line-total
- this attribute indicates a cart line total. It is required in addition to data-line-index
and requires no value.
Tags marked with this attribute will output the line price multiplied by the line quantity.
Shopify Example:
<span class="money" data-line-index="{{ forloop.index0 }}" data-line-total>{{ total line item price }}</span>
BigCommerce Example:
<strong class="cart-item-value"><span class="money" data-line-index="{{{@index}}}" data-line-total>{{ total line item }}</span></strong>
data-cart-total
- this attribute marks the subtotal price of the cart.
Big Commerce and Shopify Example:
<span class="money" data-cart-total>{{ cart total price }}</span>