Okay, so now, instead of dumping them right into the order and payment
form after they click a button, you want them to be able to continue
shopping, maybe order something else? You would need to modify your
form handler page a little, and maybe offer a choice: Check out? or
Continue shopping?
To add a product purchase to your session, you would need to take all
the inputs sent to the form handler and put them in a recognizable
shape. I would probably do this:
$id = array($price => $qty);
If they order the same thing a second time, that would overwrite the
current quantity with the new one. I’m not sure I would even accept
the price sent by the form, that’s just making it too easy for someone
to rob you. Look it up again from a known standard, like an include
file that you use in both the shopping page(s) and the order processor
page. So you could just store $id = $qty and be done. There’s one tiny
thing that you have to attend to, though, and that is that a variable
name cannot start with a numeral. So you’ll have to prepend a string
to it to make it safe as a name:
session_start();
if(isset($_POST['id'])){
$_SESSION['id_' . $_POST['id']] = $_POST['qty'];
}
//$id_123 = '4' or something like that.
Then you just have to loop over your product ids and get the quantity
for each while building your display of products ordered:
$products = array('123' => array('5-string Banjo','25'),
'456' => array('Beaver-shaped shoe scraper','45')
'789' => array('Plate glass window','750')
);
$total = 0;
$cart = '<p>';
foreach($products as $id => $product){
if(isset($_SESSION['id_' . $id])){
$qty = $_SESSION['id_' . $id];
$extended = ($qty * $product[1]);
$cart .= . $product[0] . ' quantity: ' . $qty . ' subtotal: $' .
$extended '<br />';
$total += $extended;
}
}
$cart .= '</p>';
That’s very rough, but it should show you the beginnings of how this
works.
Walter
On May 28, 2010, at 2:44 PM, David Owen wrote:
I have not got round to doing anything on the session code yet, just
exploring what is possible (I’ll try and take a look this weekend)
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options