Ecommerce Website

Business Success

Main Menu

Home
Blog
News Feeds
FAQs

Sponsored Links

osCommerce - Adding a Field pt 1 PDF Print E-mail
A question I see asked from time to time in the osCommerce support forums is "how do I add a field to the products table?" That's a question that requires an answer a bit more involved than what can normally be provided in a forum post, so I thought I give a little tutorial on the process. There is quite a bit to cover so I am going to dispense with my normal mode and extend this one this one over several articles. As with most things its a little easier to grasp in smaller bites.

If you really want to know the truth, doing things like modifying the database or other such more "involved" changes is where the real satisfaction working with osCommerce comes in. In my mind it goes over and above making cosmetic changes and installing contributions. It's something where you can stand back when finished and have a sense of satisfaction that you have created something that is truly yours. Speaking of contributions, if you come up with something valuable you have the opportunity to support the community by sharing your work if you wish.

All of the things we will talk about here can be applied across the board for other things you might find yourself wanting to do with the system. I'll also share with you some of my lessons learned, so hopefully you might avoid some of the mistakes I've made as I too learned the system. One I'll share with you right off the bat. When I first started working with osCommerce I was mostly concerned with making it work and function the way I wanted. I didn't pay a lot of attention to the standards and structure of the application. That was ok from the sense that I accomplished my goals, however later on down the line, that get it done, make it work attitude came back to bite me. So we'll concentrate on doing things the osCommerce way.

Necessity is the mother of invention, so there of course needs to be a reason we want to add a field to the products table. Lets take a step back in time and talk about the need before we get into the solution. Suppose on our e-commerce web site, we are marketing original music. Since the music is original, our site's visitors are not going to be familiar with the product we have to offer. If we happened to be marketing hard goods, we can give our potential customers a taste of the product by displaying a picture. However with music a picture is not going to quite cut it. We need to give them a sample, a short edit of each song should do the trick and hopefully entice them to buy.

Browsing the new product input form we see fields for name, price, description, image, price, etc, however there isn't a field for "sample file", so we'll have to create one for our music store. Doing so is going to give us the opportunity to dig into the osCommerce source code. The job will require some effort an and hour or two of time, but its certainly an achievable goal.

The task of adding a field for our store's products will be accomplished in three distinct step. First we'll need to modify the database table by adding the new field. Second we'll work on the input form, adding the display of the new field and handling the code which will save the new field to the database. We'll also need to ensure the functionality works so that we can go back later and edit the new field when we need to. The last step will be to display the new field on the product listings page.

Now we have a plan in place, in part 2 we'll jump in with our DBA hat on and start making some database changes.

Happy Coding.
 
< Prev   Next >
Joomla Templates by JoomlaShack