How to integrate X-Cart 5 with a CMS site: Tutorial
Hi,
I've been struggling for a while to get content pulled from our CMS, and I finally worked it out. The X-Cart documentation leaves much to be desired, so I'm trying to post the tutorial I wish I had, so somebody else may save the time. This is a pretty hard-coded example because I have a specific problem to solve, and I'm trying not to have to become an expert on the entire X-Cart class structure just to do this thing. Two things would be worth it to do for this to be a more useful module for everyone:
CREATING THE MODULE Create a folder xcart/classes/XLite/Module/HCW/CMSContent <-- HCW is the name of our company, CMSContent is the name of the module. Inside that folder, create a file Main.php containing: Code:
<?php Nothing special here, this is the default blank module example from X-Cart's website. Next, create a folder View in your module folder (total path will be xcart/classes/XLite/Module/HCW/CMSContent/View). Inside that folder, we're creating 3 nearly identical files. I'll paste them first and explain afterwards: Create the file PullHeadContent.php: Code:
<?php Create the file PullBodyTopContent.php: Code:
<?php And finally, create the file PullBodyBottomContent.php: Code:
<?php What to notice:
The templates go inside the skin, so create the folder xcart/skins/default/en/modules/HCW/CMSContent/ (you're creating only the HCW/CMSContent folders, the rest are already there). Inside that, create 3 files: Create head.tpl (this is lowercase on purpose): Code:
{pullCMSHeadContent():h} Create bodytop.tpl: Code:
{pullCMSBodyTopContent():h} And finally, create bodybottom.tpl: Code:
{pullCMSBodyBottomContent():h} What to notice:
PRACTICAL PROBLEMS:
Per |
Re: How to integrate X-Cart 5 with a CMS site: Tutorial
Very nicely done sir. I'm sure this will help others.
|
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() 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"/> 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 |
All times are GMT -8. The time now is 12:53 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.