Created
January 11, 2017 21:17
-
-
Save sean-codes/3841e6850261db43e44edb181784eeb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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