时间:2021-07-01 10:21:17 帮助过:28人阅读
$catid = $_GET['id'];
if( !isset( $_COOKIE[ $cookie_name ] ) ){
$cart_ary = array();
$cart_ary['cart'] = array();
$cart_ary['item_num'] = 0;
$cart_ary['total_price'] = 0.00;
setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
}
//第一次获取不到值,所以需要抑制第一次报错
$cart_ary = json_decode( str_replace( "\\","",@$_COOKIE[ $cookie_name ] ),true );
if( isset( $cart_ary['cart'][ $catid ] ) ){
$cart_ary['cart'][ $catid ]++ ;
}else{
$cart_ary['cart'][ $catid ] = 1;
}
$cart_ary['item_num'] = count_cart_item_num( $cart_ary['cart'] );
$cart_ary['total_price'] = count_cart_total_price( $cart_ary['cart'] );
setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
str_replace( "\\","",@$_COOKIE[ $cookie_name ] )
$catid = $_GET['id'];
if( !isset( $_COOKIE[ $cookie_name ] ) ){
$cart_ary = array();
$cart_ary['cart'] = array();
$cart_ary['item_num'] = 0;
$cart_ary['total_price'] = 0.00;
setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
}else {
$cart_ary = json_decode( str_replace( "\\","",@$_COOKIE[ $cookie_name ] ),true );
if( isset( $cart_ary['cart'][ $catid ] ) ){
$cart_ary['cart'][ $catid ]++ ;
}else{
$cart_ary['cart'][ $catid ] = 1;
}
$cart_ary['item_num'] = count_cart_item_num( $cart_ary['cart'] );
$cart_ary['total_price'] = count_cart_total_price( $cart_ary['cart'] );
setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
}