Jump to content
Sign in to follow this  
ztwistbooks

How do I write a module?

Recommended Posts

This is pretty basic, but I've looked all over, but I can't find instructions on how to write a module for OSCommerce.

 

I need a new shipping module. The existing ones don't do what I need. Where do I find directions on how to write a module?

 

I could go through all the PHP code and figure it out, but it would be much faster if the structure is all explained somewhere. Plus, I would know that I'm doing it right.

 

Does anyone have a pointer to any kind of documentation? Tutorial? Anything?

Share this post


Link to post
Share on other sites

Dan,

 

The basics, you need to know PHP very well, or atleast be able to hack up an existing module to suite you needs. You can use an existing module as a template to create your own.

 

 

But, I don't think there is a 'HOW TO' guide for creating modules because they all vary depending on your needs.

 

You can find PHP references at www.w3schools.com

 

Chris


:|: Was this post helpful ? Click the LIKE THIS button :|:

 

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

Share this post


Link to post
Share on other sites

While I don't know PHP, I've done a lot of programming, and it looks a lot like perl, so I can figure that out without difficulty. What I need to know is the general structure of a module and the store as a whole...how all the parts work with each other. Yeah, I could wade through all the code and figure it out, but that's slow and error-prone.

 

In short, I want to provide media mail as free shipping. If the customer selects USPS priority mail, they should only have to pay the difference in price between media mail and priority mail. So...

 

I want to write a new module for the discounted priority mail shipping. It should use (presumably existing) modules to calculate the media mail and priority mail prices, and subtract one from the other. This leaves a lot of questions:

 

How do I use an existing shipping module to extract the price? It seems like there would have to be a function in a standard format for this....

 

What interface functions does the shipping module class have to provide? What is their format? What are their purposes? When do they get called?

 

How does the Web site know it's there?

 

I might have to set up some database tables to hold things like shipping prices for various weights and distances. Is there a standard format for doing that? I'll need to change them as prices change. What's the right way to set up a configuration interface in the admin section to manipulate these tables?

 

Other than the main class, these modules invariably have the modification of lots of other files for the Web store. Why can't it all go in the module? Some of them seem to add general-purpose functions to the PHP libraries...why not include them in the module?

 

Etcetera, etcetera. There's a lot to figure out....

 

OSCommerce has been around a long time. I'm hoping someone who has written modules has explained how to do that.

Share this post


Link to post
Share on other sites

OSCommerce has been around a long time. I'm hoping someone who has written modules has explained how to do that.

Christian Lescuyer (who has been a team member of osC) made a contribution that explains that a long time ago (contribution 37): Documentation for shipping modules.

Share this post


Link to post
Share on other sites

There are no such general instructions that I am aware of. There is no API for custom modules to hook into. Addons don't necessarily work with each other. Logic and display functions are mixed within the same files. etc etc

 

You just have to wade in, learn the structure of osc and how it all fits together by reading the code, browsing directories, inspecting functions and classes, seeing which other files are required within a script and reading them too etc.

 

You don't need to worry about getting things wrong or breaking things if you back up a script before you change it. If it works then the change might be right, as long as it didn't break anything else or introduce a vulnerability.

 

Before trying to write a new module best is to search existing addons to see if there's one that does what you want, or is maybe close to doing what you want that could be modified rather than writing one from scratch. It should also give you an idea of the code changes needed, which files will be affected etc.

 

As Chris says, if you want to work on a new shipping template you can start by looking at an existing one and using it as a template - and the documentation refered to by Jan :)

Edited by Ben Nevis

www.jyoshna.com. Currently using OsC with STS, Super Download Store, Categories Descriptons, Manufacturers Description, Individual Item Status, Infopages unlimited, Product Sort, Osplayer with flashmp3player, Product Tabs 2.1 with WebFx Tabpane and other bits and pieces including some I made myself. Many thanks to all whose contributions I have used!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×