I have a calculation script that gets its number from a JSON and I added some deductions if they order a certain amount of pieces but I can't get it to change when a different garment is selected here is my code for the JSON:
var shirtsJSON = [
{"pattern": "Delta Adult S/S 5.2oz", "basePrice": 5.68,
"sizes": {"s-xl": 0, "xxl": 0.84},
"colors": {"white": 0, "athletic": 0.12, "color": 0.23},
"numColors": {"1-2": 0, "3-4": 1.60, "5-6": 3.18, "7-8": 4.81, "9-10": 6.39},
"deductions": {"de48pp": 0, "de72pp": .90, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 3.28, "oneloc34": 5.41, "oneloc56": 7.52, "oneloc78": 9.69, "oneloc910": 11.80},
"twoLocation": {"twolocnone": 0, "twoloc12": 3.28, "twoloc34": 5.41, "twoloc56": 7.52, "twoloc78": 9.69, "twoloc910": 11.80},
"threeLocation": {"threelocnone": 0, "threeloc12": 3.28, "threeloc34": 5.41, "threeloc56": 7.52, "threeloc78": 9.69, "threeloc910": 11.80},
"fourLocation": {"fourlocnone": 0, "fourloc12": 3.28, "fourloc34": 5.41, "fourloc56": 7.52, "fourloc78": 9.69, "fourloc910": 11.80}},
{"pattern": "Delta Adult S/S 6.1oz", "basePrice": 5.68,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 0, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 3.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "Gildan Adult S/S 5.4oz", "basePrice": 1.21,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"onelocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "Gildan Adult S/S 6.1oz", "basePrice": 1.31,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "Delta Adult 5.5oz Ringspung Tee", "basePrice": 2.48,
"sizes": {"s-xl": 0, "xxl": 3}, "colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "AIstyle Adult 5.5oz Soft Cotton Tee", "basePrice": 2.40,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "Next Level Mens Fitted S/S Tee", "basePrice": 2.76,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "Delta Adult 5.2oz L/S Tee", "basePrice": 2.35,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "AIstlye Adult 6oz L/S Tee", "basePrice": 2.70,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}},
{"pattern": "Gildan Adult 5.4oz L/S Tee", "basePrice": 3.30,
"sizes": {"s-xl": 0, "xxl": 3},
"colors": {"white": 0, "athletic": 0, "color": 1.13},
"numColors": {"1-2": 1, "3-4": 2, "5-6": 3, "7-8": 4, "9-10": 5},
"deductions": {"de48pp": 0, "de72pp": 1.20, "de96pp": 2.35, "de144pp": 1.37, "de288pp": 2.65},
"oneLocation": {"onelocnone": 0, "oneloc12": 1.60, "oneloc34": 3.18, "oneloc56": 4.81, "oneloc78": 6.39, "oneloc910": 6.39},
"twoLocation": {"twolocnone": 0, "twoloc12": 1.60, "twoloc34": 3.18, "twoloc56": 4.81, "twoloc78": 6.39, "twoloc910": 6.39},
"threeLocation": {"threelocnone": 0, "threeloc12": 1.60, "threeloc34": 3.18, "threeloc56": 4.81, "threeloc78": 6.39, "threeloc910": 6.39},
"fourLocation": {"fourlocnone": 0, "fourloc12": 1.60, "fourloc34": 3.18, "fourloc56": 4.81, "fourloc78": 6.39, "fourloc910": 6.39}}];
Then here is where it calculates
for (i = 1; i <= numOptions; i++) {
if ($('#option' + i + 'check').is(':checked')) {
totalPrice += parseFloat($('#option' + i + 'check').val());
}
}
for(i = 0; i < shirtsJSON.deductions; i++) {
}
/**
* This adds the final prices into the results area
*/
$('#48pc').html("48pc : " + currency + getMoney(totalPrice * 48));
$('#72pc').html("72pc : " + currency + getMoney(totalPrice * 72 ));
$('#96pc').html("96pc : " + currency + getMoney(totalPrice * 96));
$('#144pc').html("144pc : " + currency + getMoney(totalPrice * 144));
$('#288pc').html("288pc : " + currency + getMoney(totalPrice * 288));
$('#48pp').html("Per Piece : " + currency + getMoney(totalPrice - shirtsJSON[i].deductions.de48pp));
$('#72pp').html("Per Piece : " + currency + getMoney(totalPrice - shirtsJSON[i].deductions.de72pp));
$('#96pp').html("Per Piece : " + currency + getMoney(totalPrice - shirtsJSON[i].deductions.de96pp));
$('#144pp').html("Per Piece : " + currency + getMoney(totalPrice - shirtsJSON[i].deductions.de144pp));
$('#288pp').html("Per Piece : " + currency + getMoney(totalPrice - shirtsJSON[i].deductions.de288pp));
}
//-->
Right now it just draws the first pattern of deductions but I want it to change with each shirt. I added the loop in it but it still just does the first set.
Here is the entire code if you want to look at it. https://gist.github.com/1719315