$populated_fields[$key] = array('price'=>$_POST[$key], 'qty'=>$_POST[$value]);
}
}
-
+ // loop through the populated fields to calc the qty
+ $quantity = 0;
foreach($populated_fields as $price=>$info){
- if( $info['qty'] > 1 ){
- $prod_price = $info['qty'] * 10 - 10;
- $prod_price = $prod_price / $info['qty'];
- $_POST[$price] = $prod_price;
- return;
- } else {
- $_POST[$price] = '$0.00';
- return;
- }
+ $quantity += $info['qty'];
}
+
+ // logic to determine the discount rate, every 4 gets $10 off
+ if($quantity % 4 === 0){
+ $discount_qty = $quantity / 4;
+ $discount_price = $discount_qty * 10;
+ $price_total = ($quantity * 10) - $discount_price;
+
+ } else if( $quantity > 4 && $quantity % 4 !== 0){
+ $discount_qty = floor($quantity / 4);
+ $discount_price = $discount_qty * 10;
+ $price_total = ($quantity * 10) - $discount_price;
+
+ } else if( $quantity < 4){
+ $price_total = $quantity * 10;
+ }
+
+ $new_price = $price_total / $quantity;
+
+ // set the newly calulated price for pdf form
+ foreach($populated_fields as $price=>$info){
+ $_POST[$price] = $new_price;
+ }
+
}
?>
\ No newline at end of file
}
}
- if(qty_total > 4){
- price_total = (qty_total - 4) * 10 + 30;
- } else if( qty_total === 4){
- price_total = 30;
+ if(qty_total % 4 === 0){
+ var discount_qty = qty_total / 4;
+ var discount_price = discount_qty * 10;
+ price_total = (qty_total * 10) - discount_price;
+
+ } else if( qty_total > 4 && qty_total % 4 !== 0){
+ var discount_qty = Math.floor(qty_total / 4);
+ var discount_price = discount_qty * 10;
+ price_total = (qty_total * 10) - discount_price;
+
} else if( qty_total < 4){
price_total = qty_total * 10;
}
}
}
- if(qty_total > 4){
- price_total = (qty_total - 4) * 10 + 30;
- } else if( qty_total === 4){
- price_total = 30;
+ if(qty_total % 4 === 0){
+ var discount_qty = qty_total / 4;
+ var discount_price = discount_qty * 10;
+ price_total = (qty_total * 10) - discount_price;
+
+ } else if( qty_total > 4 && qty_total % 4 !== 0){
+ var discount_qty = Math.floor(qty_total / 4);
+ var discount_price = discount_qty * 10;
+ price_total = (qty_total * 10) - discount_price;
+
} else if( qty_total < 4){
price_total = qty_total * 10;
}