Zen Cart Logo
Forums / General Questions / Can't include catalog functions in seperate PHP file.

Can't include catalog functions in seperate PHP file.

Views: 4,010

Results 21 to 39 of 39
30 May 2011, 8:18 PM
#21
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Can't include catalog functions in seperate PHP file.

So you mean I should change the folder location?

30 May 2011, 10:02 PM
#22
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Can't include catalog functions in seperate PHP file.

Changing the folder location won't help as the only place from which your AJAX handler can invoke application_top will still be your admin's root folder.

31 May 2011, 9:46 PM
#23
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

I have resolved the issue by writing my own functions instead of using zen cart functions.

But here, i'm encountering a very serious problem with $_SESSION variables. In my root directory I set a session variable but when i try to access it on EZ pages i don't get that value rather I get 0.

How to resolve this issue?

31 May 2011, 9:51 PM
#24
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Can't include catalog functions in seperate PHP file.

Unless you're prepared to write your own version of Zen Cart's page and session initialisation routines, you resolve it by putting your ajax handler in the admin root folder and calling application_top to do the heavy lifting for you.

1 Jun 2011, 6:07 AM
#25
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

I don't understand what you mean by all this. Please explain in a different or easy way.

1 Jun 2011, 7:05 AM
#26
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Can't include catalog functions in seperate PHP file.

Any script that you want to run from outside Zen Cart but access resources from within Zen Cart ... requires that you load application_top.
If you don't do that, then you need to re-invent all the core logic that Zen Cart runs on ... essentially recreating your own framework.

So ... if you want to access Zen Cart resources, use application_top.

1 Jun 2011, 7:12 AM
#27
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Thanks for your suggestion, but i include application_top.php everything stops working in my application.

1 Jun 2011, 7:20 AM
#28
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Can't include catalog functions in seperate PHP file.

The two most likely reasons for this are:

  • that you are invoking application_top from a script that's not being run from your admin root folder, which will cause problems with the paths of some of the files to be loaded and/or
  • that you are loading separately files that application_top has already loaded causing duplicate function errors.

fawad123:

Please explain in a different or easy way.Sadly, this simply isn't that easy. It can get very technical, especially when ajaxing into the admin, as you have to also allow for the session expiring on you. PM me an email address and I'll send you some working code to look at.

1 Jun 2011, 7:24 AM
#29
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Your first point is correct. I'm loading application_top.php from different folder than admin but again the problem is if i copy that file to admin folder and include application_top.php and then give it AJAX call , it does not work. Otherwise it works fine.

1 Jun 2011, 7:25 AM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Can't include catalog functions in seperate PHP file.

And, as I said before, using PHP error_reporting can help you see what PHP errors your scripts are encountering.

1 Jun 2011, 7:55 AM
#31
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

OK I will use this function to extract error details.

1 Jun 2011, 8:27 AM
#32
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

I have used the following line of code:
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);

in my root folder PHP file when this file is access from EZ pages using AJAX call I don't see any error but AJAX does not work.

The EZ Pages block all PHP errors.

What should I do now?

1 Jun 2011, 8:33 AM
#33
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Can't include catalog functions in seperate PHP file.

Where are you looking for the errors? How do you know that the AJAX hasn't worked? Which step in the AJAX process isn't working?

1 Jun 2011, 8:38 AM
#34
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

I'm using Jquery for AJAX call.

The Success function or any other function like Error or Complete does not execute once I send the AJAX Call.

I'm using json_encode to get everything back on EZ pages on Zen cart. After including Application_top.php file nothing comes back through JSON_ENCODE, rather i receive 0 bytes.

1 Jun 2011, 9:36 AM
#35
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Can't include catalog functions in seperate PHP file.

All you're telling us is that you're not getting a response after triggering an ajax message. But you telling us anything about what steps you've taken to work out whether it's a problem with sending your message, or with receiving it on the server, or with handling the message or with preparing the response or with sending the response.

You do suggest that you're using json_encode to send the response, but that's not what json_encode does. It's function is merely to take a value (usually an array for AJAX) in UTF-8 format and return a string in json format. It doesn't send it anywhere.

The situation you find yourself in is normal when developing ajax, since by definition, much of the processing is hidden away. I find the Firebug console feature invaluable for exposing the messages to and from the server.

Errors on the server can be seen in your site's or your apache log files, and if they're not reported there, insert some dumps of your own and write them to your own log files (or echo or var_dump trace information and pick it up in the ajax response shown in the Firebug console).

However, the only person who can do all this is you, as it requires access to your server, and possibly your admin (though your later posts suggest that you're doing something on your EZ-Pages rather than in your admin, so maybe not), and specific knowledge of the code you're writing.

2 Jun 2011, 3:03 PM
#36
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Thank you so much for your detailed response. I will try to track the error and will inform you where the exact problem is.

Previously, I had enabled PHP reporting but no error was detected when AJAX stopped working after including application_top.php file.

I think Firebug is the right option at this time to track what the exact problem is?

I know you cant test what I'm trying to do but if you want I can paste the code here. Let me know if by pasting code here can give you better understanding of how I'm implementing AJAX. ?

2 Jun 2011, 4:21 PM
#37
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Thank you so much for all your effort.

BUT I HAVE JUST GIVEN UP !

I have tried everything but i don't know why php file is not sending response back to JS file when I include application_top.php file.

2 Jun 2011, 4:57 PM
#38
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

I have given one more attempt to this issue. The following code is tested:

myphp.php file:

<?php echo 'Testing module'; require('../includes/application_top.php'); echo 'Code after Application_top.php'; ?>

When I call this myphp.php file through AJAX I get only "Testing module" printed but no other message after application_top.php file is executed.
It shows that when require('../includes/application_top.php'); is executed it redirects somewhere else without giving any error therefore nothing after that line is executed. That is why I'm not getting any response from AJAX as soon as I include application_top.php file.

I hope now you can realize that there are some settings or some variables in application_top.phph which does not allow further execution of my php file.

Can you suggest any solution now?

6 Dec 2017, 6:59 PM
#39
s_thomas avatar

s_thomas

New Zenner

Join Date:
Oct 2015
Posts:
5
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

this is late I'm sure but this was my solution. I needed to add the chdir. With out that no matter if I put the full path or not it would not work

chdir('../../');
require_once('includes/application_top.php');