Created 07-22-2024 10:12 PM
Hello,
Could you please help me what i am missing here.. i am trying to copy currency value from currency condition and adding it in calculatePrice array.
Input
{
"tiers": [
{
"rewards": [
{
"rewardId": 8127,
"changeType": 2,
"changeAmount": 15,
"changePercent": null,
"quantityToDiscount": null,
"applyInd": 2,
"rewardsMerch": []
}
],
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_CURR_CONDITION",
"values": [
"AED"
]
}
]
},
{
"rewards": [
{
"rewardId": 8128,
"changeType": 2,
"changeAmount": 18,
"changePercent": null,
"quantityToDiscount": null,
"applyInd": 2,
"rewardsMerch": []
}
],
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_CURR_CONDITION",
"values": [
"USD"
]
}
]
}
]
}
Spec
[
{
"operation": "shift",
"spec": {
"tiers": {
"*": {
"priceRuleAttributes": {
"*": {
"id": {
"PR_CURR_CONDITION": {
"@(2,values[0])": "paths.[&5].currencyCondition[#2].currency"
}
}
}
},
"rewards": {
"*": {
"changeType": "paths.[&3].calculatePrice[&1].calculationType",
"changeAmount": "paths.[&3].calculatePrice[&1].amount",
"changePercent": "paths.[&3].calculatePrice[&1].percentage"
}
}
}
}
}
},
{
"operation": "modify-default-beta",
"spec": {
"paths": {
"*": {
"calculatePrice": {
"*": {
"currency": "@(0,currencyCondition[&].currency)"
}
}
}
}
}
}
]
Expected output
{
"paths" : [ {
"currencyCondition" : [ {
"currency" : "AED"
} ],
"calculatePrice" : [ {
"calculationType" : 2,
"amount" : 15,
"percentage" : null,
"currency" : "AED"
} ]
}, {
"currencyCondition" : [ {
"currency" : "USD"
} ],
"calculatePrice" : [ {
"calculationType" : 2,
"amount" : 18,
"percentage" : null,
"currency" : "AED"
} ]
} ]
}
Created 07-23-2024 02:44 AM
Hi,
I think you can do this part of the first shift spec unless Im missing something:
[
{
"operation": "shift",
"spec": {
"tiers": {
"*": {
"priceRuleAttributes": {
"*": {
"id": {
"PR_CURR_CONDITION": {
"@(2,values[0])": "paths.[&5].currencyCondition[#2].currency"
}
}
}
},
"rewards": {
"*": {
"changeType": "paths.[&3].calculatePrice[&1].calculationType",
"changeAmount": "paths.[&3].calculatePrice[&1].amount",
"changePercent": "paths.[&3].calculatePrice[&1].percentage",
"@(2,priceRuleAttributes[0].values[0])": "paths.[&3].calculatePrice[&1].currency"
}
}
}
}
}
}
]
Created 07-23-2024 10:44 AM
In that case you made it static as priceRuleAttributes array can have multiple dynamic values and its index can be change for PR_CURR_CONDITION.
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_BRANCH_NAME",
"values": [
"MEMBERS"
]
},
{
"type": "CFA",
"id": "PR_PRICE_RULE_PROMO",
"valueBoolean": true
},
{
"type": "CFA",
"id": "PR_TARGET_SEGMENT",
"values": [
"PAS_LOGGEDIN",
"LOGGEDIN",
"PAS_NOT_LOGGEDIN"
]
},
{
"type": "CFA",
"id": "PR_CURR_CONDITION",
"values": [
"AED"
]
}
]
Created 07-23-2024 02:52 PM
I guess Im having hard time understanding what are you trying to do . In the first post you said you are just wanting to copy the value from Currency Condition into Calculate Pricee, so I assumed there is always going to be one value in the Currency Condition Array, but now you are saying can be dynamic and it can change . So what are the rules here in case you have multiple values? how do you decide? Can you specify the different scenarios that you would have in the input and what is the expected output for each ?
Created 07-24-2024 06:34 AM
Sorry i shared simplified input JSON, here is input so priceRuleAttributes array can have more than one value or can be empty.
{
"tiers": [
{
"rewards": [
{
"rewardId": 8127,
"changeType": 2,
"changeAmount": 15,
"changePercent": null,
"quantityToDiscount": null,
"applyInd": 2,
"rewardsMerch": []
}
],
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_BRANCH_NAME",
"values": [
"MEMBERS"
]
},
{
"type": "CFA",
"id": "PR_PRICE_RULE_PROMO",
"valueBoolean": true
},
{
"type": "CFA",
"id": "PR_TARGET_SEGMENT",
"values": [
"PAS_LOGGEDIN",
"LOGGEDIN",
"PAS_NOT_LOGGEDIN"
]
},
{
"type": "CFA",
"id": "PR_CURR_CONDITION",
"values": [
"AED"
]
}
]
},
{
"rewards": [
{
"rewardId": 8128,
"changeType": 2,
"changeAmount": 18,
"changePercent": null,
"quantityToDiscount": null,
"applyInd": 2,
"rewardsMerch": []
}
],
"priceRuleAttributes": [
{
"type": "CFA",
"id": "PR_BRANCH_NAME",
"values": [
"MEMBERS"
]
},
{
"type": "CFA",
"id": "PR_CURR_CONDITION",
"values": [
"USD"
]
}
]
}
]
}
Output
{
"paths" : [ {
"currencyCondition" : [ {
"currency" : "AED"
} ],
"calculatePrice" : [ {
"calculationType" : 2,
"amount" : 15,
"percentage" : null,
"currency" : "AED"
} ]
}, {
"currencyCondition" : [ {
"currency" : "USD"
} ],
"calculatePrice" : [ {
"calculationType" : 2,
"amount" : 18,
"percentage" : null,
"currency" : "USD"
} ]
} ]
}
Created 07-25-2024 10:53 AM
Hi,
Sorry for the delay. See if this will work:
[
{
"operation": "shift",
"spec": {
"tiers": {
"*": {
"priceRuleAttributes": {
"*": {
"id": {
"PR_CURR_CONDITION": {
"@(2,values[0])": "paths.[&5].currencyCondition[#2].currency"
}
}
}
},
"rewards": {
"*": {
"changeType": "paths.[&3].calculatePrice[&1].calculationType",
"changeAmount": "paths.[&3].calculatePrice[&1].amount",
"changePercent": "paths.[&3].calculatePrice[&1].percentage",
"@(2,priceRuleAttributes)": {
"*": {
"id": {
"PR_CURR_CONDITION": {
"@(2,values[0])": "paths.[&7].calculatePrice[&4].Currency"
}
}
}
}
}
}
}
}
}
}
]