Page 1 of 1

[56K WARN] stock after customer add item to cart

Posted: Wed May 17, 2006 3:33 pm
by laura
i am a super newbie to php,i can make the cart untill this step it is bcos of the help of schoolmate!the problem might be easy for u guys here,but it is tough for me!i am super dumb in programing world!but i really need help for this php code,thank u everyone who helps me!!
i put the pictures and code,mayb can let ppl understd more easily!!thank you very much!!!!
Image Image Image Image

my problem is: how to code after a customer has added the items to the cart,the value of the stock
decrease.

this is the code in 'movies.php' page.

Code: Select all

<?php
if($_POST['add'])
{ 
$movieID=$_POST["movieID"];
$num=$_POST["num"];
$_SESSION["cart"][$movieID] += $num;
echo "added ok!!"; echo "<br>";
}
	
if($_POST["delete"])
{
	$_SESSION["cart"]=array();
	echo "delete your cart ok!!"; echo "<br>";
}
?>
this is the code in 'cart.php' page.

Code: Select all

foreach($_SESSION["cart"] as $movieID=>$num)
{
	$sql="select * from movies where MovieID=".$movieID;
	//print $sql;
	$rs=mysql_query($sql,$myConn);
	$row=mysql_fetch_array($rs);
	$ss=$num*$row["Price"];
	echo "<tr>";
	echo "<td>";
	print $row[1];
	echo "</td>";
	echo "<td>";
	print $row[2];
	echo "</td>";
	echo "<td>";
	print "<img src='images/".$row["3"]."' height=50 width=50>";
	echo "</td>";
	//print $movieID;
	print "<td>";
	print $num;
	print "</td>";
	echo "<td>";
	print $ss;		
	echo "</td>";
	$sum+=$ss;
	echo "</tr>";
}
echo "<tr>";
echo "<td colspan=4>";
print "Total Sum is ";
echo "</td>"; 
echo "<td>"; 
echo $sum; 
echo "</td>";
echo "</tr>";
echo "</table>";
pls dun laught at my question!!! ^^

Posted: Thu May 18, 2006 11:25 am
by laura
seem nobody could help me.... T-T

Posted: Thu May 18, 2006 3:00 pm
by Oren
I don't think you really want to do that. People add items to their carts every day, it doesn't mean they buy anything.
I believe that the site admin should decrease the stock manually when he/she really sells an item.

Posted: Thu May 18, 2006 5:49 pm
by laura
is it u suggest me dun show the stock?is this way better?

Posted: Thu May 18, 2006 5:59 pm
by lBurt0n
I think the suggestion is not to have such a dynamic level of stock. The problem is you have Item Ain stock with 90 left and someone comes onto your site and malicously puts 90 in there basket without intention to buy, anyone who comes on who actually wants to buy one will see that its out of stock. Also people including myself like to go on sites and pretend buy items, whether it be to see if the site seems trust worthy or just pretending for that moment I can afford something that I won't be able to buy for years on my wages!

Your best bet is to update the stock levels manually as the sales are made because otherwise it could end up backfiring on you. Many big online shops I've bought off when they have had 1 item left in stock. Even after I've paid for my item if I go back to the product page it will still say "1 item left"... even though I know I've bought it... its common practice... hope thats helped.

-Leonard

Posted: Thu May 18, 2006 6:15 pm
by laura
i got it..tq very much..
i think i will make another one update for stocks.
cos i have update for 'products',update for 'category'.
ok,i will try to make update stocks n see ^^v
tq^^

Posted: Thu May 18, 2006 7:49 pm
by Christopher
laura wrote:my problem is: how to code after a customer has added the items to the cart,the value of the stock
decrease.
You really only want to decrease stock once to order is processed successfully.

If you have very high order volume and must maintain exact stock then you can create a record to indicate that a certain number of units of an item are on hold. The hold records are deleted when the order is processed and the actual stock number decreased. The hold records are timestamped so you can clear records from abandoned carts.

Posted: Thu May 18, 2006 10:15 pm
by feyd
Please leave the "56K WARN" note in the subject laura, you have 4 rather large images that are not friendly to modem users.

Posted: Fri May 19, 2006 4:29 pm
by laura
arborint : tq,is a very good information! (but is kinda difficult for me to code =.=""" ,i m not good in coding!!when i code,usually have fren beside me=.=" )but thanks!

arborint : sorry!i dunno what is the 56k means!that's y i deleted it!cos i tot i have problem!!
ok!i will leave it!!! tq!!!

tq everyone!