X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   where can I add my own functions? (https://forum.x-cart.com/showthread.php?t=58409)

Kamran Khan 03-09-2011 10:13 PM

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

Shamun 03-10-2011 12:04 AM

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.

cherie 03-10-2011 12:25 PM

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.

Kamran Khan 03-10-2011 01:39 PM

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)

Shamun 03-10-2011 01:50 PM

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.

Kamran Khan 03-11-2011 10:20 AM

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.

Shamun 03-11-2011 01:25 PM

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);
?>



All times are GMT -8. The time now is 02:42 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.