We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40944
    • 78 Posts
    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 tongue

    Thanks in advance,
    Erwin
      • 40944
      • 78 Posts
      I got it to work by including the config file and starting a cms session instead of a normal session.

      Still to do
      A tool for printed pictures (size, crop, quantity price calculation, ..)
      Paying method (probably Ideal, a dutch online banking system)

      I think I still forgot some to-dos.
        • 3349
        • 126 Posts
        Sounds great - i’ve been looking at a solution like this for ages.

        I wish I could help you with aspects of it but unfortuantely have little coding experience.

        Keep us posted!

        bS
          • 40944
          • 78 Posts
          I have encountered some problems again.

          The first problem is the add to cart button. The button should only appear when the images are listed, but since the <form> tags have to be arround the checkboxes, I have to do something like this:
          <form>
          [!MaxiGallery!]
          <input type="submit" value"add images" />
          </form>

          That way the input button wil always be there.

          I came up with 2 1 solutions so far:
          1. Call the maxigallery snippet in my snippet, that way I have more control over maxigallery.
          I don’t even know if that works, also it seems unhandy to me.

          Calling a snippet in a snippet did’t work when I tried. Maybe I did something wrong, please tell me if so.

          2. Create a few Tpl’s for first and last MG picture, and put the form and button in the chunks.
          I want to keep it as simple as possible this way users have to create all kinds of chunks first...

          Suggestions anyone? huh
            • 7690
            • 166 Posts
            Nice idea. I was looking for this.
            Keep up the good work. Can’t wait till the alpha version.
              • 40944
              • 78 Posts
              I thought of something new. Now, I am just going to include the MaxiGallery file into my snippet.

              All the parameters will be used on my snippet, so MG will recognize them. I will test some things if it works properly. If it does, development continues.
                • 40944
                • 78 Posts
                Hello,

                I thought you might be interested in a preview of the snippet.

                So far I have got these parameters:
                -&list: 1 to show the shoppingcart. (default: 0)
                -&mg: 1 to output maxigallery (default: 0)
                -&lang: en for english, nl for dutch (default: en)
                -&cartID: the document ID of the shopping cart page.
                -&digitalPrice: price for digital pictures (default: 2,50)
                -&printPrice: price for printed pictures (default: 5,00)

                I still have to do something with the pricing, this is a unhandy way.

                Oh and the maxigallery parameters can be placed within the same snippet call.

                Snippet code:
                <?php
                $output = "";
                $path_to_galleries="assets/galleries/"; // [ path ]
                define(MAXIGALLERY_PATH, "assets/snippets/maxigallery/");
                define(MAXICART_PATH, "assets/snippets/maxiCart/");
                include(''.$modx->config['base_path'].'assets/snippets/maxiCart/maxiCart.php');
                return $output;
                ?>


                I deleted the comment in the maxigallery snippet to see what was important, I will put the credits back later

                In de attached rar file you will find my snippet code, and also a little patch for maxigallery.
                The only thing that has been changed in the maxigallery file is that I replaced all $output = [...] for $output .= [...].


                Please tell me what you think of it,

                Erwin