0

Hi, now I've a function which is add product to cart:

    function addtocart($pid,$q,$attribute){
        if($pid<1 or $q<1) return;

        if(is_array($_SESSION['cart'])){

            $max=count($_SESSION['cart']);
            $_SESSION['cart'][$max]['productid']=$pid;
            $_SESSION['cart'][$max]['qty']=$q;
            $_SESSION['cart'][$max]['attribute']=$attribute;
        }
        else{
            $_SESSION['cart']=array();
            $_SESSION['cart'][0]['productid']=$pid;
            $_SESSION['cart'][0]['qty']=$q;
            $_SESSION['cart'][0]['attribute']=$attribute;
        }
    }

And now my remove product function is :

$id is generate from for loop in cart page which is same value with $i below

    function remove_product($id){
        $id=intval($id);
        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){

            (This part how to determine $_SESSION['cart'][$i] that match with $id)?

                unset($_SESSION['cart'][$i]);
                break;
            }
            if($_SESSION['cart'] == ''){
            unset($_SESSION['cart']);   
            }
        }
        $_SESSION['cart']=array_values($_SESSION['cart']);
    }

my previous code is :

if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;

but now I don't want to determine productid , I want to determine the number $i that pass from my cart page and remove the item. Any solution?

2
Contributors
1
Reply
19
Views
4 Years
Discussion Span
Last Post by LastMitch
0

but now I don't want to determine productid , I want to determine the number $i that pass from my cart page and remove the item. Any solution?

@devianleong

Even before we start assisting you. You have to be very honest with us. Where did you get this code? Are you using a platform like Magento or Prestoshop? If so you are trying to modify the file? If you did created this code, you should know there is a by pass and so far the code you provided doesn't show any sign of it. You need to post a code related to that

Edited by LastMitch

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.