Skip to content

Instantly share code, notes, and snippets.

@sean-codes
Created January 11, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean-codes/3841e6850261db43e44edb181784eeb1 to your computer and use it in GitHub Desktop.
Save sean-codes/3841e6850261db43e44edb181784eeb1 to your computer and use it in GitHub Desktop.
<cfsetting showdebugoutput='no'>
<cfscript>
var string = '{
"title":"Test Discount",
"code":"boomshaka",
"type":"by_percent",
"discountValue":"10",
"dateStart":"01/01/2017",
"dateEnd":"01/31/2017",
"aggregator":"any",
"conditions":[
{
"type":"product",
"aggregator":"all",
"conditions":[
{
"type":"test",
"aggregator":"all",
"conditions":[
{
"attribute":"category_ids",
"operator":"==",
"value":"216,248"
},
{
"attribute":"quantity",
"operator":">=",
"value":"2"
}
]
}
]
},
{
"type":"product",
"aggregator":"any",
"conditions":[
{
"attribute":"category_ids",
"operator":"=",
"value":"252"
}
]
},
{
"type":"address",
"aggregator":"all",
"conditions":[
{
"attribute":"postcode",
"operator":"==",
"value":"51106, 51108, 60613"
}
]
}
]
}';
var data = deserializeJSON(string);
recurse(data, data);
function recurse(parent, element){
if(structKeyExists(ARGUMENTS.element, 'conditions')){
dump('Super: ' & ARGUMENTS.element.aggregator);
for(var i = 1; i <= ARGUMENTS.element.conditions.len(); i++){
recurse(ARGUMENTS.element, ARGUMENTS.element.conditions[i]);
}
return;
} else {
//The info
dump(ARGUMENTS.parent.aggregator);
dump(ARGUMENTS.parent.type);
dump(ARGUMENTS.element);
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment