We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    I’m sorry to ask this on the "Core Code" section of the forum, but I almost spent 3 full days on a bug to which I cannot find any solution.

    It concerns this page: http://www.altipoint.ch/demo_product

    When I’m connected to the MODx manager, the cart works perfectly.
    When clicking the "Au panier" button, I get this picture:
    http://www.altipoint.ch/preview/copies_ecran_treasurechest/exemple_de_produit.png

    When not connnected, the cart does not work at all when clicking the "Au panier" button.

    Firebug reports a very strange error:
    missing } in XML expression
    [Break on this error] <style>TD, BODY { font-size: 11px; font-family:verdana; }</style>\n
    The error is detected in treasurechest.js (see code below), but from what I can see it is due to an jQuery Ajax request that fails, most probably the product count after one product was added to the cart.

    Are there restrictions in the MODx API when the user is not connected to the manager?

    As far as I can see, all PHP files have the correct permissions.
    Assuming that a file is in some subfolder, do all folders above it need to have the same permissions (e.g. EXEC)?

    The site is running on MODx 0.9.6.2.
    Is this a version-specific problem?

    On "localhost" the problem does not occur.

    Thanks for your help.

    The error is dectected at this line of treasurechest.js
    function cartCount(){$.ajax({async:false,url:cart_doc,data:{action:'count'},cache:false,success:function(a){cart_count=eval("("+a+")");if(cart_count.length){cart_string='<input type="button" id="cart_view_button" class="thickbox tc_view button large_text marine w85 h40" style="text-align:left" onclick="return false;" /><img alt="Affichage du panier détaillé" src="assets/snippets/treasure_chest/images/cart_icon.gif" style="float:left;position:relative;left:-27px;top:10px;" /><input id="cart_empty_button" type="button" style="text-align:left" /><img alt="Vider le panier" src="assets/snippets/treasure_chest/images/cart_icon.gif" style="float:left;position:relative;left:-27px;top:10px;" />';if(cart_el){$(cart_el).show().html(cart_string);}if(cart_view){if(document.getElementById("cart_view_button")){document.getElementById("cart_view_button").value=cart_view;document.getElementById("cart_view_button").title="cart_view";}}

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No, but when logged in to the Manager you do get the QuickManager plugin activated, which includes the jquery library for its own functions. You can either disable QM for the pages involved, disable it altogether if you don’t use it, or configure it to not load jquery in the front-end, and/or change the setting on whether or not it loads jquery in "no-conflict" mode in the front end.

      I would first simply disable the QM plugin, then get my cart working. After that, if you still want QM, then enable it and fiddle with its configuration. I’ve only had to disable it for a specified page once, when using a rather complicated JQuery plugin. If my site is going to use javascript a lot, I just configure QM to not load jquery and not use jquery in "no-conflict" mode in the front-end, load the jquery library myself in my template, and it usually works just fine.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 15001
        • 697 Posts
        Thanks. In my case QuickEdit was already disabled.
        (QuickEdit, not QM, as I’m using the 0.9.6.2 of MODx.)
        I assume the problem is due to some wrong file permission as all was working fine some time ago. So, I plan reinstalling MODx.
          • 15001
          • 697 Posts
          As what fails is Ajax-related stuff, I should maybe look at this:
          http://wiki.modxcms.com/index.php/Use_AJAX_with_modxAPI

          Does anyone know if using Ajax with the MODx API works without following above procedure when connected to the MODx backend ?
          This would explain the problem.
            • 15001
            • 697 Posts
            To summarize, my page makes Ajax request through jQuery.
            The request fails when I’m not connected to the MODx backend.

            [table]
            [tr][td] [/td][td]Connected to MODx backend[/td][td]Not connected to backend[/td][/tr]
            [tr][td]localhost[/td][td]success[/td][td]success[/td][/tr]
            [tr][td]remote host[/td][td]success[/td][td]fails[/td][/tr]
            [/table]

            I tried including the config file at the beginnig of the snippet, but it still does not work.

               // define('MODX_MANAGER_PATH', $modx->config['base_path'].'/manager/');//relative path for manager folder
                require_once $modx->config['base_path'].'/manager/includes/config.inc.php';  //config
                require_once $modx->config['base_path'].'/assets/snippets/treasure_chest/treasurechest.class.php';


            I assume that when not connected some session variables lack and I have not access to the full API.

            Can some guru tell what changes a connection the MODx manager is established?

            Thanks a lot for your help.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The Manager includes a plugin "QuickManager" which load the main jquery library in the front-end. If you aren’t logged in, then no QuickManager and no jquery library. There are a number of ways to solve the issue; I tend to use a snippet that checks for a logged-in manager user and if there isn’t one then use $modx->regClientStartupScript() to insert the tags for loading the jquery library file in the head.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 15001
                • 697 Posts
                For the 0.9.6 version, the plugin is Quick Edit. Quick Manager comes for newer versions.

                jQuery is loaded in my case. (I also use regClientStartupScript when necessary.)

                For the problematic page, the HTML code is 100% identical if I’m connected or not to the MODx manager. (This was checked by copy-pasting the codes in two files that were then compared with PSPad.) But the behaviour is different.

                I observe that the PHP files in "manager/processors" and "manager/action" have "644" file permission, i.e. are read-only for users other than the owner. This could explain the difference. What should the permissions be for the PHP files in those folders ?


                  • 15001
                  • 697 Posts
                  I still cannot make it work after 4 days!
                  All works perfectly only when I’m connected to the MODx backend.

                  I assume the problem is due to restrictions when using the MODx api from a snippet making Ajax requests.

                  Maybe the problems comes from something like this
                  http://modxcms.com/forums/index.php?topic=44188.0

                  I also found this thread interesting (it’s in French)
                  http://modxcms.com/forums/index.php?topic=25266.0

                  I tried adding this in my snippet, and even in the class defifinition:
                  define('MODX_API_MODE', true);
                  include('index.php')

                  but it did not help. Maybe I inserted this at the wrong location...

                  Did someone experience problems with ajax when not connected to the backend?










                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    No, I use MODx resources with no template only a snippet in its content. That snippet contains my processor. MODx does not in any way prevent the API from being used from the front-end or the back-end. Check your "view source" and make sure all the required javascript libraries are being loaded.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 15001
                      • 697 Posts
                      Thanks for your continuous help.
                      I could go much forward in the debugging and identify that one method of TreasureChest cannot connect a database table when I’m disconnected from the MODx manager.

                      A new thread was created to explain what happens.
                      http://modxcms.com/forums/index.php/topic,50705.0.html

                      More code samples of what happens in this particular case are also given in this thread (in French): http://modxcms.com/forums/index.php/topic,50705.0.html