Expand my Community achievements bar.

Assistance with JavaScipt Code for Three Tier Discount Levels

Avatar

Level 4

I have a three tier discount level requirement which I have encoded as follows:

var numTotalUnits = xfa.resolveNode("subTotal.numTotalUnits");

var numThreshold1 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1");

var numThreshold2 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2");

var numThreshold3 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3");

var numRegularPrice = xfa.resolveNode("this.parent.parent.parent.subControls.subBelow.numRegularPrice");

var numDiscount1 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount1");

var numDiscount2 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount2");

var numDiscount3 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount3");

if (numTotalUnits.rawValue == null || numTotalUnits.rawValue == ""){

this.rawValue = numRegularPrice.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && (numThreshold2.rawValue == null || numThreshold2.rawValue == "") && (numDiscount2.rawValue == null || numDiscount2.rawValue == "") && (numTotalUnits.rawValue < numThreshold1.rawValue)){

this.rawValue = numRegularPrice.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && (numThreshold2.rawValue == null || numThreshold2.rawValue == "") && (numDiscount2.rawValue == null || numDiscount2.rawValue == "") && (numTotalUnits.rawValue >= numThreshold1.rawValue)){

this.rawValue = numDiscount1.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && (numThreshold3.rawValue == null || numThreshold3.rawValue == "") && (numDiscount3.rawValue == null || numDiscount3.rawValue == "") && (numTotalUnits.rawValue >= numThreshold1.rawValue && numTotalUnits.rawValue < numThreshold2.rawValue)){

this.rawVaue = numDiscount1.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && (numThreshold3.rawValue == null || numThreshold3.rawValue == "") && (numDiscount3.rawValue == null || numDiscount3.rawValue == "") && (numTotalUnits.rawValue >= numThreshold2.rawValue)){

this.rawValue = numDiscount2.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && numThreshold3.rawValue != null && numDiscount3.rawValue != null && (numTotalUnits.rawValue >= numThreshold2.rawValue && numTotalUnits.rawValue < numThreshold3.rawValue)){

this.rawValue = numDiscount2.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && numThreshold3.rawValue != null && numDiscount3.rawValue != null && (numTotalUnits.rawValue >= numThreshold3.rawValue)){

this.rawValue = numDiscount3.rawValue;

}

When the total order value is over the third discount level and is reduced to the second all works fine, however, when the total is reduced to the first level or below that the code does not copy over the first discount level or the regular price. All else works fine.

Please provide any assistance as any is extremely welcome. Previously BR001 had helped with the initial coding, however, it did not work when discount levels were not filled.

Lewis

1 Reply

Avatar

Level 10

Hi there,

This is quite a bit of code... and hard to figure out what you are trying to do exactly... but I might have spotted something out..

Let's go step by step...

If you start off the end of your code where discount 3 is applied (last elseif), that means it has a value...

afterwards, one if above, discount 2 will apply only if total units is between threshold 2 and 3...

one if above... discount 2 will apply if total units is greater than threshold 2 and discount 3 and threshold 3 is null...

one if above... discount 1 will apply if total units is between threshold 1 and 2 and discount 3 and threshold 3 are null...

one if above... discount 1 will apply if total units is greater than threshold 1 and discount 2 and threshold 2 are null...

one if above (first elseif)... regular price will apply if total units is under threshold 1 and discount 2 and threshold 2 are null...

one if above (first if)... (self explained) if total units is different than null

Like I said it is not easy to understand exactly what you are trying to do... so trying to explain what is wrong needs to be detailed and it's hard to do so...

Hope this will help... NOTE that I have omitted many conditions to make it quicker to write in words.