We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9549
    • 93 Posts
    I know this is an old thread, but have you thought about doing some sort of documentation of how to integrate this completely into MODx, with the snippets and the custom eForm function? I’m trying to migrate it MODx but I don’t seem to get my head around it. However, I’m using a payment gateway that would be fairly easy to install into Flat File.
      • 14050
      • 788 Posts
      Sorry I am to the party so late, but hopefully I can provide some insight on how to integrate this into a MODx install. Hopefully I will be able to remember how I implemented it myself, so as to document it in digestible steps for you to consume.


      1. Create a chunk that will serve as the template for your list of products. In this example we will name it "products". The content should contain the following:
      [+productid+]|[+productname+]|[+productprice+]|[+productdescription+]|;


      2. Create template variables to match the above code. So you should have a TV called "productid", "productname", "productprice","productdescription". I set the input type to "Text" for all but "productdescription" which I set to "Text Area." Make sure to provide "Template Access" to these TVs by checking the appropriate box.

      3. Now create a new document to hold all your products. In this example we will name it "Catalog" and it will be the parent document for all products. Make sure it is published.

      4. Create another new document, which will generate the product list based on the chunk you created it. In this example I call mine "Product-List". It should be published and have the following content:
      [[Ditto?parents=`48`&tpl=`products`&display=`all`]] 

      Make sure to replace "48" with the ID of the "Catalog" document we created earlier.

      5. Download the PHPCart file at http://cmssandbox.com/MODx096/assets/snippets/sss/FlatFileCart.php.txt and look for the following:
      define("PRODUCTS_FILE_PATH", "http://cmssandbox.com/MODx096/index.php?id=49");

      Make sure to replace the "49" with the ID of the "Product-List" document we created earlier. Rename this file to "FlatFileCart.php" and upload this file to the snippet directory in a folder called "sss".

      6. Now create a snippet called "sss" with the following code:
      <?php
      include_once('assets/snippets/sss/FlatFileCart.php');
      $productTVs = array ('productprice','productdescription','productid','productname');
      $id =  $modx->documentObject['id'];
      $productTVs = $modx->getTemplateVarOutput($productTVs,$docid=$id, $published="1");
      $title = $modx->documentObject['pagetitle'];
      $longtitle = $modx->documentObject['longtitle'];
      
      return ReturnAddLinkHTML($productTVs[productid], "Add to Cart",$id);
      ?>


      7. Create another snippet called "sss_cart" with the following code:
      <?php
      include_once('assets/snippets/sss/FlatFileCart.php');
      $id =  $modx->documentObject['id'];
      if (!isset('tpl') $tpl = 'No template was set.';
      else $tpl = $modx->getChunk($tpl);
      $sss_cart = ReturnCartHTML(1,$id,$tpl);
      echo $sss_cart;
      return ReturnConditionalClearLinkHTML("<br />", "", "Clear the cart",$id);
      
      	//add a placeholder for the cart in eForm
      	function returnCartReport( &$fields ){
      		global $modx;
      		include_once('assets/snippets/sss/FlatFileCart.php');
      		$id =  $modx->documentObject['id'];
      		if (!isset('tpl') $tpl = 'No template was set.';
      		else $tpl = $modx->getChunk($tpl);
      		$sss_cart = ReturnCartHTML(1,$id,$tpl);
      		ClearCart();
      		$fields['sss_cart'] = $sss_cart;
      		//return succes
      		return true;
      	}
      ?>


      8. We are getting closer. In your catalog parent, start creating documents that represent each individual product. Make sure the template is set to one that hass access to the TVs created earlier. Fill in the appropriate information in each respective TV and make a call to the snippet in the content of the document as: [!sss!]

      9. Now create a chunk to serve as the template for the cart. You can call your template "Cart_TPL" and place the following in it:
      {+quantity+} x {+name+} = ${+quantityprice+} - <a href="{+addlink+}">Add</a>/<a href="{+removelink+}">Remove</a><br />


      10. Next place a call to the snippet in your template where you want your cart to appear. The snippet to call is [!sss_cart? &tpl=`Cart_TPL`!]. Follow that call with some code like this:
      <br /><a href="[~6~]">Checkout</a>

      Make sure to replace the "6" with the ID of the document containing your eForm call (See next step.)

      11. Lastly, you need to create a document with an eform call. The eform call should look like this:
      [!eForm? &formid=`ContactForm` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &eformOnBeforeMailSent=`returnCartReport` &gotoid=`46`!]
      Make sure to change the "46" to the ID of your thank you page. The "ContactForm" is the standard one included with the demon content, included for your convenience:
      <p class="error">[+validationmessage+]</p>
      
      <form method="post" action="[~[*id*]~]" id="EmailForm" name="EmailForm">
      
      	<fieldset>
      		<h3> Contact Form</h3>
      
      		<input name="formid" type="hidden" value="ContactForm" />
      
      		<label for="cfName">Your name:
      		<input tabindex="1" name="name" id="cfName" class="text" type="text" eform="Your Name::1:" /> </label>
      
      		<label for="cfEmail">Your Email Address:
      		<input tabindex="1" name="email" id="cfEmail" class="text" type="text" eform="Email Address:email:1" /> </label>
      
      		<label for="cfMessage">Message: 
      		<textarea tabindex="1" name="message" id="cfMessage" rows="4" cols="20" eform="Message:textarea:1"></textarea>
      		</label>
      
      		<label> </label><input type="submit" name="contact" id="cfContact" class="button" value="Send This Message" />
      
      	</fieldset>
      
      </form>
      The ContactFormReport is as follows:
      <p>This is a order sent by <b>[+name+]</b> using the feedback form on the website. The details of the order follow below:</p>
      
      Cart Contents:
      
      [+sss_cart+]
      
      <p>Name: [+name+]</p>
      <p>Email: [+email+]</p>
      <p>comments:<br />[+message+]</p>
      
      <p>You can use this link to reply: <a href="mailto:[+email+]?subject=RE: Your Order">[+email+]</a></p>


      I tried to recreate my steps from memory. Let me know if you run into trouble. Plus this likely could be made more efficient, but this is how I implemented back when it was implemented. Good luck.
        Jesse R.
        Consider trying something new and extraordinary.
        Illinois Wine

        Have you considered donating to MODx lately?
        Donate now. Every contribution helps.
        • 3758
        • 17 Posts
        Jesse, thanks for sharing your work on this.
        I tried to reconstruct the solution you described but ended up with two errors.

        I’ stuck with the problem that my add links are empty like this:
        http://domain.com/index.php?cartaction=add&cartitem=&carttoken=268479023
        So I thought there must be a problem reading the page which has the ditto call with the product list.
        I saw few post above you mentioning to replace the function "LoadProductsFromFile".
        But when I do that I receive an parse error
        [tt]
        PHP error debug
        Error: file_get_contents(http://domain.com/index.php?id=102) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503
        Error type/ Nr.: Warning - 2
        File: /homepages/22/d227248782/htdocs/domains/domain.com/assets/snippets/sss/FlatFileCart.php
        Line: 73
        Line 73 source: $contents = file_get_contents(PRODUCTS_FILE_PATH);
        [/tt]
        Any ideas what could be the problem?


        Another thing is that the "add link" is without the "?id=[~id~]" part after the index.php.
        Do I have to modify the links?


        Thanks!
        Boris
          • 14050
          • 788 Posts
          Ahh...I forgot that step.  You do need to edit the file.  Look at step 5 again as I uploaded the exact file that is working in my example.  Also, it looks like your error might be related to not having the proper PHP configuration to use fopen.  In the manager, please go to Reports->System Info...and where it says phpinfo() click "View".  What value is set for "allow_url_fopen"?
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 3378
            • 5 Posts
            I am new to MODx. I am not a techie. I always meet with some tech problem. These days, I am thinking about setting up a free shopping cart in fastcommerce. It has lots of features I like, especially for a non-techie.  I am also considering other ecommerce website to build my online business.
              • 4749
              • 623 Posts
              Yes, very interesting. It would be a fabulous addition to modx. Even making it a simple add-on would be great. I’ve had several clients that needed to sell one, two, or three items and adding a full blown shopping cart seemed silly. This seems like a viable solution.
                The MODx has you...
                Utah Web Design
                • 31943
                • 1 Posts
                I found a couple of great web sites using
                simple self totaling online forms instead
                of a cart.
                Here ae a couple of examples:
                http://www.fospace.com/FOSformexample63.htm
                http://www.elbowspace.com/FRHformexample103.htm

                Basically, the web form itself calculate totals,
                tax & shipping with each stroke of the keyboard.
                Compared to a shopping cart that transfers inforamtion
                back and forth between the server and the client
                everytime a product is selected, the web form page
                is sent only once. All product selections
                are made on the same web page and submitted when the
                shopping is complete.
                  • 14152
                  • 3 Posts
                  I still think the flat files concept wouldn’t scale well for larger e-commerce sites. anyone else?