This article has been written to explain how a custom section or page can be added to the front end of CubeCart. For example you may want to add a dynamic page for a feature CubeCart doesn't currently support such as a wishlist or store news.
Before going any further we would suggest getting an understanding of the Hooks system used by CubeCart in this article.
CubeCart has a number of contoller files that use URL values to determine what content to show. With Search Engine Optimisation turned off you may see these in the URL with the GET variable "_a". For example if the value of "_a" is "product" CubeCart will load the product detail page. "basket" would load the carts vew/edit basket page.
Lets say that we wanted to create a news section and intend to set the GET variable "_a" with the value of "news". In our browser the URL will look something like:
http://www.example.com/store/index.php?_a=news
With this attribute in place CubeCart will take the following directions to find the location of source code it needs.
1. index.php loads the encoded index_*_enc_*.php file
2. the encoded file will load the controller file controllers/controller.index.inc.php
3. the controller file loads up the required classes, functions and libraries required to operate the store.
4. this controller file initilizes the CubeCart class method "loadPage" with the code $GLOBALS['cubecart']->loadPage(); from the classes/cubecart.class.php file.
5. this method take the value of "_a" (if "_g" is not set) and performs a switch to see if there are any matches for it to work from. If there are not the default section of the switch is executed with the following code:
$method = '_'.strtolower($_GET['_a']);
// CubeCart will auto load any class in the classes folder. Please use the method below to
// load a function from the class. e.g. widget.class.php
if (method_exists($this, $method)) {
$this->{$method}();
}
// and/or you can use code from a hook in the plugins folder.
foreach ($GLOBALS['hooks']->load('class.cubecart.construct') as $hook) include $hook;
From this block of code we have two methods of getting our code into CubeCart. Whichever you choose it totally up to you however method 2 bypasses the need for whole plugin to be created.
Method 1 - from a plugin:
Assuming that you have read and understood the hooks documentation we can see that a hook can now be used to create your page data and load any custom template files you may wish to from your plugins folder.
Method 2 - from a single class file:
Alternatively it is possible to create a custom class for your code in the classes folder with the same name as the value of the GET variable "_a". For example "classes/news.class.php". If this class exists and the method within the class has been initiated it is possible to work this way. CubeCart has a class autoloader system in that it will automatically load any class file in the classes folder with the naming convention *.class.php.
Comments
0 comments
Please sign in to leave a comment.