Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / drop-down list to enter new product info

drop-down list to enter new product info

Locked

Views: 4,895

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
17 May 2009, 7:04 PM
#1
lndlyb4 avatar

lndlyb4

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:

  1. 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.

  2. 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

  1. 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>
  2. 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.)

  1. 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.)

  1. 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

18 May 2009, 6:55 PM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: drop-down list to enter new product info

I think you're missing one key item in your file #6 - includes/modules/pages/product_info/main_template_vars.php

If you look at the file, at about line 69 you'll see that it's getting the manufacturers name from the database with the function zen_get_products_manufacturers_name.

You need to add code to get the light requirement name from your database table, into a variable $light_name, then modify your tpl_product_info_display to have:

<?php echo TEXT_PRODUCT_LIGHT . stripslashes($light_name); ?>
19 May 2009, 11:14 PM
#3
lndlyb4 avatar

lndlyb4

New Zenner

Join Date:
Mar 2009
Posts:
78
Plugin Contributions:
0

Re: drop-down list to enter new product info

bunyip,

Thank you so much for helping me out. I did as you suggested and the "light_type" is now appearing in the plant info page. You've helped me to take a MAJOR STEP in getting these drop-down menus working -- after DAYS of frustration (I know, we've all been there :smile:).

I did, however, run into another problem when trying to use the drop-down to update other records.

First, let me list what I did to get to this point so that I am clear (and in case anyone else is following along).

1. I added a new function to the includes/functions/functions_lookups.php file that gets the light_type from the light table based on the light_id in the products table. I imitated the function_get_products_manufactuers_name and simply replaced the appropriate code with "light_type" and "light_id". I added it at around line 364:

**function zen_get_products_light_type($product_id) {
global $db;

$product_query = "select l.light_type
                  from " . TABLE_PRODUCTS . " p, " .
                        TABLE_PRODUCTS_LIGHT . " l
                  where p.products_id = '" . (int)$product_id . "'
                  and p.light_id = l.light_id";

$product =$db->Execute($product_query);

return ($product->RecordCount() > 0) ? $product->fields['light_type'] : "";

}**

2. Then I added the code below to the includes/modules/pages/product_info/main_template_vars.php file as you suggested. I inserted it around line 77 (my file), just below the similar code for the manufactures_name.

$light_type= zen_get_products_light_type((int)$_GET['products_id']);

3. I then added the code below to the includes/templates/my custom folder/templates/tpl_product_info_display.php file.

<?php echo TEXT_PRODUCT_LIGHT . stripslashes($light_type); ?>

I tested the new code by going to my catalogue and clicking on a product that I already had added a light_type to and THERE IT WAS. The light_type showed up on the product_info page.

I did however, encounter a problem when trying to update records with the new drop down. I got an error message saying: "1054 Unknown column 'light_type' in 'field list'
in:
[update zen_products set products_quantity = '0', products_type = '1', products_model = '', products_price = '0', products_date_available = null, products_weight = '0', products_status = '1', products_virtual = '0', products_tax_class_id = '0', manufacturers_id = '0', light_id = '2', light_type = '', products_quantity_order_min = '1', products_quantity_order_units = '1', products_priced_by_attribute = '0', product_is_free = '0', product_is_call = '0', products_quantity_mixed = '1', product_is_always_free_shipping = '0', products_qty_box_status = '1', products_quantity_order_max = '0', products_sort_order = '0', products_discount_type = '0', products_discount_type_from = '0', products_price_sorter = '0.0000', products_image = 'Caladium-(13).jpg', products_last_modified = now(), master_categories_id = '14' where products_id = '39']".

I did a bunch of searches with the Developers Tool, but I could not find the query that contains the extra "light_type" field. I looked in all of the files mentioned in my previous post, but couldn't determine which one was causing the problem.

I searched the forums and most of the threads mentioned upgrading to a newer version. I just installed mine a month or so ago, so I am assuming it is the latest.

Zen Cart 1.3.8a
Database Patch Level: 1.3.8
PHP Version: 5.2.9 (Zend: 2.2.0)
Database: MySQL 5.1.30

Is this something to do with my database tables? The only changes I made to the database where adding a table called products_light that has light_id and light_type. I had also added a column to the products table entitled "light_id".

Any advice you could give me would be greatly appreciated.

19 May 2009, 11:48 PM
#4
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: drop-down list to enter new product info

check your file admin/includes/modules/update_product.php, where you added light_id into the array at line 48 and ensure you didn't also add light_type in there.

20 May 2009, 2:04 AM
#5
lndlyb4 avatar

lndlyb4

New Zenner

Join Date:
Mar 2009
Posts:
78
Plugin Contributions:
0

Re: drop-down list to enter new product info

bunyip,

Thanks for hanging with me on this.

I discovered what the problem was. I had added "light_type" to the update_product file and later removed it, but neglected to upload the corrected file. I had done this on the preview file as well.

I am now happily using my new drop down menu.

I was able to discover this by using the Developers Tool Kit to search for all instances of "light", and there it was! I had cleaned up my local files, but not my remote files. By the way, (I'm sure you know.) I am finding the DTK to be an indispensible tool. It seems that Dreamweaver does not find and replace within php code.

In any case, thanks again.

I am going to write up the instructions on how to do this in a clearer way. I hope you will take a look and add to it, if you get a chance.

thank you

24 May 2009, 4:02 PM
#6
lndlyb4 avatar

lndlyb4

New Zenner

Join Date:
Mar 2009
Posts:
78
Plugin Contributions:
0

Re: drop-down list to enter new product info

In my first post at the top of this page, in the section titled "Database Changes", at #2, I meant to say "light_id" instead of "light_type".

24 May 2009, 6:43 PM
#7
lndlyb4 avatar

lndlyb4

New Zenner

Join Date:
Mar 2009
Posts:
78
Plugin Contributions:
0

Re: drop-down list to enter new product info

File #8 above should be "includes/languages/english/product_info.php"