我如何从购物车改变会话

时间:2015-03-02 03:09:51

标签: session cart shopping

如何更改衬衫的尺寸。 我有代码将产品添加到成功SESSION,如下所示: 尺寸为衬衫的尺码为(S,M,L,XL)

    <?php
$id = $_GET['id']; 
$quanlity = $_GET['quanlity'];
$size = $_GET['size'];

if(!isset($_SESSION['cart'][$id][$size]) or $_SESSION['cart'][$id][$size] == "" or $_SESSION['cart'][$id][$size] == NULL)

$_SESSION['cart'][$id][$size] = $quanlity;

else $_SESSION['cart'][$id][$size] = $_SESSION['cart'][$id][$size] + $quanlity;
?>

现在我想购物后顾客可以改变尺码(尺码服装),我用以下段落jQuery:

$(function() {
 $(".changesize").change(function() {
     var id = $(this).attr("rel");
     var size = $("#product-size-tab"+id+" select").val();
     var type = "POST";
     var url = "change_size.php";

$.ajax({
  type: type,
  url: url,
  data: {shopping_id : id, shopping_size : size}
 })
    .done(function(data) {


});


 return false;

});

});

PHP文件:

    <select class="changesize" id="product-size-tab<?php echo $data['shopping_id']; ?>" name="shopping_size" rel="<?php echo $data['shopping_id']; ?>">
<option value="<?php echo $item; ?>">Do not change</option>
<?php  $sizes = explode(", ", $data['shopping_size']);
foreach ($sizes as $s) {
echo "<option value=\"".preg_replace('/\s+/', '', convert($s))."\">$s</option>";
}
?>

文件 change_size.php

    <?php
session_start();
if(isset($_POST['shopping_id'])){

      $toBeUpdate = $_POST['shopping_id'];
      $CartR = $_SESSION['cart'];
      $size = $_POST['shopping_size'];

         foreach($CartR as $key => $Cart){  
                if($Cart['id'] == $toBeUpdate){  
                    $_SESSION['cart'][$key]['size'] = $size;
               }
         }
              echo json_encode(array('success'=> true));
}
?>

请帮帮我...僵局。

0 个答案:

没有答案