I have a shopping cart class and when the user puts a product in their cart I have to do a check on that product to see if it has a price break on it
IE: product price each = $5.99 buy 5 and you get them for $3.99 each
I'm getting it to work half ass, basically I have a table that stores the buy# and the new price along with a product id to xref the products table but I'm always getting the last row of data's price right now
<?php
function PriceBreakCheck($product,$qty)
{
//GET MY RESULT SET TO SEE IF THERE IS A PRODUCT BREAK
$result = query_db("SELECT products_price, products_pbreak FROM products WHERE products_id = $product");
$row = @mysql_fetch_array($result);
// IF THERE IS NO PRODUCT BREAK JUST USE THE NORMAL PRODUCT PRICE
if(($row['products_pbreak']) == 0){
$this->unit_price = ($row['products_price']);
return $this->unit_price;
//START THE SECTION TO LOOP THROUGH THE BREAKS
} else { // 1st else
$result2 = query_db("SELECT p.products_id, products_price, products_pbreak,break_buy,break_fixed "
."FROM products as p,products_pbreak as pb WHERE p.products_id = $product ORDER BY break_buy asc");
$numrows = mysql_num_rows($result);
GOTTA DO SOMETHING HERE TO LOOP THROUGH THE TABLE AND GET THE RIGHT DATA
}
}
?>
my table result looks like this:
products_id products_price products_pbreak break_buy break_fixed
4 16.99 1 6 14.99
4 16.99 1 100 12.99
4 16.99 1 200 10.99
basically if someone buys 150 of these things the price should be 12.99 each
if they buy 204 they should be 10.99 each
if they buy 3 then its under the minimum of 6 for the price break so the price should be the standard product price
I've been stuck on the logic for a few hours now 🙁