Configuring Special Conditions
Special Conditions are XML based language for specifying a subset of store products; this language defines a set of criterion (or rules) products must meet.
The "Tags and Labels" and "Shop by Special Price, Catalog Price Rules, New Arrivals, Attribute Option, Bestseller" extensions both use Special Conditions which are store in Condition
field.
Special Conditions have different types. These types are:
Attribute Rules
- select products based on attribute option like "Red Products"Predefined Rules
- select products based not on attribute options but rather on some other conditions like new products, promotion rules etcOperators
- this type is used to combine or intersect product lists
Predefined Rules
<new />
Prepares a collection of products set as new
<special_price />
Prepares a collection of products with special price.
<promo />
Prepares a collection of products that is used by a catalog price rule. Uses the following XML attribute:
id
- The ID of the catalog price rule that will be used as a filter. If not mentioned, all products that belong to an active catalog price rule will be used as the condition.
<price />
Prepares a collection of products with specified product final price (including all effective special prices and catalog price rules).
Price attribute uses the following XML attributes:
from
- The starting price.to
- The ending price. Its value should be bigger thanfrom
.
At least one of these attributes needs to be mentioned. Both can be mentioned at the same time to use as a range.
Example: To get all products with a price from 0 to 500:
<price to="500" />
To get all products with a price of 1,000 above:
<price from="1000" />
To get all products with a price between 1,000 and 5,000:
<price from="1000" to="5000" />
Attribute Rules
Unlike Predefined Rules, Attribute Rules depends on what attributes are available in a Magento store.
Attribute code will work as a rule (e.g. <cpu_speed equals="2.0 GHz" />
). However, Special Filters only support a few input types and each input type uses different XML attribute format.
If an attribute has the same name as any of the Predefined Rules, it will be used as Predefined Rule instead of an Attribute Rule.
Here are the supported input types and their format:
To optimize special tags loading from Tags and Labels Extension, it is advised to set Used in Product Listing
to Yes
.
Date
Attribute of date type uses the following XML attributes:
since
- Possible values are1 day
,40 days
,N days
,1 month
,36 months
,N months
,1 year
,2 years
,N years
. Note thatN
should be bigger than 1.
Example: To get all products updated from today up to the last 1 month.
<updated_at since="1 month" />
Dropdown
Attribute of dropdown type uses the following XML attributes:
equals
- Must be an option in the dropdown.
Example:
Let's say we want to filter products with a specific color. First, we need to find out the possible options for the Color
attribute.
If we want to filter products with the color Red
, we should use the following XML tag:
<color equals="Red" />
Value of
equals
is case sensitive, so<color equals="red" />
will not work because it must beRed
and notred
.
Price
Works the same as <price />
predefined rule.
Attribute of price type uses the following XML attributes:
from
- The starting price.to
- The ending price. Its value should be bigger thanfrom
.
At least one of these attributes needs to be mentioned. Both can be mentioned at the same time to use as a range.
Example: To get all products with a custom price from 0 to 500:
<custom_price to="500" />
To get all products with a custom price of 1,000 above:
<custom_price from="1000" />
To get all products with a custom price between 1,000 and 5,000:
<custom_price from="1000" to="5000" />
Operators
Operators are used to combine different rules. In XML, they are the parent tag of each rule. Here are the operators supported:
<and>
<and>
is used to get products that is qualified in all the rules that it contains.
Example:
<and>
<new />
<price to="1000" />
</and>
This will prepare all new products with price of 0 up to 1,000.
<or>
<or>
is used to get products that is qualified in **at least one rule ** that it contains.
<or>
<color equals="Red" />
<color equals="Black" />
<color equals="Blue" />
</or>
This will prepare products that has either Red
, Black
, or Blue
.
<not>
<not>
is used to get products that is not qualified in the rule that it contains.
It should have one rule inside it. If it has multiple children rules, then it will only negate the first rule and ignore the others.
To apply negation of multiple rules, then nest it with either
<and>
or<or>
operators.
Example:
<not>
<new />
</not>
This will filter all products except new products.