Hello,
This is not a question. I am setting up a shopping cart which requires multiple price breaks to calculate the booking fee for tickets (as many as the client wants) and I've come up with a solution so I thought I should post it here in case someone runs into this problem in the future 🙂
Let's assume there's a text field in your database holding the price break info in this format:
1,2.00
5,1.50
10,1.00
so each line is a seperate break. First value is the quantity limit and second value is the price (seperated by a comma).
function get_fee($breaks,$quantity){
// split lines into array
$lines = explode("\n", $breaks);
// loops through array above
while ( list($key, $val) = each($lines) ) {
// make sure there are no blank lines
if($val != ""){
// split each line, get break and price
list ($br,$price) = split (',', $val);
// if quant >= than break limit flag on
if($quantity >= $br){
$booking = $price;
$flag = 1;
}else{
$flag = 0;
}
// exit loop
if($flag == 0){ end; }
}
}
// pass final booking value
return($booking);
}
// call function
$booking_fee = get_fee($breaks,$quantity);
I hope this comes in handy for someone one day 🙂
A