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
https://forums.phpfreaks.com/topic/214117-help-needed-with-cart-function/
Share on other sites

  • 2 weeks later...

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.