Forums / General Questions / Programming php in Zen Cart

Programming php in Zen Cart

Locked

Views: 2,078

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
31 Aug 2009, 2:07 PM
#1
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Programming php in Zen Cart

Hi Folks.

Was hoping someone could answer a couple of programming questions for me. I see a lot of really knowledgeable people here in the forums, doing all kinds of customization and mods, and I'm hoping I can learn this as well.

I am reading through the developers API tutorial which is helping a great deal. I also found a "Zen Cart Program Flow (v1.3 series)" chart somewhere in this forum. Here are 2 things I am kind of stuck on. Any help would greatly be appreciated.

First question: Am I correct in assuming that each time I visit a page within my cart, ALL of the steps in the "Zen Cart Program Flow" get executed? Seems to me that some of the initial stuff like the InitSystem calls would only need to be executed once at the start of the session, but the flow chart doesn't make that clear... at least that I can see. Maybe I'm missing it. So is there a place in the program flow that represents a point when a user changes to a new page, or does this entire flow happen each time a new page is visited. The last event leads me to believe that it happens every time since it says, "causing actual output to the browser." Need some clarification on this, please.

Second question... When a particular class is instantiated, does that class remain instantiated for the entire users session, or does each class get instantiated over and over again as the program flow progresses. Perhaps the answer to the above question will answer this question for me.

OK, that's all for now. Thanks a bunch for taking the time to look at this post and providing some guidance. Really appreciate all the contributions in this forum.

And just so I'm not out of line with the posting guidelines here. I am using ZenCart 1.3.8a fully upgraded and patched to the most recent level. The only add-on I'm using at the moment is the Image Handler2. Site is a basic vanilla install of ZC with some Admin customization. Site = https://www.bryia.com. Yes, I've been reading the FAQ's and the forum for months.

Thanks again folks.
Bruhn

31 Aug 2009, 2:21 PM
#2
kuroi avatar

kuroi

Totally Zenned

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

Re: Programming php in Zen Cart

I think you're misunderstanding slightly how PHP works. Each page is built independently of the previous one linked only by a relatively small number of global variables such as the $_SESSION which persists for the session and $_GET & $_POST which can be used to pass data forward into the present page only.

So most of the initialisation needs to be done for each page (though some bits are grabbed back from $_SESSION where they persist) and no, classes don't remain instantiated for the whole session and need instead to be instantiated each time a page is built.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

31 Aug 2009, 3:28 PM
#3
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Re: Programming php in Zen Cart

Thank You. That answers my question. And that was totally opposite of what I was thinking. Yes, I do need to brush up on my php skills. I'm reviewing the docs on php.net as well as the Zen Cart specific stuff. I done some C++, C# and Perl, but this whole concept of php and how it integrates with www pages is making me rethink some of the things I've learned.

One last thing and then I'll continue my reading. I'm trying to identify the entry point for each page that I click. Not sure if that is going to make sense or is even the proper terminology.

Let me rephrase... I go to my site and index.php runs. I understand that much so far. It loads all of the external php pages that are a result of the auto_loaders, etc. Now I click on another link on my page, let's say... shipping. How do I know how to trace the path of what is being run. Do I just start at the top of the Zen Cart Flow chart and substitute the shipping.php page for index.php. I know this is getting into some really deep concepts here and if it's not something that can be answered in the forums, I understand. I'll keep reading.

Thanks for your help.
Bruhn

31 Aug 2009, 3:40 PM
#4
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,668
Plugin Contributions:
0

Re: Programming php in Zen Cart

What are you trying to do as the result? Zen Cart is really pretty easy to work with and you shouldn't have to go digging around in the code to do most things ...

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

31 Aug 2009, 5:33 PM
#5
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Re: Programming php in Zen Cart

Here is what I am trying to do. I have 4 top categories on my site. ie: Men's, Women's, Boys, Girls. Within each of these categories, I have sub-categories. Shirts, Pants, Shoes, etc. When someone is on my main page and then clicks the Womens top category, for instance, I would like for ZC to display all items within all of the Womens sub-categories until they click on one of the sub-categories.

I found several posts out here, that seemed to apply. This one: http://www.zen-cart.com/forum/showthread.php?t=100555 seemed to be the most applicable and there were 3 different zip files within this post, all appeared to be some variation on this theme. But when I tried to apply any one of these mods, for some reason, they didn't do anything. I noticed that most times people had to do some tweaking.

