We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    I'm trying to add a third party shopping cart system that I've installed many times on other, non-MODx sites (or any CMS sites) with excellent results. All of these sites, however, were static sites and the install was quite straight-forward. Mostly, copy/pasting of certain includes into my pages and that's it. Always worked great. The third-party shopping cart system by the way is called ecommerce templates.

    This, though, is my first attempt at installing it through MODx.

    The cart's files are located in a directory called 'shop'.

    If I was installing the main products page, for instance in a static page, all I would normally need to do is copy/paste the following code before the opening doctype tag:

    <?php
    session_cache_limiter('none');
    session_start();
    ob_start();
    ?>


    And then, in the body somewhere, I would add this bit of code:

    <?php include "shop/vsadmin/db_conn_open.php" ?>
    <?php include "shop/vsadmin/inc/languagefile.php" ?>
    <?php include "shop/vsadmin/includes.php" ?>
    <?php include "shop/vsadmin/inc/incfunctions.php" ?>
    <?php include "shop/vsadmin/inc/incproducts.php" ?>


    Other pages would have most of the same code above, except for the last line, which would be different, including the files to make that page do what it needs to do (product page, as apposed to category page, apposed to product details page, etc.)

    Usually works like a charm. But, I'm using MODx Revo now...

    Obviously, placing the above code directly in a template or chunk doesn't work. So, I try placing each one in its own snippet but the snippet keeps stripping off each ending php tag. I even tried to cheat the system by placing my own ending php tag directly in the template, after each snippet call but that didn't work, either (don't laugh...it was worth a try).

    I also tried changing each include to look like this:

    <?php
    include($modx->config['base_path'].'shop/vsadmin/db_conn_open.php');


    ...but that didn't help. Actually, what ends up happening is that the page times out and dies, giving me an error message that looks like this:

    Fatal error: Maximum execution time of 30 seconds exceeded in /home/"username"/domains/domain.com/public_html/shop/vsadmin/inc/incfunctions.php on line 286

    No doubt you'll need more information from me than I know to provide. But, any help is appreciated.

    Revo 2.1.3
    PHP Version 5.2.10

    Thanks in advance.
      • 3749
      • 24,544 Posts
      I think this might work in one or more snippets:

      <?php 
      $output = include "shop/vsadmin/db_conn_open.php";
      $output .= include "shop/vsadmin/inc/languagefile.php";
      $output .= include "shop/vsadmin/includes.php";
      $output .= include "shop/vsadmin/inc/incfunctions.php";
      $output .= include "shop/vsadmin/inc/incproducts.php";
      return $output;


      You might need to use the full path to each file (or prepend the base path).

      You could make the snippet more generic by sending a comma-separated list of files to include as a property to the snippet and just looping through them.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 31902
        • 342 Posts
        Thank you, Bob, for responding. Your suggestion, at least, stopped the system from timing out and dying but is still resulting in a blank content, where I should be seeing products. But, hopefully, it is a step in the right direction.

        Some things to note and things I've done:

        1. In troubleshooting, I noticed that the page containing the cart code wants to be in the same directory as the rest of the base files of the shopping cart. In other words, it doesn't seem to like just referring to pages in another directory (in the above case, the other directory being 'shop'). I tested this by creating a static test page and running it, first in the same directory as the cart and then in the same directory as MODx. The static test page in the same directory worked but the one in the base level didn't.

        Okay, so I reinstalled the cart in the main level, as I usually do. I don't have a problem with that.

        2. The cart, according to the instructions, really needs to have the code on pages that have a php suffix. So, I made sure the site is using FURLs and created a content type of php and set the page to run that content type. The page comes up with that suffix okay att.

        3. Testing the page, it still comes up with the product area blank. So, below is my setup so far:

        The template (called Shopping Cart) used on the resource looks like this:

        [[session_cache_limiter]]
        [[$head]]
        </head>
        
        <body>
        <div id="wrapper">
        
        <div id="header">
        </div><!--header -->
        <div id="navigation">
        [[$navigation]]
        </div><!--navigation -->
        
        <div id="content">
        
        <div id="left_column">
        <p>left column stuff</p>
        </div><!--left_column -->
        
        <div id="main_column">
        <h1>[[*longtitle]]</h1>
        [[*content]]
        [[cart_test]]
        </div><!--main_column -->
        
        </div><!--content -->
        
        [[$footer]]
        
        
        </div><!--wrapper -->
        </body>
        </html>


        Out of the above code, please note two snippets: the top of the page is a snippet called session_cache_limiter. This contains some code that each cart page needs added to the top of the page (according to instructions). In this snippet is the following code:

        <?php
        session_cache_limiter('none');
        session_start();
        ob_start();


        In the static page version, there would be a closing php tag at the end of it. The snippet strips that off here.

        Lower down in the template, under the content, is a snippet call called cart_test. Inside this snippet lives your suggestion:

        <?php
        $output = include "http://www.domain.com/vsadmin/db_conn_open.php";
        $output .= include "http://www.domain.com/vsadmin/inc/languagefile.php";
        $output .= include "http://www.domain.com/vsadmin/includes.php";
        $output .= include "http://www.domain.com/vsadmin/inc/incfunctions.php";
        $output .= include "http://www.domain.com/vsadmin/inc/incproducts.php";
        return $output;


        ...although I made them absolute.

        I think I got everything. Can anyone spot anything?

        Again, thanks in advance. [ed. note: waizen last edited this post 14 years, 11 months ago.]
          • 31902
          • 342 Posts
          Please note: This forum is taking it upon itself to change/add to some of my displayed code above. The contents of the snippet called cart_test above is showing code with 'a href' code added. In my code, it would only have the absolute address (appearing only once each), starting with 'http'. And, no 'rel="nofollow" or target="_blank" or %22.

          Just the absolute address in between double-quotes.
            • 3749
            • 24,544 Posts
            I wonder if your first snippet is interfering with MODX's built-in session and ob handling.

            You might try eliminating it or changing it to just:

            <?php
            session_cache_limiter('nocache');


            AFAIK, 'none' is not a valid argument for session_cache_limiter (though I believe session_cache_limiter(false) -- with no quotes -- will work).
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 31902
              • 342 Posts
              Again, thanks for your quick response. However, still nothing.

              I tried the code you posted above, then the code with false (no quotes) and finally with no code at all...nothing.

              Just for my FYI, why is it that snippets within MODx do not accept closing php tags? Not sure if that's what is causing the problems here but it makes me wonder.
                • 3749
                • 24,544 Posts
                I've never tried to do what you're doing, so I'm afraid I don't know why it wouldn't work. It depends on the code in those files. You might try changing "include" to "require" -- that might show you whether it's finding the files and where it's looking for them.

                The final PHP tag is stripped because it's unnecessary and MODX handles moving in and out of PHP internally. In fact, if the files are indeed being found, you might try removing any final PHP tags in those files.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting