Hi.
I have a simple cart script that adds items to a session. The script first checks if an item with a unique id exists. If no it creates one, if yes just add to the quantity of the existing id:
public function add_item($id,$qty) {
if (!isset($_SESSION['cart'][$id])) {
$_SESSION['cart'][$id] = $qty;
} else {
$_SESSION['cart'][$id] += $qty;
}
return;
}
So a post consist of a product_id and qty e.g.:
101,1
But now I want to add to more values: attributes_text and attributes_price.
Now I am guessing I need multi-dimensional arrays like this:
So a post consist of a product_id, attributes_text, attributes_value, qty e.g.:
101,Deluxe edition,10.00,1
public function add_item($id,$attributes_text,$attributes_value,$qty) {
if (!isset($_SESSION['cart'][$id])) {
$_SESSION['cart'][] = array('product' => $id, 'attributes_text' => $attributes_text, 'attributes_value' => $attributes_value, 'qty' => $qty);
}
return;
}
Now I know this wouldn't work, that is why Im asking the question but you should get the general idea. Remember that if $id and $attributes_value both uniquely identify each post in the session.
Oh, and how to output the values 🙂