New Zenner
- Join Date:
- Mar 2009
- Posts:
- 78
- Plugin Contributions:
- 0
drop-down list to enter new product info
Hi,
I have been working with Zen Cart for about a month now. I am an experienced web designer, but new to writing php/mysql code.
The question I have has been brought up before in the forums, but it seems to dead end. See thread: http://www.zen-cart.com/forum/showthread.php?t=72183
I am hoping others will engage with me in this topic as I think it will be very useful to many.
I am creating a website that displays plant care information for each type of plant (leaves, not power. :smile:). I would like to create a drop-down list on the New Product page to make data-entry go faster when entering new plant information. The drop-down list in this case is called "Light Requirements". I would like to create several other drop down lists for other plant info as well.
I have tried to duplicate the manufacturer drop-down without success. I tried to find every piece of code that is connected to it, then changed the field names to "light_id" and "light_requirement. I also added a field in the products table called "light_id".
I am a beginning php user and generally understand how things work. It’s a bit tough figuring out where things are in the Zen Cart code because it is so multi-layered, pulling in variables, functions and constants from other pages. (not a criticism, just a description).
I’m hoping some kind soul will help me to work through this issue and help me to understand how things are connected. My goal is, not only to get an ecommerce site up and running, but to become proficient at php/mysql so any explanations about what files do and how they work together would be appreciated. .
Here is the url to the site I am referring to:
http://blackoliveeastnursery.net/zenCart/index.php?main_page=product_info&cPath=14&products_id=94
Below is an explanation of the database and file and changes I made:
Database Changes:
-
I created a table called “zen_products_light” to hold the different light requirements to be pulled into the drop-down menu. It has “light_id”, and “light_type” columns. I populated it with several choices.
-
I added a “light_type” column to the “zen_products” table. (again, just imitating what I have seen with the manufacturers drop-down.)
File Changes:
File Number 1:
admin/includes/modules/product/collect_info.php
-
I added this row directly above the code that contains the drop-down for the manufacturers. (around line 314, in my file). I changed “manufactures_id” to “light_id”, “manufactures_array” to “light_array” and “TEXT_PRODUCTS_MANUFACTURER” to “TEXT_PRODUCTS_LIGHT”.
<tr> <td class="main"><?php echo TEXT_PRODUCTS_LIGHT; ?></td> <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_pull_down_menu('light_id', $light_array, $pInfo->light_id); ?></td> </tr> -
Also in the “collect_info.php” file. I added 'light_id' => '', to the $parameter array around line 28 (my file)
(I’m not sure what this piece of code does, but manufacturers_id existed here, so I added the light_id here as well.)
- Also in the “collect_info.php” file. I added “p.light_id” to the “ $product ” query around line 59 (my file).
(I’m assuming this query pulls the light_id from the products table to be used elsewhere.)
-
Also in the “collect_info.php” file. I added the following code around line 84 (my file), just above the code that defines the $manufacturer_array.
$light_array = array(array('id' => '', 'text' => TEXT_NONE));
$light = $db->Execute("select light_id, light_type
from " . TABLE_PRODUCTS_LIGHT . " order by light_type");
while (!$light->EOF) {
$light_array[] = array('id' => $light->fields['light_id'],
'text' => $light->fields['light_type']);
$light->MoveNext();
}
(This code defines the light_array so that the drop down menu can pull from the products_light table.)
File Number 2:
includes/languages/english/product.php
I defined the text for the title of the drop down menu as displayed on the product_info.php page.
define(TEXT_PRODUCTS_LIGHT, 'Light Requirements:'); (around line 103, my file)
File Number 3:
**
admin/includes/modules/product/preview_info.php **
Around line 26, I added “p.light_id,” to the $product array. (my file, double-quotes excluded)
File Number 4:
**admin/includes/modules/update_product.php **
I added “'light_id' => $light_id,” to the $sql_data_array around line 48 (my file, double-quotes excluded)
File Number 5:
includes/database_tables.php
I defined the new “products_light” table here.
define('TABLE_PRODUCTS_LIGHT', DB_PREFIX . 'products_light');
around line 48 in my file
File Number 6:
includes/modules/pages/product_info/main_template_vars.php
I added “p.light_id,” (around line 53, my file)
I added “ $flag_show_product_info_light = zen_get_show_product_switch($_GET['products_id'], 'light_type');” around line 177.
File Number 7:
**includes/templates/template_default/templates/tpl_product_info_display.php **
<?php echo TEXT_PRODUCT_LIGHT . stripslashes($light_type); ?>line 88, my file
File Number 8:
admin/includes/english/product_info.php
I defined the field title for the light_type that will be displayed on the product info page.
define('TEXT_PRODUCT_LIGHT', 'Lighting Requirements: ');
RESULTS
The drop-down list itself on the new product page is working fine. I am able to select from a list of light requirements. It also appears that it is successfully sending the light_id to the products table.
I have also been able to get the field label to appear on my product info page by adding the following code just below the Product Description, around line 88.
<?php echo TEXT_PRODUCT_LIGHT . stripslashes($light_type); ?>However, the Light Requirement name does not appear.
I am not sure what I am missing. The code should be replacing the light_id with the light_requirement, just as it replaces manufacturer_id with manufacturer name and displays the name on the product id page. I thought it was the “switch” code that made this happen. (see file number 6 above). Also, somewhere there should be a query that pulls the light_type from the light table based on the light_id. I can’t figure out where that should be.
I'm hoping there is someone who has done this before and would be willing to share their knowledge.
thanks in advance