Jump to content

id


raptor30506090

Recommended Posts

If English is not your first language, just try to say MORE on the subject so we can get an idea of what you mean.

 

What you need to be doing is storing the cart in the session using the product ID as the key:

 

$_SESSION['cart'][$productId] = array('quantity' => 5, 'price' => 9.99, 'options' => array( 'color' => 'green', 'size' => 'medium' ) );

Link to comment
https://forums.phpfreaks.com/topic/265112-id/#findComment-1358583
Share on other sites

this is were im a bit stuck if they orderd

 

$_SESSION['cart'][$productId] = array('quantity' => 5, 'price' => 9.99, 'options' => array( 'color' => 'green', 'size' => 'medium' ) );

 

and then same person orderd

 

$_SESSION['cart'][$productId] = array('quantity' => 5, 'price' => 19.99, 'options' => array( 'color' => 'blue', 'size' => 'large' ) );

 

would that over right the first order?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/265112-id/#findComment-1358591
Share on other sites

I don't know, that's a business rule.  What do you want to happen when they do that? 

 

If I bought 3 green shirts at $9.99, then 15 red shirts at $8.00, would you really make an entry for 18 shirts?  How would you ever figure out the original order?

 

If it were me, I'd probably use the same idea I gave you earlier, except $_SESSION['cart'][$productId] would be an array of products, each with their own quantities and specifications.  if all specifications matched, I'd update the quantity.  If any one of them did not match, I'd add a new row. 

 

Obviously, if $_SESSION['cart'][$productId] didn't already exist I'd add a new array of products, like this:

 

 

$_SESSION['cart'][$productId] = array( array( 'quantity' => 5, 'price' => 9.99, 'options' => array( 'color' => 'green', 'size' => 'medium' ) ) );

 

Link to comment
https://forums.phpfreaks.com/topic/265112-id/#findComment-1358614
Share on other sites

Archived

This topic is now archived and is 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.