Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

where can I add my own functions?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-09-2011, 10:13 PM
 
Kamran Khan Kamran Khan is offline
 

Newbie
  
Join Date: Mar 2011
Posts: 3
 

Default where can I add my own functions?

Hey Guys,

I'm kind of lost here.

I need to integrate the header and footer of a wordpress blog into x-cart and so far I have landed into a lot of problems despite succeeding.

So after two days I have given up and would really like someone to lead me into the right direction.

Firstly, where exactly am I supposed to add PHP codes that I can later on put into the templates inside my x-cart? I have no idea where to locate the file.

I decided to do all my coding inside smarty.php located in the main folder; and this worked, at first. However, I realised 12 hours later that this makes most things give out a 500 server error.

So, if I add this chunk of code:
Code:
define('WP_USE_THEMES', false); require('../wordpress/wp-load.php'); // TO GET THE WORDPRESS HEADER ob_start(); get_template_part( 'navigation' ); $wordpress_header = ob_get_contents(); ob_end_clean(); ob_start(); get_template_part( 'stylesheet' ); $wordpress_stylesheet = ob_get_contents(); ob_end_clean(); $smarty->assign('wordpress_header', $wordpress_header); $smarty->assign('wordpress_stylesheet', $wordpress_stylesheet);

upon calling {$wordpress_header} inside a tpl file, I get the right header, but most things break (by giving 500 internal server errors).

Is it because these extra things I need shouldn't be implemented inside smarty.php? And if not, where exactly should I do such coding for my website?

I'm using the 4.4.2 version of x-cart
__________________
4.2.4 pro
Reply With Quote
  #2  
Old 03-10-2011, 12:04 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: where can I add my own functions?

If you need to use your own functions, then you should make a new folder under /modules/ in the root dir. This will keep all your stuff in one place. I would do something like
/modules/wp_integration/
Then make your php file in there with your functions.

Then you can make an init.php file in there with your functions or to make it logical, you can make init.php and then include your funcs.php file from there. X-cart auto-loads any init.php in a module directory.

As for your internal errors, I'm fairly certain it's because of conflicting function names or session problems. Fixing the first is not good as it will pretty much render the application you changed unupgradable. Fixing the second is possible, but requires alot of work.

If all you need is a design from WP, then make it in x-cart. Integrating it is much harder. If you need certain elements, make some functions to work on the WP db. Doing a full-on integration is more than a 10 hour job.
__________________
- Shane Munroe
Reply With Quote

The following user thanks Shamun for this useful post:
gb2world (03-10-2011)
  #3  
Old 03-10-2011, 12:25 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: where can I add my own functions?

In addition to Shamun's excellent reply, check your server logs for the cause of the server errors. It may be something simple.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #4  
Old 03-10-2011, 01:39 PM
 
Kamran Khan Kamran Khan is offline
 

Newbie
  
Join Date: Mar 2011
Posts: 3
 

Default Re: where can I add my own functions?

Hey guys, thank you so much for your replies!

I don't want to do an entire integration (there is no way I would be able to anyway considering how much I'm hating even having to do this right now!)

I know I can just hard-code my wordpress header into x-cart but because of all the time I have spent trying to do this I really don't want to give up at this point.

Here is a simple question if you guys can help me figure out.

Imagine if I just have a separate php file, say wordpress.php inside my x-cart directory and have all my codes and functions in there, plus have everything stored inside variables, how will I be able to assign them to be used inside the smarty template engine?

Imagine if I have a php file with this code:
Code:
$content = 'lorem ipsum'; smarty->assign('content', $content);

how will I be able to use this within the template?

I already tried but failed (the template won't recognise anything) and would appreciate any kind of help from the geniuses who know their way around x-cart (this is my first time)
__________________
4.2.4 pro
Reply With Quote
  #5  
Old 03-10-2011, 01:50 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: where can I add my own functions?

You have to 'start' X-cart in each script.

The first thing you should have in your file, if in xcart root, is this:
Code:
require './auth.php';

Then you can use $smarty and other x-cart functions.
__________________
- Shane Munroe
Reply With Quote
  #6  
Old 03-11-2011, 10:20 AM
 
Kamran Khan Kamran Khan is offline
 

Newbie
  
Join Date: Mar 2011
Posts: 3
 

Default Re: where can I add my own functions?

I'm assuming there is more to be done than just that? It didn't do it.
__________________
4.2.4 pro
Reply With Quote
  #7  
Old 03-11-2011, 01:25 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: where can I add my own functions?

Code:
<?php // Start X-cart require './auth.php'; // Your code between this line // And this line $smarty->assign('main', 'SomethingHere'); $smarty->assign('location', $location); func_display('customer/home.tpl', $smarty); ?>
__________________
- Shane Munroe
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:35 AM.

   

 
X-Cart forums © 2001-2020