You can use predefined condition macros for a certain type of operation.
- Empty Condition
- Attribute Value Condition
- Multiple Value Condition
- Return first not empty value
- Return value after first TRUE condition
- Concatenate all values with TRUE condition
- Timestamp settings (Facebook channel)
- Shipping costs for a product above a certain price
- Shipping costs for a product above a certain weight
For more information about how to open the Exported Value section, please check
For basic macros examples, please check
Empty Condition
You can set a condition to export non-empty values only.
// you can use a condition in a ternary operator form
[[ ? : ]]
// if value of the 'meta_title' attribute is not empty the 'meta_title' value is used,
// otherwise it is used the value of the 'name' attribute
[[('{{meta_title}}' != '')? '{{meta_title}}': '{{name}}';]]
// note double curling brackets surrounding attribute codes
Attribute Value Condition
You can define a value condition to modify the exported value based on the input value.
// if product price is higher than 100 then use product price as the final price,
// otherwise increase the price for 20 (adding 20 as shipping costs)
[[condition_1 ? value_1 : value_2 ]]
Example:
[[({{price_final_include_tax}} > 100) ? {{price_final_include_tax}} :
{{price_final_include_tax}} + 20]]
// note double curling brackets surrounding attribute codes
Multiple Value Condition
You can modify the Attribute Value Condition and define multiple value conditions to cover cases.
// if product price is lower than 20 then use product price as the final price increased by 25%,
// if product price is lower than 40 and higher than 20
// then use product price as the final price increased by 15%,
// otherwise use product price as the final price
[[condition_1 ? value_1 : (condition_2) ? value_2 : value_3 ]]
Example:
[[({{price_final_include_tax}} < 20) ? {{price_final_include_tax}}*1.25 :
({{price_final_include_tax}} < 40) ? {{price_final_include_tax}}*1.15 :
{{price_final_include_tax}}]]
Return first not empty value
This condition returns the first none empty value from the list of attributes. You can define more input attributes - compNotEmptyFromList( 1:N params)
// if tags value is not empty, returns tags value
// if name value is not empty, returns name value
// else returns default value - e.g. 'default value'
Example:
[[compNotEmptyFromList( '{{tags}}', '{{name}}', 'default value')]]
Return value after first TRUE condition
This condition returns the first value after the first TRUE condition. You can define more input attributes - compMultiConditions( cond1, value1, cond2, value2, ..., condN, valueN, default)
// if sku value is equal to 'foo', returns price value
// if sku includes 'bar' valu, returns name value
// else returns default value - e.g. 'default value'
Example:
[[compMultiConditions( '{{sku}}' == 'foo', {{price}},
strpos( '{{sku}}', 'bar') !== false, {{name}}, 'default value')]]
Concatenate all values with TRUE condition
This macro returns all values with TRUE condition concatenated by the glue -
compConcatMultiConditions( glue, cond1, value1, cond2, value2, ..., condN, valueN, default)
// if name value is not empty, returns tags value
// if brand value is not empty, adds brand value
// if mpn value is not empty, adds mpn value
// else returns default value - e.g. 'default value'
Example:
[[compConcatMultiConditions( ' | ', '{{name}}' != '', '{{name}}',
'{{brand}}' != '', '{{brand}}',
'{{mpn}}' != '', '{{mpn}}',
'default value')]]
Result: name value | brand value | mpn value| default value
Timestamp settings (Facebook channel)
Facebook feed requires to set the "sale_price_effective_date" in the format below:
2017-01-03T00:01-0100/2017-01-26T23:59-0100
You can do it by setting 2 conditions.
//For "g:sale_price_effective_date FROM" attribute
[[ ("{{special_from_date}}" != "")? "{{special_from_date}}T00:01-0100":"" ]]
//For "g:sale_price_effective_date TO" attribute
[[ ("{{special_to_date}}" != "")? "{{special_to_date}}T23:59-0100":"" ]]
Shipping costs for a product above a certain price
// use cases for shipping cost export
// if product prices is higher than 50 then set shipping price as 3.5,
// else zero price Ci.e. free shipping)
[[({{price_final_include_tax}} > 50) ? 0 : 3.5]]
Shipping costs for a product above a certain weight
// if products weight is higher than 100 then increase shipping cost by 10,
else export base shipping cost
[[{{weight}} > 100) ? {{shipping_cost}} : {{shipping_cost}} + 10]]
Comments
0 comments
Please sign in to leave a comment.