PHP购物车 - 添加变量

时间:2015-09-07 11:27:48

标签: php mysql cart

我正在为摄影业务创建一个PHP购物车。这是我尝试的第一个电子商务网站(新手)

我设法将商品添加到购物车(存储在会话中) (产品:印刷,钥匙圈,磁铁等)

但是我还需要将imageID添加到会话

这是我的代码

$product_id = $_GET[id];     //the product id from the URL 
    $imageId = $_GET[imageid];   //the image id from the URL 
    $action     = $_GET[action]; //the action from the URL 

    switch($action) {   //decide what to do 

        case "add":
            $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id 
        break;

将产品保存到购物篮中 enter image description here

cart.php网址显示为:

  

cart.php图像标识= 83&安培;?ID = 12&安培;行动=添加

有人可以帮助/建议我如何将图像ID添加到产品中吗?

由于

1 个答案:

答案 0 :(得分:1)

这假设一个图像可以被不同的产品使用?否则,您应该只能根据产品ID推断出要使用的图像:

case "add":
    $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id
    $_SESSION['images'][$product_id] = $imageId; //Will map the image ID to the product being added
break;

无论如何,如果没有看到你的实际标记,将图像添加到购物篮应该是这样的:

<basket element>
    <item element>
        <img src="path/to/images/<?=$_SESSION['images'][$product_id]?>.filetype" />
    </item>
</basket>