Cart-Lab Blog

X-Cart & E-commerce related news, resources and tips. Postings by: B00MER of Cart-Lab.com


Monday, May 23, 2005

Writing your own X-Cart modifications


<?php
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# X-Cart mod template by cart-lab.com
# A Basic PHP template for X-Cart 4.0.x
# Written 5/23/2005 9:07AM
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

/*
Require X-Cart functions & Categories if you are creating a new modification that is not included but rather called upon by the URI. These lines are mainly used when you are saving the php file in your /xcart, /admin or /provider directory as they all have the auth.php file that will include all of X-Cart's basic functions and basically initialize X-Cart.
*/ 
require "./auth.php";
require 
$xcart_dir."/include/categories.php";

/*
If your are including this code elsewhere and not from the URI then uncomment the below line and comment/remove the two require statements above as they will have already been included. This line of code will help keep those trying to access this php file via the URI, which will simply redirect them to the homepage.
*/
#if ( !defined('XCART_SESSION_START') ) { header("Location: ../../"); die("Access denied"); }

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# CONFIG
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

# Here is where we set any configuration variables the script may use
$hello "Hello,";
$world "World!";

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# START
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

# Insert your code here
$hello_world $hello." X-Cart ".$world;

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# END
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

# Send the variable to the Smarty class to be used in a .tpl
$smarty->assign("hello_world",$hello_world);

# This is the variable that will control what .tpl to reference in common_templates.tpl
$smarty->assign("main","hello_world");

# This function will start the display of the .tpl's
func_display("customer/home.tpl",$smarty);

/*
You'll add a new elseif condition in common_templates.tpl which looks for the variable $main to eq "hello_world" which will include the .tpl you specify in the elseif condition.  Below is the single line in my .tpl for this above example. (minus the # comment)
*/

# {$hello_world}

/*
Which will print "Hello, X-Cart World!";  Placing this line of code in X-Cart's main area of content (the middle) keeping the site structure, header, navigation side bars and footer.

There are also other methods when it comes to creating X-Cart mods, if you are somewhat familiar with Object oriented programming you can easily write ALL of your php and display code in your .tpl file with the {php}{/php} smarty tags.  You can easily access the $Smarty class and manipulate it as you see fit.

A good example to see how you can achieve this, paste the following code in one of your .tpl files:

{php}func_print_r($this->_tpl_vars);{/php}

Which will output a nested layout of the current template .tpl vars.

You can also use:

{php}func_print_r($GLOBALS);{/php}

To see EVERY variable available.  

NOTE: This method of creating mods is a bit more time consuming not to mention the code isn't as clean but it makes its alot easier if you are redistributing your mods to novices.

Happy X-Carting.
*/

?>


Cart-Lab.com: X-cart Resources, and More!

Blinkbits
co.mments
Delicious
digg
Furl it!
NewsVine
Reddit
Spurl
TailRank
DZone
Google Bookmarks
taggly
Windows Live Favorites
addtoany
technorati



0 Comments:

Post a Comment

<< Home