However my aim here was not to try and target a small handful of people with that particular need. Rather my hope has been and is to provide some tips which cover a wide range of modifying osCommerce. I have attempted to take you through some of the thought process, I have gone through myself trying to learn and figure out the system. Most of the knowledge I have gained concerning osCommerce has come from digging into the code and just plain old figuring it out. So hopefully this series has been helpful to a few or more of those reading. Even more I hope that it sparks your abilities to take things even further as you use this very robust system. And now off to the races....
So we've taken care of the admin portions of this project. Now we need to display something on a page in our store which makes it all worthwhile. In the process we will be working with several files, configure.php, a language file, and a few others.
There are a couple of different approaches we could take, however for this tutorial we'll take the simple and straight forward approach. We'll use a simple HTML link which our site's visitors will be able to click on in order to listen to the sample file. We will also display the link on the Product Information page (product_info.php). An alternative approach would be to display the link on the grid listings of products, however that gets a little more complex and I want to finish this series without a couple of more steps. You should however be able to apply the information here if you did choose to display the link on any other pages than what will be demonstrated.
If we look at the Product Information page, we have the product title and price at the top. Below is the product description. Further down are the product attributes and finally the 'Review" and 'Add to Cart' buttons. We will be placing our link directly below the product description. The link will contain the text 'Listen to a Sample'. Therefore the first thing we need to do, because we are placing text on the page, is add an entry to the language file for the page. If you have had a change to read my article on language files, you know that you will need to open /includes/languages/english/product_info.php. Since I've also covered the territory in the other article I won't repeat myself here, if you haven't read that article now would be a good time.
With the /includes/languages/english/product_info.php file open, add this line of code just above the final ?> tag, and of course save the file when you are done:
define('TEXT_LISTEN_SAMPLE', Listen to a Sample');
OK with that step complete lets turn our attention to the physical location of our sample file. We can store the sample files anywhere that we want on the web server, for this example we will use a 'samples' folder which is directly under the root folder for osCommerce which is usually 'catalog'. That would make the location of the samples folder catalog/samples/.
When we are adding or updating a product it will make things a lot easier if all we have to do is enter the file name for our samples rather than the complete path. What will enable us to do that is an entry in the includes/configure.php file. Just like with the language file, anywhere above the final ?> tag, insert this line of code:
define('DIR_WS_SAMPLES', 'samples/');
Save and close the configure.php file and now its time for home stretch. Open up the product_info.php file. It should make perfect sense that anytime the system displays something like product information that is stored in the database, the first thing that needs to happen is for the system to query the database for that information. On line 72 is where this happens:
$product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
In case you aren't familiar with the way osCommerse does SQL selects here's a brief explaination. Take a look at this portion of the code:
TABLE_PRODUCTS . " p
osCommerce uses the database_tables.php file to define the table names in the database. 'TABLE_PRODUCTS' is defined as the 'Products' table. The above line of code therefore would translate out to 'Products p'. In SQL the 'p' then becomes an alias for 'Products'. Now look at this piece of code:
p.products_id
This is the same as saying 'products.products_id' or the 'products_id' column of the 'Products' table. Way back in part 2 of this series we added the 'products_sample' to the 'Products' table. Therefore we need to retrieve that value when we do the query. It makes no difference where its added as long as it is before the 'from' keyword in the statement. Also remember to insert a comma between each column being retrieved. When complete a portion of the statement might looks like this:
select p.products_id, p.products_sample, pd.products_name, pd.products_description,
The SQL statement should now be complete. The following line after the SQL statement is:
$product_info = tep_db_fetch_array($product_info_query);
tep_db_fetch_array is another osCommerce function that performs the retrieve on the database and returns the result set in the form of an array, in this case $product_info. The values contained in the array are then accessed using the array subscript in this manner: $product_info['column_name']. We will need to add the code to grab the sample file name from the array, on line 88 is a closing ?> tag. Insert a line above that tag and add this code:
$sample_file['sample_file']
And now we are on the home stretch. On line 120 is this line of code:
<p><?php echo stripslashes($product_info['products_description']); ?></p>
Insert a line directly below that one and add this which will be our link display:
<p><?php echo '<a href="' . tep_href_link(DIR_WS_SAMPLES . $sample_file) . '">' . TEXT_LISTEN_SAMPLE. '</a>'; ?> </p>
And guess what? We are all done! Now from that line of code we have the constant name for the samples folder, so say our sample file for this product was tune1.mp3, the link would look like:
http://www.storexyz.com/catalog/samples/tune1.mp3
And the displayed text for the link would be 'Listen to a Sample' as we have defined it.
This concludes this multipart series of Adding a Field, I hope that you the reader have gained some knowledge and enjoyed reading as much as I have writing. My great love in life is sharing knowledge to those anxious and willing to learn. I would hope that you would take some of the principles and ideas here and apply them in your own way. I would also encourage anyone working with osCommerce to have a test/development installation of the system so that you may experiment and try things out. In my opinion there is no better way to learn.
Happy Coding!

![Add this page to My.MSN.com... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 5 - [XML/RSS 2.0]](/images/rss_mymsn.gif)
![Subscribe to this page with Bloglines... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 5 - [XML/RSS 2.0]](/images/sub_modern5.gif)
![Subscribe to this page with NewsGator Online... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 5 - [XML/RSS 2.0]](/images/ngsub1.gif)
![Subscribe to this page with Feedburner... Shopping Cart Review - ECommerce Cart Software Reviews, Ratings and Information Understanding osCommerce - Adding a Field Part 5 - [XML/RSS 2.0]](/images/fbapix.gif)






















