Interesting code question posed on the osCommerce forum so I thought it would make a decent blog post;
Are there any contributions out there which add product information fields in the admin section so that you can list the product as new, used, or refurbished?
Always self code if possible, it’s better and you learn a little bit about the osCommerce engine…
Step 1: Add new input fields to admin/categories.php
Easy enough, basically look at produce model, and copy the code but rename to product_type. Add an extra question in the form;
Next up, an ugly kludge to read the value of each of the options and check the correct one automatically (eg, if you are updating an existing product).
[php]products_type == 0) ? true : false;
$checked1 = ($pInfo->products_type == 1) ? true : false;
$checked2 = ($pInfo->products_type == 2) ? true : false;
Step 2: Add language definitions to admin/includes/english/categories.php
I’m sure you can see what you need to add, from the code above!!!
Step 3: Add new row to DB products table
Add a row called products_type, and make it a smallint of 2 characters (this gives you upto 99 different types in case you need to expand this in the future.
DONE! Here is how it looks;
Now you can do more stuff, how about showing the type of product on the product_info.php page? Certianly possible, but quite complicated as you need two new functions along with a sprintf. But, easy enough, here’s how it looks;
I can maybe show how I did that in a future post, if there is any interest. But if you want to try yourself, here is a few clues;
1. Because all we have in the database is “0” or “1” or “2”, you need to link those numbers to text, so 0 = new, 1 = Old and so on.
2. Once you’ve done that you need to use a sprintf to show some text along with the number.
3. And make a function to change the number into the text that it is linked to.
Remember that this is a quick and easy way of doing this – coded by me in less than 10 minutes – so it might not do everything that you need it do! But it’s a good start on a coding adventure. Good luck!