0

want to minus the quantity when click delete if cart qty is more then 1

//remove item from shopping cart
if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"])){
    $product_code   = $_GET["removep"]; //get the product code to remove
    $product_s      = $_GET["removes"]; //get the product size to remove
    $return_url     = base64_decode($_GET["return_url"]); //get return url

    foreach ($_SESSION["products"] as $key=>$cart_itm){ //loop through session array var
        if($cart_itm["id"] !=$product_code || $cart_itm["size"] !=$product_s){ //item does,t exist in the list
          $product[] =array(

              'name'=>$cart_itm["name"],
              'id'=>$cart_itm["id"], 
              'size'=>$cart_itm["size"],
              'qty'=>$cart_itm["qty"],
              'price'=>$cart_itm["price"]);
            }
        //create a new product list for cart
         $_SESSION["products"] = $product;
    }
        //redirect back to original page
    header('Location:'.$return_url);
}

this code is deleting the product but i want minus also when qty is greater then 1

2
Contributors
3
Replies
24
Views
3 Years
Discussion Span
Last Post by minitauros
0

Why don't you just select the product merely by the product code? Or isn't that unique?

E.g.

foreach($_SESSION['products'] as $key => $cart_item) {
    if($product_code == $_GET['product_code']) {
        //* This is the product of which we're reducing the quantity.

        // Substract one (or whatever you want) from the quantity.
        $cart_item['quantity'] -= 1;

        // Save the product in its session variable.
        $_SESSION['products'][$key] = $cart_item;
    }
}
0

You should not use that exact example, but modify it to your own needs. Or did you do that already and is it still not working?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.