Jump to content

help needed with cart function


adi123

Recommended Posts

I have 3 actions below which control my cart. My problem is with the minus action. It's supposed to remove 1 quantity from the cart but instead it takes the quantity all the way down to 1.

 

for example: you add 3 quantities of a usb stick and you want to remove 1 quantity, it would take the amount of quantity to 1 instead of 2.

 

here are the functions:

 

switch ($action) {

case 'add':

if ($cart) {

$cart .= ','.$_GET['id'];

header("Location: cart.php");

} else {

$cart = $_GET['id'];

header("Location: cart.php");

}

break;

case 'minus':

if ($cart) {

$items = explode(',',$cart);

$newcart = '';

foreach ($items as $item) {

if ($_GET['id'] != $item) {

if ($newcart != '') {

$newcart .= ','.$item;

} else {

$newcart = $item;

}

}

}

$cart = $item - $id;

}

break;

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 != '') {

$newcart .= ','.$item;

} else {

$newcart = $item;

}

}

}

for ($i=1;$i<=$value;$i++) {

if ($newcart != '') {

$newcart .= ','.$id;

} else {

$newcart = $id;

}

}

}

}

}

$cart = $newcart;

break;

}

 

can some help with the minus function. thanks

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.