View Single Post
  #3  
Old 11-06-2014, 01:43 PM
 
drholmes drholmes is offline
 

Advanced Member
  
Join Date: Oct 2014
Posts: 84
 

Default Re: How to integrate X-Cart 5 with a CMS site: Tutorial

Thanks, Mike.

Here's the variation I talked about. Many people will have a CMS where they can't just break the page up into individual chunks in different HTML pages. Instead, they'll be able to put some comments into their CMS template, and then the following alternative pullCMSHeadContent() function will extract the part they marked:

Code:
public function pullCMSHeadContent() { $source = file_get_contents("http://www.example.com/blankpage.html"); $startMarker = "<!-- HEAD START -->"; $endMarker = "<!-- HEAD END -->"; $startPos = strpos($source, $startMarker); $endPos = strpos($source, $endMarker); if ($startPos === false || $endPos === false) return ''; $startMarkerLen = strlen($startMarker); $output = substr($source, $startPos + $startMarkerLen, ($endPos - $startPos) - $startMarkerLen); return $output; }

Then using CNN.com as an example, here's how you would modify your basic CMS template (the same template used for all pages in your CMS):

Code:
<link href="http://www.cnn.com/" rel="canonical"/> <link href="http://www.cnn.com/favicon.ie9.ico" rel="Shortcut Icon" type="image/x-icon"/> <link href="/tools/search/cnncom.xml" rel="search" title="CNN.com" type="application/opensearchdescription+xml"/> <!-- HEAD START --> <link href="/tools/search/cnncomvideo.xml" rel="search" title="CNN.com Video" type="application/opensearchdescription+xml"/> <link href="http://i.cdn.turner.com/cnn/.e/img/3.0/global/misc/apple-touch-icon.png" rel="apple-touch-icon" type="image/png"/> <link href="http://rss.cnn.com/rss/cnn_topstories.rss" rel="alternate" title="CNN - Top Stories [RSS]" type="application/rss+xml"/> <link href="http://rss.cnn.com/rss/cnn_latest.rss" rel="alternate" title="CNN - Recent Stories [RSS]" type="application/rss+xml"/> <!-- HEAD END --> <link href="http://edition.cnn.com" hreflang="en-gb" rel="alternate" title="CNN International" type="text/html"/> <link href="http://arabic.cnn.com" hreflang="ar" rel="alternate" title="CNN Arabic" type="text/html"/> <link href="http://mexico.cnn.com" hreflang="es" rel="alternate" title="CNN Mexico" type="text/html"/>

So you just put HTML comments into your main CMS template, and these parts get reused in X-Cart. If you make a blank page, and then insert this for your <head> content (exclude the <title> tag, it's better that X-Cart generates it, you mark another range for after <body> until the content, and the final range for after-content-until-</body>, then X-Cart gets wrapped into your site.

A little caveat, this adds CPU overhead. Especially because you're pulling the same page 3 times. Even if it's coming from a static cache, it's three times processing. It would be better to store it and use it three times. Or to only extract your segments one time and store them until the source has changed.

Anyway, these examples are very basic, I just feel that that's what we need in order to get a handle on the massive X-Cart structure. And they're just to show the principle as I imagine it. This isn't, and shouldn't be rocket science. I've just been stumped with the X-Cart documentation, which reads like a phone book, and there are bugs in the examples, so I've actually spent two days getting to this Hello World example.

But I have it running beautifully here. The rest of the stuff we do runs directly on the database, so I won't likely need to write any more modules. That's why I was trying to avoid getting a whole education in X-Cart development just to do this one thing

Best,

Per


Per
__________________
X-Cart Business 5.4.1.7, No third party modules, most modules disabled, zero modifications other than CSS.
Reply With Quote