PHP 购物车 - 添加变量

PHP Cart - Adding variables

我正在为一家摄影公司创建一个 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;

将产品保存到购物车

cart.phpurl显示为:

cart.php?imageid=83&id=12&action=add

任何人都可以 help/advise 我如何将图像 ID 添加到产品中?

谢谢

这是假设一张图片可以用于不同的产品?否则,您应该能够根据产品 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>