Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How do I write a module?


ztwistbooks

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?

Link to comment
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

Link to comment
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.

Link to comment
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!

Link to comment
Share on other sites

  • 13 years later...
On 1/10/2010 at 9:07 AM, ztwistbooks said:

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.

Everything can be found on the Internet

Link to comment
Share on other sites

  • 2 weeks later...
On 1/10/2010 at 6:54 AM, Guest said:

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

thanks 👽

Link to comment
Share on other sites

On 1/10/2010 at 10:46 AM, Ben Nevis said:

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 :)
A good module is a module that solves a specific problem and does it right. It should be easy to understand and easy to use by other developers. It is important to write clear documentation so that it is clear what the module does and how to use it. I remember that I found free essay examples to make it easier, I used https://phdessay.com/free-essay-examples/ for this. In addition, the module must be tested to ensure correct operation. Keep in mind that the module may be extensible in the future, so try to make it as flexible and versatile as possible.

agree with this

Edited by kamekosabad
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...