I have a function which updates a cart but it is not working correctly. Basically if i have e.g.
2 x Red Shoes
3 x Blue Shorts
And then i change the qty of the blue shorts to 4 and pass to the update function it just completely removes the first lot of items in the list e.g. the 2 x red shorts.
The data is stored in a session like so:
Expand|Select|Wrap|Line Numbers
- 58:|Red Shoes|14.95,58:|Red Shoes|14.95,56:|Blue Shorts|8.95,56:Size|Blue Shorts|8.95,56:Size|Blue Shorts|8.95
Expand|Select|Wrap|Line Numbers
- case 'update':
- if ($cart) {
- $newcart = '';
- foreach ($_POST as $key=>$value) {
- if (stristr($key,'qty')) {
- $id = str_replace('qty','',$key);
- $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
- $newcart = '';
- foreach ($items as $item) {
- if ($id != $item) {
- if ($newcart != '') {
- $item = '';
- $newcart .= ','.$item;
- } else {
- $item = '';
- $newcart = $item;
- }
- }
- }
- for ($i=1;$i<=$value;$i++) {
- if ($newcart != '') {
- $newcart .= ','.$id;
- } else {
- $newcart = $id;
- }
- }
- }
- }
- }
- $cart = preg_replace("/_/i", " ", preg_replace("/(\d+)_(\d+)/i", "$1.$2", $newcart));
- break;
- }
Adam