So, to answer your question, I'm trying to learn how all this stuff works and ties together so I can debug a mod when it doesn't work instead of just posting something like, "Mod doesn't work for me, please help." And hopefully someday create my own mods and add-ons.

Bruhn

31 Aug 2009, 5:42 PM
#6
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,668
Plugin Contributions:
0

Re: Programming php in Zen Cart

I would like for ZC to display all items within all of the Womens sub-categories until they click on one of the sub-categories.

This is a very unintuitive way to navigate, why would you want to confuse your customers?

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

31 Aug 2009, 5:43 PM
#7
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Re: Programming php in Zen Cart

One other thing I just thought of that I'm trying to do.... I modified the Greeting line on the main page to say something like click here to login or create an account. Problem is.... once a user logs in, the greeting on the main page still says, click here to login. I need to figure out where to put some logic code that figures out if a user has logged in and then displays another message on that line. Don't want to say "login" if they are already logged in.

31 Aug 2009, 5:44 PM
#8
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,668
Plugin Contributions:
0

Re: Programming php in Zen Cart

One other thing I just thought of that I'm trying to do.... I modified the Greeting line on the main page to say something like click here to login or create an account. Problem is.... once a user logs in, the greeting on the main page still says, click here to login. I need to figure out where to put some logic code that figures out if a user has logged in and then displays another message on that line. Don't want to say "login" if they are already logged in.

That is already built in - if it is not working then you have broken something.

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

31 Aug 2009, 5:55 PM
#9
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Re: Programming php in Zen Cart

Kim:

That is already built in - if it is not working then you have broken something.

So if I broke something, that goes right back to your first question as to what I am trying to accomplish. I am trying to learn how to program ZC.

I am not an expert at this as you appear to be. I am learning. I might make some poor decision on how to set things up or how to implement site navigation, but at this point, I am learning.

Hope it's OK to be a novice and want to learn in this forum.

31 Aug 2009, 6:17 PM
#10
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,668
Plugin Contributions:
0

Re: Programming php in Zen Cart

May I suggest that you play with a stock installation for a while and learn the built in capabilities before attempting to change the default behavior? Zen Cart is designed to be very easy to manipulate without having to do any programming.

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

31 Aug 2009, 6:23 PM
#11
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,844
Plugin Contributions:
17

Re: Programming php in Zen Cart

Think of this more like a car. You're wanting to dissect the firing order of the cylinders and maybe turn the engine ninety degrees in the mounts.

Zen Cart is an e-commerce engine that will run without being touched. You just need to decide on body style and color (stylesheet). Next, design your interior (admin menus and the occasional php edit) for those leather seats and plush headliner.

No need to become a mechanical engineer (php guru):yes:

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

31 Aug 2009, 6:31 PM
#12
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Re: Programming php in Zen Cart

Thanks dbltoe. Yes, I know I'm probably digging in too deep. Just trying to familiarize myself with all the inner workings. Anyway... thanks again for something constructive.

31 Aug 2009, 7:12 PM
#13
kuroi avatar

kuroi

Totally Zenned

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

Re: Programming php in Zen Cart

Nothing wrong with wanting to understand how it works. This is open source.

Kim's right though, get to understand what's available functionally before trying to work out how that's achieved.

Also, when you want to understand how it works, start from the other end. Look at the templates and then work backwards to see where the information that they output is coming from. It sounds counter-intuitive, but you'll find it much easier to approach it from that direction.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

31 Aug 2009, 7:46 PM
#14
bruhnf avatar

bruhnf

New Zenner

Join Date:
Jan 2009
Location:
Baltimore, MD
Posts:
21
Plugin Contributions:
0

Re: Programming php in Zen Cart

kuroi:

Nothing wrong with wanting to understand how it works. This is open source.

Thank you. I was beginning to feel like I wasn't supposed to even try to understand this, let alone ask any questions.

kuroi:

Also, when you want to understand how it works, start from the other end. Look at the templates and then work backwards to see where the information that they output is coming from. It sounds counter-intuitive, but you'll find it much easier to approach it from that direction.

Got it! I understand and thanks for your help earlier today. Much appreciated!

Bruhn