Reputation: 753
I am creating a PHP cart for a photography business. This is the 1st Ecommerce site I have attempted (Newbie)
I have managed to add products to the cart (stored in the session) (Products: Print, Keyring, Magnet ect)
However I also need to add the imageID to the session
Here is my code
$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;
Which saves the product to the basket
The cart.php url is shown as:
cart.php?imageid=83&id=12&action=add
Could anyone help/advise how I add the Image ID to the product?
Thanks
Upvotes: 0
Views: 147
Reputation: 727
This is assuming one image can be used by different products? Otherwise, you should simply be able to deduce which image to use based on the product 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;
Anyway, without seeing your actual markup, adding the image to the basket should be something like:
<basket element>
<item element>
<img src="path/to/images/<?=$_SESSION['images'][$product_id]?>.filetype" />
</item>
</basket>
Upvotes: 1