We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1535
    • 84 Posts
    Hi.

    I am currently working on integrating some elements from OsCommerce into a MODx frontend. My immediate need is product listings and other simple stuff. Maybe some cart functions later.

    I am building a snippet based on a XML database query contribution for OsCommerce.

    There are multiple includes involved, and it was pretty hard getting the link up, but I think I got it now.

    I got the database stuff working and can pull stuff from the OsC database using standard OsC calls, so the OsC backbone is running ok.

    The problem is, whenever I try to return anything from the snippet, I get a blank page.

    I know the code is working, because if I terminate the snippet with exit; right after echoing my variable I get a full XML dump of the resultset on screen.

    It seems to me that something is preventing a proper return to the MODx environment after the OsC code has run.

    If someone could give me a pointer in the right direction, maybe we could get this thing working.

    Cheers,

    Andreas
      • 1535
      • 84 Posts
      Anyone got any hints for me on this, please?

      I feel really close to a working solution, think I just need a little help to return properly to MODx environment, or if that is not the issue, figuring out why I get a blank screen upon returning from the snippet.

      I can post more details if needed.

      Cheers,

      Andreas
      • Not sure, without looking at osC code, but you’ll likely need to capture any output from your includes in an output buffer. See http://modxcms.com/forums/index.php/topic,672.msg3883.html#msg3883 for an example.
          • 1535
          • 84 Posts
          Thanks OpenGeek.

          I am not sure, but I don’t think that would help me as the OsC code isn’t producing any direct output. It all goes into a variable.

          I needed to use the set_include_path in the snippet this to get the OsC include files to find their own includes, maybe that’s the problem:

          Here is an excerpt of the snippet:

          set_include_path(get_include_path() . PATH_SEPARATOR . realpath("../oscdir"));
          include (’includes/application_top.php’);
          include (’includes/crex.php’);
          $crex_xml_doctype = ’<?xml version="1.0" encoding="UTF-8"?>’;
          $crex_xml_output = ’’;
          etc...
          ...
          code to query the database and parse the result into an XML array, filling up the $crex_xml_output variable.
          ...

          I end the snippet with this:

          include (’includes/crex_application_bottom.php’);
          $out=$crex_xml_doctype.$crex_xml_output.’\n\n’;
          return $out;

          It is so strange, the $out variable contains everything I need and the OsC code has done it’s job, but I can’t return it to MODx without getting a blank screen.

          Cheers,

          Andreas
          • If you change the include_path, you’ll kill MODx. Try setting it back to the previous value before returning from the snippet.
              • 1535
              • 84 Posts
              Thanks, OpenGeek.

              I tried that, but it didn’t have any apparent effect.

              In any case, I only append to the include path, I don’t remove anything from it.

              I will try some more around this, though. Thanks for the input.

              Cheers,

              Andreas
                • 1535
                • 84 Posts
                Got it!

                I had to make a new application_top.php file that strips out everything but the bare necessities of OsC and I now can display my data in MODx.

                I got some further testing to do, but if there is interest I can post the code.

                Thanks for the help.

                Cheers,

                Andreas
                  • 26179
                  • 21 Posts
                  AndreasT, I’m very interested !
                  I was thinking on how to do this work and searching the forum I found this post!

                  Please post the code, or send it in pm
                  Thanks.
                  Sara
                    • 29181
                    • 480 Posts
                    Yes, it sounds interesting. If it can be done with osCommerce, it probably isn’t too difficult beat up into working with xt:commerce.

                    So you are still using the osCommerce backend, and just porting the output into a ModX template?

                    All the best,
                    Taff
                      Adrian Lawley: www.adrianlawley.com
                      • 1535
                      • 84 Posts
                      Hi Sara.

                      OK, I’ll try to explain, but this was very hard to do, much because I am still very new to MODx and have probably not done things the ’right’ way, and certainly not the most efficient way.
                      But it works, and I needed it in a hurry. I will do some work later and try to optimize some of the code when I add cart and customer functions.

                      I have only used the category/product functions, the contribution offer much more which I have not tested yet.

                      First you need the XML contribution for OsC:

                      CREX - OSCommerce XML
                      http://www.oscommerce.com/community/contributions,5198

                      Support for the contribution is here:
                      http://forums.oscommerce.com/index.php?showtopic=266505

                      There are some bugs in the code, so check out the forum before you start, if you don’t use my versions.
                      My versions include a few bugfixes, some expanded functions and some UTF8 cleaning of the OsC data among other stuff.

                      First you need to get this working using the crex_read.php script before you delve into MODx.

                      Then you need to make the crex_read.php into a MODx snippet, more or less.

                      I also made a snippet parsing out the XML data into either tables or unordered lists, depending on what I need for the various functions.

                      I wanted the categories to be hard coded in MODx so that I could have a static "header" page for each category, but I wanted dynamic subcategories and products. The subcategories are returned as lists, while the product listing is a table.

                      I use TV’s to send the category and product parameters to the snippet.

                      I include all the code I have on this, some of it is not very pretty, although working.

                      A few hints:

                      You need to set register_globals to ON. ( I know, it’s a bad idea, but OsC requires it in this version)

                      I use a fixed value TV in my static category pages in a call to the get_subcategories function.
                      A left container uses chunks to show the expanded subcategories under each category after they are clicked.

                      I had issues with double calls to OsC, which I could not resolve by other means than using a session variable to hold temporary results, in my case I chose to store the returned subcategories in a session variable. This does restrict direct linking to product listings, as the session will not be set and the query will return null and an empty listing. I made a workaround for that with a message saying that direct linking was not possible.

                      If you find a way to control two calls to OsC on the same page, it would be great. I didn’t have the time to pursue it.

                      Dataflow:

                      Category pages

                      I have static category pages as I said, I only have 6 or 7 so it’s ok. They are all containers.

                      The main content is a general description of the category, all in MODx.

                      The following TV’s are used:

                      OsC_Cpath: Any valid OsC category value, such as 20
                      OsC_Command: get_subcategories



                      Subcategories

                      The subcategories/product listing page is a child page for each Category page, not so efficient, but there you have it.

                      In my subcategory pages I use a placeholder as the Description: [+catname+]
                      (I use the same Title as the main category static page.)

                      The main content is just a snippet call: [!OsC!]
                      This returns the products in the given subcategory as a table

                      The following TV’s are used:

                      OsC_Cpath: @EVAL $up_Params; return $modx->runSnippet(’OsC_get_cpath’,$up_Params);
                      OsC_Command: get_category_products_ext


                      Chunks

                      I use one chunk for the leftcontent (categories) for each category, basically they are all the same, just differing on the category to expand. Again, very inefficient. Feel free to improve on it.

                      <dl class="nav3-grid">
                      <dt ><a href="[~95~]"> Category x </a></dt>
                      <dd>[!OsC_categories_select!]</dd>
                      
                      <dt><a href="[~88~]"> Category x </a></dt>
                      
                      <dt><a href="[~89~]"> Category x </a></dt>
                      
                      <dt><a href="[~90~]"> Category x </a></dt>
                      
                      <dt><a href="[~91~]"> Category x </a></dt>
                      
                      <dt><a href="[~109~]"> Category x </a></dt>
                      
                      <dt><a href="[~92~]"> Category x </a></dt>
                      
                      <dt><a href="[~94~]"> Category x </a></dt>
                      
                      <dt><a href="[~93~]"> Category x </a></dt>
                      
                      <dt><a href="[~99~]"> Category x </a></dt>
                      



                      I also use a snippet called thumbs for the images, it’s in the repository.

                      Some of the text in the code are in Norwegian, but those are just labels. Should not be a problem, but let me know if you need them translated.

                      I think that is all of it, the snippets and my version of the contribution are in the zip file.

                      Good luck.

                      Cheers,

                      Andreas