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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
laura
Forum Newbie
Posts: 19
Joined: Wed May 17, 2006 1:06 pm

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

Post 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!!! ^^
Last edited by laura on Thu May 18, 2006 6:18 pm, edited 1 time in total.
User avatar
laura
Forum Newbie
Posts: 19
Joined: Wed May 17, 2006 1:06 pm

Post by laura »

seem nobody could help me.... T-T
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
User avatar
laura
Forum Newbie
Posts: 19
Joined: Wed May 17, 2006 1:06 pm

Post by laura »

is it u suggest me dun show the stock?is this way better?
lBurt0n
Forum Newbie
Posts: 6
Joined: Thu May 18, 2006 3:48 pm

Post 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
User avatar
laura
Forum Newbie
Posts: 19
Joined: Wed May 17, 2006 1:06 pm

Post 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^^
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
laura
Forum Newbie
Posts: 19
Joined: Wed May 17, 2006 1:06 pm

Post 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!
Post Reply