Hello
I am working on a snippet which can be used as a shopping cart using the pictures from maxigallery.
So far I made a chunk for maxigallery thumbs with a checkbox. The value of the checkbox is the path to the picture. I don’t know if this right yet, I’ll find out when I have to list the photo’s and calculate the price.
I have made a snippet with the following code:
$output = "";
include(’’.$modx->config[’base_path’].’assets/snippets/shop/index.php’);
return $output;
index.php contains the following:
<?php
session_start();
//Add new pictures
if($_SERVER[’REQUEST_METHOD’] == ’POST’) {
$cart = array();
$items = array();
$items = $_POST[’photo’];
//In case there is already something in the basket, copy its contents first
if(!empty($_SESSION[’cart’])){
$cart = $_SESSION[’cart’];
}
foreach($items as $item){
array_push($cart, $item);
}
$_SESSION[’cart’] = $cart;
}
//Create a list of the pictures in the basket
if($list == 1 || $_GET[’list’] == ’pics’){
if(empty($_SESSION[’cart’])){
$output = "There are no pictures in your basket.";
} else{
$output = "<ul>";
foreach($_SESSION[’cart’] as $item){
$output .= "<li>".$item."</li>";
}
$output .= "</ul>";
}
return;
}
?>
There is a problem though, when I add something to the basket, and then view the list, it still says the basket is empty.
When I tested it halfway making it, it did work. So I must have done something wrong. Does anyone see what I am doing wrong?
Also, feel free to comment on my idea in any way
Thanks in advance,
Erwin