Jump to content

custom cart working out discounts


mupparion

Recommended Posts

Hi,

 

What i want is relatively simple yet i seem to be massively over complicating it.

I've never really had to use forums for help before but this is annoying me now lol.

 

Basically, what i want is when someone orders 3 or more products that aren't in this case, a canvas, they get 20% off the cheapest 3 products.

But where things get complicated is that there is also a quantity field. So if someone orders say 1 item at 1.99 and then 3 at 2.99 id have to be able to get 1.99 + 2 lots of 2.99 and then work out the 20% on that. And obviously i dont know what they're going to order so it needs to be something dynamic and i've kinda written rules for several possibilities but i cant get it right.

 

Heres my code so far anyway:

 

$row3 = mysql_fetch_array(mysql_query("SELECT SUM(qty) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 3"));
$price3 = mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 3"));

$row2 = mysql_fetch_array(mysql_query("SELECT SUM(qty) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 2"));
$price2 = mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 2"));

$row1 = mysql_fetch_array(mysql_query("SELECT SUM(qty) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 1"));
$price1 = mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 1"));

$totalqty3 = $row3['SUM(qty)'];
$totalnonec=mysql_num_rows(mysql_query("SELECT * FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas'"));
/////IF QTY FROM 3 ITEMS IS MORE THAN 3 OR IS 3
if($totalqty3 > 3 && $totalnonec == 3){
echo "3 > 3";
}elseif($totalqty3 == 3  && $totalnonec == 3){
$otherdiscount = (($price3['SUM(price)'] + 0.03)  * 3) * 0.2;


/////IF QTY FROM 2 ITEMS IS MORE THAN 3 OR IS 3
}elseif($row2['SUM(qty)'] > 3  && $totalnonec == 2){
$otherdiscount = (($price2['SUM(price)'] + 0.03)  * 3) * 0.2;
}elseif($row2['SUM(qty)'] == 3  && $totalnonec == 2){
$otherdiscount = (($price2['SUM(price)'] + 0.03)  * 3) * 0.2;

/////IF QTY FROM 1 ITEM IS 3 OR LESS
}elseif($row1['SUM(qty)'] > 2  && $totalnonec == 1){
$otherdiscount = (($price1['SUM(price)'] + 0.03)  * 3) * 0.2;
}else{
$otherdiscount = 0.00;
}

$totaldiscount = $otherdiscount;

 

$otherdiscount = (($price3['SUM(price)'] + 0.03)  * 3) * 0.2;

This is basically, get the price total, add 3p (as all prices end in .99 so it rounds it off) x 3(as you get 20% off 3 items) then x 0.2 to get the 20% value.

 

Probably worth starting over but id have know idea where to begin lol so any help with getting this code to work or posting some new code on where to start would be brilliant!

 

Thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.