Jump to content

Recommended Posts

It now adds X ammount of products I add, but it still fails to update.

 

 

Here is the code for the entire process as it stands:

 

/(product)/index.html

<FORM action="../../../../cart/addtocart.html" method="post" name="form">
<DIV>
	Add <TEXTAREA class="quantity" cols="0" name="quantity" rows="0">
	</TEXTAREA> <SELECT class="size" name="size"><OPTION>Large</OPTION></SELECT> to 
	<INPUT class="cart" type="submit" value="CART"><INPUT class="id" name="id" type="hidden" value="<?php echo $id; ?>">
</DIV>
</FORM>

 

cart/addtocart.html

<?php
$quantity = $_POST['quantity'];
$size = $_POST['size'];
$id = $_POST['id'];
$item_found = false;
foreach ($_SESSION['cart']['content'] as $key=>$product) {
	if ($product['id'] == $id) {
		$item_found = $key;
		break;
	}
}
if ($item_found !== false) {
$_SESSION['cart']['content'][$item_found]['$quantity'] = $_SESSION['cart']['content'][$item_found]['$quantity'] + $quantity;
	echo "Quantity updated";
} else {
	$_SESSION['cart']['content'][] = array ('quantity' => $quantity, 'size' => $size, 'id' => $id);
	echo "Added.";
}
?>

 

cart/index.html

$query = "select * from products where id='{$content['id']}'"; $result = mysql_query($query); $row = mysql_fetch_array($result);
echo '
	<DIV class="cartproduct">
		<IMG alt="" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png">
		<DIV class="cartproductdata">
			<B>Product ID:</B> '.$content['id'].'
			<BR>
			<B>Size:</B> '.$content['size'].'
			<BR>
			<B>Price:</B> $'.$row[price].' AUD
			<BR>
			<B>Quantity:</B> '.$content['quantity'].'
			<BR>
			<BR>
			<INPUT type="submit" value="REMOVE FROM CART">
		</DIV>
	</DIV>
';

Buddski it worked bro! Thanks

Tomorrow I am gonna work on the removing part. That I will be able to figure out myself with this new code flow. Its familiar now I understand WTF is going on.

 

Do you have Facebook? Your my age and from VIC aswell and seem to enjoy computers as do I. Send me a PM and I'll add ya.

 

I'm going to bed man, I am Fd! running around the CBD all day over absolute BS. TTYL

Buddski it worked bro! Thanks

Tomorrow I am gonna work on the removing part. That I will be able to figure out myself with this new code flow. Its familiar now I understand WTF is going on.

 

Do you have Facebook? Your my age and from VIC aswell and seem to enjoy computers as do I. Send me a PM and I'll add ya.

 

I'm going to bed man, I am Fd! running around the CBD all day over absolute BS. TTYL

psyco stalker...

Buddski it worked bro! Thanks

Tomorrow I am gonna work on the removing part. That I will be able to figure out myself with this new code flow. Its familiar now I understand WTF is going on.

 

Do you have Facebook? Your my age and from VIC aswell and seem to enjoy computers as do I. Send me a PM and I'll add ya.

 

I'm going to bed man, I am Fd! running around the CBD all day over absolute BS. TTYL

psyco stalker...

Hahahahaha...

AyKay47, it sounds like you don't have much experience in life. I suspect your one of those womanless losers that has spent their entire social life on SourceForge and Warhammer 10 000 forums.

 

 

Sup Buddski,

 

When I add 1 size Large to a SESSION, it adds fine... When I had another 3 size Large to the SESSION, it adds onto 1 fine and becomes 4... but when I add 1 size Small, it adds onto the same entity in the session and becomes 5.

 

Now that my brains functioning again, I checked out the code you suggested and I think I can see why its happening:

The action to add to the SESSION is:

foreach ($_SESSION['cart']['content'] as $key=>$product) {
if ($product['id'] == $id) {
	$item_found = $key;

 

... I think its happening because the key is just the id, and I think what needs to be done is also make the key the size?

I tried this, but it didn't work:

foreach ($_SESSION['cart']['content'] as $key=>$product,$size) {
if ($product['id'] == $id && $product['size'] == $size) {
	$item_found = $key;

 

... am I going the right way about it? Like, with the key being the id and the size or am I tripping? lol

... Also tried this:

foreach ($_SESSION['cart']['content'] as $key=>$product && $key=>$size) {
if ($product['id'] == $id && $product['size'] == $size) {
	$item_found = $key;

... and this:

foreach ($_SESSION['cart']['content'] as $key=>$product & $key=>$size) {
if ($product['id'] == $id & $product['size'] == $size) {
	$item_found = $key;

... and this:

foreach ($_SESSION['cart']['content'] as $key=>$product || $size) {
if ($product['id'] == $id || $size) {
	$item_found = $key;

... but fail.

1)  None of those are proper syntax.  use a regular foreach loop and print_r the row inside the loop so you know what you're dealing with.

 

2)  Don't feed the trolls.  AK would have left you alone if you had ignored him.  He's a troll.  If someone honestly has nothing better to do than be a dick on the internet, let them be a dick somewhere else.

Thanks ManiacDan for the code suggestion and advice.

 

I've changed the entire code flow to how my cart should work, and have another problem at the moment. I am 100% confident I will know how to remove a session entity with this new code flow, so I think this thread has been concluded.

 

Thanks to everyone who constructively contributed to this thread. :)

 

!Lock!

1)  None of those are proper syntax.  use a regular foreach loop and print_r the row inside the loop so you know what you're dealing with.

 

2)  Don't feed the trolls.  AK would have left you alone if you had ignored him.  He's a troll.  If someone honestly has nothing better to do than be a dick on the internet, let them be a dick somewhere else.

wouldn't calling someone a troll on the internet when you know nothing about them also be considered "dick like" behavior.. hmmm

i was a dick because I can't stand complete morons on here.

Guest
This topic is now closed to further replies.
×
×
  • 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.