Forums / Setting Up Categories, Products, Attributes / How To Add New Product Fields?

How To Add New Product Fields?

Views: 83,922

Results 121 to 140 of 159
10 Nov 2011, 7:31 AM
#121
jonathanbee avatar

jonathanbee

New Zenner

Join Date:
Oct 2007
Posts:
19
Plugin Contributions:
0

How To Add New Product Fields?

I got it. There's another file, copy_to_confirm.php that also needs to be updated for this to work fully. I'm on an older version of Zen Cart so maybe that's why nobody else seems to have this issue..

19 May 2012, 5:01 PM
#122
jordanfey1978 avatar

jordanfey1978

New Zenner

Join Date:
May 2012
Posts:
2
Plugin Contributions:
0

Re: How To Add New Product Fields?

I know this original thread is a few years old, so I'm hoping someone might still be watching it and be able to help.

I'm currently working on my wifes shop (http://www.katiesgiftshop.co.uk) And I've added a new field for Google Categories as we have written a PHP export which creates a file to upload all our products into their merchant / shopping tool.

I'm more of a hack programmer than someone who knows what they are doing, but I got the new field showing on the admin product details screen, it works for both new and existing records on update, but after I have put it in I cannot copy products as duplicate. No error is generated to the user, but no details copy to the new product at all. In the cache directory I get a file showing :-

[19-May-2012 18:38:01] PHP Warning: reset() [<a href='function.reset'>function.reset</a>]: Passed variable is not an array or object in /'admin'/includes/classes/object_info.php on line 29
[19-May-2012 18:38:01] PHP Warning: Variable passed to each() is not an array or object in /homepages/12/d254737192/'admin'/includes/classes/object_info.php on line 30

When I installed a different mod (MSRP) that added additional fields I had to amend 'copy_to_confirm.php' and I think ?I have to do the same to make this work again, but I am a bit lost, any pointers would be very gratefully recieved.

19 May 2012, 7:40 PM
#123
jordanfey1978 avatar

jordanfey1978

New Zenner

Join Date:
May 2012
Posts:
2
Plugin Contributions:
0

Re: How To Add New Product Fields?

jordanfey1978:

I know this original thread is a few years old, so I'm hoping someone might still be watching it and be able to help.

I'm currently working on my wifes shop (http://www.katiesgiftshop.co.uk) And I've added a new field for Google Categories as we have written a PHP export which creates a file to upload all our products into their merchant / shopping tool.

I'm more of a hack programmer than someone who knows what they are doing, but I got the new field showing on the admin product details screen, it works for both new and existing records on update, but after I have put it in I cannot copy products as duplicate. No error is generated to the user, but no details copy to the new product at all. In the cache directory I get a file showing :-

[19-May-2012 18:38:01] PHP Warning: reset() [<a href='function.reset'>function.reset</a>]: Passed variable is not an array or object in /'admin'/includes/classes/object_info.php on line 29
[19-May-2012 18:38:01] PHP Warning: Variable passed to each() is not an array or object in /homepages/12/d254737192/'admin'/includes/classes/object_info.php on line 30

When I installed a different mod (MSRP) that added additional fields I had to amend 'copy_to_confirm.php' and I think ?I have to do the same to make this work again, but I am a bit lost, any pointers would be very gratefully recieved.
------------------------------------------------------_-
With a bit of homework I've managed to sort this myself, there was already some things in this forum that I had overlooked. Here is my full 'copy_to_confirm.php' file that I hope people might find interesting, please note though, there are a lot of extra fields, I have modified https://www.katiesgiftshop.co.uk quite a lot!

<?php /** * @package admin * @copyright Copyright 2003-2009 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: copy_to_confirm.php 14139 2009-08-10 13:46:02Z wilt $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } if (isset($_POST['products_id']) && isset($_POST['categories_id'])) { $products_id = zen_db_prepare_input($_POST['products_id']); $categories_id = zen_db_prepare_input($_POST['categories_id']); // Copy attributes to duplicate product $products_id_from=$products_id; if ($_POST['copy_as'] == 'link') { if ($categories_id != $current_category_id) { $check = $db->Execute("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$categories_id . "'"); if ($check->fields['total'] < '1') { $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$categories_id . "')"); } } else { $messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error'); } /*Removed 27/09/2011 as part of RRP mod } elseif ($_POST['copy_as'] == 'duplicate') { $old_products_id = (int)$products_id; $product = $db->Execute("select products_type, products_quantity, products_model, products_image, products_price, products_virtual, products_date_available, products_weight, products_tax_class_id, manufacturers_id, products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute, product_is_free, product_is_call, products_quantity_mixed, product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order, products_price_sorter, master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); */ /* Removed and replaced as part of google category addition } elseif ($_POST['copy_as'] == 'duplicate') { $old_products_id = (int)$products_id; $product = $db->Execute("select products_type, products_quantity, products_model, products_image, products_price, products_msrp, products_virtual, products_date_available, products_weight, products_tax_class_id, manufacturers_id, products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute, product_is_free, product_is_call, products_quantity_mixed, product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order, products_price_sorter, master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); */ } elseif ($_POST['copy_as'] == 'duplicate') { $old_products_id = (int)$products_id; $product = $db->Execute("select p.products_type, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_msrp, p.products_virtual, p.products_date_available, p.products_weight, p.products_tax_class_id, p.manufacturers_id, p.products_quantity_order_min, p.products_quantity_order_units, p.products_priced_by_attribute, p.product_is_free, p.product_is_call, p.products_quantity_mixed, p.product_is_always_free_shipping, p.products_qty_box_status, p.products_quantity_order_max, p.products_sort_order, p.products_price_sorter, p.master_categories_id, pdex.google_category from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_ADDITIONAL_DETAILS . " pdex where p.products_id = '" . (int)$products_id . "' and pdex.products_id = '" . (int)$products_id . "'"); $tmp_value = zen_db_input($product->fields['products_quantity']); $products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value; $tmp_value = zen_db_input($product->fields['products_price']); $products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value; $tmp_value = zen_db_input($product->fields['products_weight']); $products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value; $db->Execute("insert into " . TABLE_PRODUCTS . " (products_type, products_quantity, products_model, products_image, products_price, products_msrp, products_virtual, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute, product_is_free, product_is_call, products_quantity_mixed, product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order, products_price_sorter, master_categories_id ) values ('" . zen_db_input($product->fields['products_type']) . "', '" . $products_quantity . "', '" . zen_db_input($product->fields['products_model']) . "', '" . zen_db_input($product->fields['products_image']) . "', '" . $products_price . "', '" . zen_db_input($product->fields['products_msrp']) . "', '" . zen_db_input($product->fields['products_virtual']) . "', now(), '" . (zen_not_null(zen_db_input($product->fields['products_date_available'])) ? zen_db_input($product->fields['products_date_available']) : '0001-01-01 00:00:00') . "', '" . $products_weight . "', '0', '" . (int)$product->fields['products_tax_class_id'] . "', '" . (int)$product->fields['manufacturers_id'] . "', '" . zen_db_input($product->fields['products_quantity_order_min']) . "', '" . zen_db_input($product->fields['products_quantity_order_units']) . "', '" . zen_db_input($product->fields['products_priced_by_attribute']) . "', '" . (int)$product->fields['product_is_free'] . "', '" . (int)$product->fields['product_is_call'] . "', '" . (int)$product->fields['products_quantity_mixed'] . "', '" . zen_db_input($product->fields['product_is_always_free_shipping']) . "', '" . zen_db_input($product->fields['products_qty_box_status']) . "', '" . zen_db_input($product->fields['products_quantity_order_max']) . "', '" . zen_db_input($product->fields['products_sort_order']) . "', '" . zen_db_input($product->fields['products_price_sorter']) . "', '" . zen_db_input($categories_id) . "')"); $dup_products_id = $db->Insert_ID(); // added fields//////// $db->Execute("insert into " . TABLE_PRODUCTS_ADDITIONAL_DETAILS. " (products_id, google_category ) values ('" . (int)$dup_products_id ."', '" . zen_db_input($product->fields['google_category']) . "' )"); // added fields//////// $description = $db->Execute("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'"); while (!$description->EOF) { $db->Execute("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description->fields['language_id'] . "', '" . zen_db_input($description->fields['products_name']) . "', '" . zen_db_input($description->fields['products_description']) . "', '" . zen_db_input($description->fields['products_url']) . "', '0')"); $description->MoveNext(); } $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')"); $products_id = $dup_products_id; $description->MoveNext(); // FIX HERE ///////////////////////////////////////////////////////////////////////////////////////////// // Copy attributes to duplicate product // moved above $products_id_from=zen_db_input($products_id); $products_id_to= $dup_products_id; $products_id = $dup_products_id; if ( $_POST['copy_attributes']=='copy_attributes_yes' and $_POST['copy_as'] == 'duplicate' ) { // $products_id_to= $copy_to_products_id; // $products_id_from = $pID; // $copy_attributes_delete_first='1'; // $copy_attributes_duplicates_skipped='1'; // $copy_attributes_duplicates_overwrite='0'; if (DOWNLOAD_ENABLED == 'true') { $copy_attributes_include_downloads='1'; $copy_attributes_include_filename='1'; } else { $copy_attributes_include_downloads='0'; $copy_attributes_include_filename='0'; } zen_copy_products_attributes($products_id_from, $products_id_to); } // EOF: Attributes Copy on non-linked ///////////////////////////////////////////////////////////////////// // copy product discounts to duplicate if ($_POST['copy_discounts'] == 'copy_discounts_yes') { zen_copy_discounts_to_product($old_products_id, (int)$dup_products_id); } // BEGIN CEON URI MAPPING 1 of 1 // Generate new URI mapping for this new product? $uri_mapping_autogen = (($_POST['uri_mapping'] == 'autogen') ? true : false); // Copy existing URIs from product being copied? $uri_mapping_copy = (($_POST['uri_mapping'] == 'copy') ? true : false); if ($uri_mapping_autogen || $uri_mapping_copy) { if ($uri_mapping_copy) { // Lookup and copy any URI mappings for the product be copied from $existing_product_uri_mappings = array(); $existing_product_uri_mappings_sql = " SELECT language_id, uri FROM " . TABLE_CEON_URI_MAPPINGS . " WHERE main_page = '" . zen_db_input($zc_products->get_handler($product->fields['products_type'])) . "_info' AND associated_db_id = '" . (int) $products_id_from . "' AND current_uri = '1';"; $existing_product_uri_mappings_result = $db->Execute($existing_product_uri_mappings_sql); while (!$existing_product_uri_mappings_result->EOF) { $existing_product_uri_mappings[ $existing_product_uri_mappings_result->fields['language_id']] = $existing_product_uri_mappings_result->fields['uri']; $existing_product_uri_mappings_result->MoveNext(); } } // Now insert the URI mappings for the new product into the database $languages = zen_get_languages(); for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { $uri_mapping = ''; $unique_id_to_add = ''; // Auto-generate the URI if requested if ($uri_mapping_autogen) { $uri_mapping = ceon_uri_mapping_autogen_category_or_product_uri( $products_id_to, 'product', null, null, $languages[$i]['code'], $languages[$i]['id']); } else { // Copy any URI mappings for the product be copied from, changing them slightly so // they are unique (in case admin user forgets to change the URI for the "new" // product) if (isset($existing_product_uri_mappings[$languages[$i]['id']])) { $uri_mapping = $existing_product_uri_mappings[$languages[$i]['id']]; if (strlen($uri_mapping) > 1) { $unique_id_to_add = '/' . $products_id_to; } } } if (strlen($uri_mapping) > 1) { // Make sure URI mapping is relative to root of site and does not have more than // one trailing slash or any illegal characters $uri_mapping = ceon_uri_mapping_cleanup_uri_mapping($uri_mapping); } if ($uri_mapping != '') { // URI mapping does not yet exist $sql_data_array = array( 'uri' => zen_db_prepare_input($uri_mapping . $unique_id_to_add), 'date_added' => date('Y-m-d H:i:s') ); $insert_sql_data = array( 'main_page' => $zc_products->get_handler($product->fields['products_type']) . '_info', 'associated_db_id' => (int) $products_id_to, 'language_id' => (int) $languages[$i]['id'], 'current_uri' => 1 ); $sql_data_array = array_merge($sql_data_array, $insert_sql_data); zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array); // Now add the URI mappings for the review pages/tell-a-friend page for this // product if (substr($uri_mapping, -1) != '/') { $uri_mapping .= '/'; } $sql_data_array['uri'] = zen_db_prepare_input($uri_mapping . CEON_URI_MAPPING_URI_PART_PRODUCT_REVIEWS . $unique_id_to_add); $sql_data_array['main_page'] = zen_db_prepare_input(FILENAME_PRODUCT_REVIEWS); zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array); $sql_data_array['uri'] = zen_db_prepare_input($uri_mapping . CEON_URI_MAPPING_URI_PART_PRODUCT_REVIEWS_INFO . $unique_id_to_add); $sql_data_array['main_page'] = zen_db_prepare_input(FILENAME_PRODUCT_REVIEWS_INFO); zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array); $sql_data_array['uri'] = zen_db_prepare_input($uri_mapping . CEON_URI_MAPPING_URI_PART_PRODUCT_REVIEWS_WRITE . $unique_id_to_add); $sql_data_array['main_page'] = zen_db_prepare_input(FILENAME_PRODUCT_REVIEWS_WRITE); zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array); $sql_data_array['uri'] = zen_db_prepare_input($uri_mapping . CEON_URI_MAPPING_URI_PART_TELL_A_FRIEND . $unique_id_to_add); $sql_data_array['main_page'] = zen_db_prepare_input(FILENAME_TELL_A_FRIEND); zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array); } } } // END CEON URI MAPPING 1 of 1 } // reset products_price_sorter for searches etc. zen_update_products_price_sorter($products_id); } zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
30 Jul 2012, 11:49 PM
#124
enochian avatar

enochian

New Zenner

Join Date:
Jan 2009
Posts:
33
Plugin Contributions:
0

Re: How To Add New Product Fields?

Hi I have used this thread to add extra fields and it works great, thanks.

I was wondering if anyone could tell me how to add radio buttons. For example I am working on a site where you can book courses. I would like to add a set of radio button in the admin page where I can choose the location where the course will be held and display it. Some courses will have two locations so I thought a radio button would be best but I don't know how to go about it. The display could be something like this Location: Here, There if two were selected or just Location: Here if only one selected.

When adding a product in admin, after adding the description there would be a set of radio buttons to select the location the course will be held in. I can just do a text field where you type the location in but I'm not sure if this is the best way because I want people to be able to search for courses held at a particular location. Not sure if its possible but I noticed you can search by manufacturer, I would like to be able to search by location. I don't need the manufacturer field so maybe there is a way I can just change it to location but some courses I would need to add two locations but now I can only add one.

I have tried to search the forum but can't find any help so if some one can point me in the right direction it would be greatly appreciated. Hope this makes sense.

31 Jul 2012, 5:27 PM
#125
jagall avatar

jagall

Zen Follower

Join Date:
Mar 2011
Location:
Ireland
Posts:
286
Plugin Contributions:
0

Re: How To Add New Product Fields?

You could do search and replace on manufacturer in develop tool kit in admin pannel and change to location etc. what about using attributes for location, would have to be different locations attribute for each course? but the user would only get to choose the locations available for that course.

25 Nov 2012, 3:25 AM
#126
mybiz9999 avatar

mybiz9999

Zen Follower

Join Date:
Jul 2010
Posts:
143
Plugin Contributions:
0

Re: How To Add New Product Fields?

Thank you so much for such valuable post!

I have a question.

I need only do the step 1, 2, 7,8 if I don't need to maintain the new field at Admin?

Is that correct?

please help, thank all of you so much.

1: Create a new table to hold your additional fields and give it a name i.e. products_extra_stuff and add the products_id field (so we can relate our new table to the existing products table) and whatever fields you wish to add i.e. products_colour

2:Open includes/database_tables.php and add your new table to the list of definitions i.e.define('TABLE_PRODUCTS_EXTRA_STUFF', DB_PREFIX . 'products_extra_stuff');

Step 7
...

Step 8

webego:

After searching through the Zen Cart forums for help on how to add new product fields, I came across a thread started by crazy_chris which shows how to add a new field to the existing products table. Later in that thread zskiman shows how to add fields into a separate table, which is a great idea to future proof your efforts for later upgrades etc. My intention here is to share what I have learned from both these posts and add my own input which I think simplifies the end usage of your new fields.

Any changes to existing code or completely new code are shown in red (what out for , too).

So lets gets started...

  1. Create a new table to hold your additional fields and give it a name i.e. products_extra_stuff and add the products_id field (so we can relate our new table to the existing products table) and whatever fields you wish to add i.e. **products_colour

**

  1. Open includes/database_tables.php and add your new table to the list of definitions i.e.define('TABLE_PRODUCTS_EXTRA_STUFF', DB_PREFIX . 'products_extra_stuff');

  1. Open admin/includes/modules/product/preview_info.php and change the following lines:

(line 26 for me)
p.products_sort_order, pdex.products_colour
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_EXTRA_STUFF . " pdex
where p.products_id = pd.products_id and p.products_id = pdex.products_id

  1. Open admin/includes/modules/product/collect_info.php and change the following lines :

(line 12 for me)
$parameters = array('products_name' => '',
'products_description' => '',
…
'master_categories_id' => '',
'products_colour' => ''

);

(now line 60 for me after the above edit)
p.products_price_sorter, p.master_categories_id, pdex.products_colour
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS_EXTRA_STUFF . " pdex

where p.products_id = '" . (int)$_GET['pID'] . "'
and p.products_id = pd.products_id and p.products_id = pdex.products_id

  1. In the same file (collect_info.php) insert your form fields to collect your new data along with the rest:

(line 305 for me as I wanted to insert just below product name)
<!-- BOF - Additional field added -->
<tr>

<td class="main"><?php echo 'Colour '; ?></td> <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '13') . '##' . zen_draw_input_field('products_colour', $pInfo->products_colour, zen_set_field_length(TABLE_PRODUCTS_EXTRA_STUFF, 'products_colour')); ?></td> </tr> <!-- EOF - Additional field added -->

  1. Open admin/includes/modules/update_product.php and add the following lines to process both new products and the editing of existing ones:

(line 153 for me)
////////////// MY ADDED FIELDS ////////////////////
$sql_data_array = array('products_colour' => zen_db_prepare_input($_POST['products_colour']));

if ($action == 'insert_product') {
$insert_sql_data = array('products_id' => $products_id);

      $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

      zen_db_perform(TABLE_PRODUCTS_EXTRA_STUFF, $sql_data_array);

} elseif ($action == 'update_product') {
zen_db_perform(TABLE_PRODUCTS_EXTRA_STUFF, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
}
/////////////////////////////////////////////

  1. In order to make the data from your new field(s) available to add to the product page open inludes/modules/pages/product_info/main_template_vars.php and change the following lines:

(line 55 for me)
p.products_discount_type, p.products_discount_type_from, p.products_sort_order,
p.products_price_sorter, pdex.products_colour
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_EXTRA_STUFF . " pdex
where p.products_status = '1'
and p.products_id = '" . (int)$_GET['products_id'] . "'
and pd.products_id = p.products_id and p.products_id = pdex.products_id

(line 101 for me amongst products name, model and description)
$products_colour = $product_info->fields['products_colour'];

  1. Finally, to display the data from your new field(s) open includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display.php and add something similar to the following:

(place wherever you wish your new field to be displayed)
<!--bof Product Colour -->

<?php if ($products_colour != '') { ?> <div id="productColour" class="productGeneral"><strong>Colour: </strong><?php echo $products_colour; ?></div> <?php } ?> <!--eof Product Colour -->

And that my friends is it...Enjoy!

15 Dec 2012, 10:58 PM
#127
gandalfsmith avatar

gandalfsmith

New Zenner

Join Date:
Oct 2011
Location:
Toronto Canada
Posts:
69
Plugin Contributions:
0

Re: How To Add New Product Fields?

mybiz9999:

1: Create a new table to hold your additional fields and give it a name i.e. products_extra_stuff and add the products_id field (so we can relate our new table to the existing products table) and whatever fields you wish to add i.e. products_colour
2:Open includes/database_tables.php and add your new table to the list of definitions i.e.define('TABLE_PRODUCTS_EXTRA_STUFF', DB_PREFIX . 'products_extra_stuff');

Zencart Version 1.5.0

I have followed all of these instructions to the letter and got it to work. I have created two extra fields (one is products_rating and the other is products_averageprice), they both work.

http://www.winez2u.com/index.php?main_page=product_info&cPath=&products_id=243

I have also got it to display on the website on the product info pages (tpl_product_info_display.php) - with this code:

<!--bof Product Average Price -->
<?php if ($products_averageprice != '') { ?>
<div id="productDescription" class="">
<h3>Average Price:</h3>
<div class="pDesc"><?php echo $products_averageprice; ?></div>
<?php
}

?>
<!--eof Product Average Price -->

<!--bof Product Rating -->
<?php if ($products_rating != '') { ?>
<div id="" class="">
<h3>Current Rating:</h3>
<div class="pDesc"><?php echo $products_rating; ?></div>
<?php
}

?>
<!--eof Product Rating -->


So now the next part is what has been CONFUSING me for days and I just cannot get it right.

I want only ONE Of those extra fields to display on the product_listing page (ie. where all the products for a category come up). I am using a 4 Column Layout . I want the PRODUCTS_RATING extra field to display on each product UNDER THE PRICE (see http://www.winez2u.com/index.php?main_page=index&cPath=75_65

I CANNOT get it to work, no matter what I try and figure I am missing something - I have tried inc/mod/mytemplate/product_listing.php but am totally LOST. On that page, I have this code in to display if column layout is selected:

// Following code will be executed only if Column Layout (Grid Layout) option is chosen
    if ($product_listing_layout_style == 'columns') {
      $lc_text = implode('<br />', $product_contents);
      $list_box_contents[$rows][$column] = array('params' => 'class="product-grid-list"' . ' ' , 'text' => (($listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<div class="product-bg"><div class="product-topbg"><div class="featureImg1"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . $productsInCategory[$listing->fields['products_id']] . '&products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a></div></br>') . '<div class="featureDescription1"><div class="prodtitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . $productsInCategory[$listing->fields['products_id']] . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name']. '</a></div><span class="Price">' . $lc_price . '</span></div><div class="featureButton">'.$lc_button.'</div><div class="product-bottombg"> </div></div></div>');

      $column ++;
      if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
        $column = 0;
        $rows ++;
      }
    }
    // End of Code fragment for Column Layout (Grid Layout) option in add on module

PLEASE HELP, what code do I need to put in to get it to show my extra field PRODUCTS_RATING? I know it is calling from a 2nd table, and thats about it.
Would really appreciate some help.:ohmy:

9 Jan 2013, 6:21 PM
#128
gandalfsmith avatar

gandalfsmith

New Zenner

Join Date:
Oct 2011
Location:
Toronto Canada
Posts:
69
Plugin Contributions:
0

Re: How To Add New Product Fields?

Anyone willing to help me with this - please?

gandalfsmith:

Zencart Version 1.5.0

I have followed all of these instructions to the letter and got it to work. I have created two extra fields (one is products_rating and the other is products_averageprice), they both work.

http://www.winez2u.com/index.php?main_page=product_info&cPath=&products_id=243

I have also got it to display on the website on the product info pages (tpl_product_info_display.php) - with this code:

<!--bof Product Average Price -->
<?php if ($products_averageprice != '') { ?>
<div id="productDescription" class="">
<h3>Average Price:</h3>
<div class="pDesc"><?php echo $products_averageprice; ?></div> <?php } ?> <!--eof Product Average Price --> <!--bof Product Rating -->
<?php if ($products_rating != '') { ?>
<div id="" class="">
<h3>Current Rating:</h3>
<div class="pDesc"><?php echo $products_rating; ?></div> <?php } ?> <!--eof Product Rating -->

So now the next part is what has been CONFUSING me for days and I just cannot get it right.

I want only ONE Of those extra fields to display on the product_listing page (ie. where all the products for a category come up). I am using a 4 Column Layout . I want the PRODUCTS_RATING extra field to display on each product UNDER THE PRICE (see http://www.winez2u.com/index.php?main_page=index&cPath=75_65

I CANNOT get it to work, no matter what I try and figure I am missing something - I have tried inc/mod/mytemplate/product_listing.php but am totally LOST. On that page, I have this code in to display if column layout is selected:

// Following code will be executed only if Column Layout (Grid Layout) option is chosen
if ($product_listing_layout_style == 'columns') {
$lc_text = implode('<br />', $product_contents);
$list_box_contents[$rows][$column] = array('params' => 'class="product-grid-list"' . ' ' , 'text' => (($listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<div class="product-bg"><div class="product-topbg"><div class="featureImg1"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . $productsInCategory[$listing->fields['products_id']] . '&products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a></div></br>') . '<div class="featureDescription1"><div class="prodtitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . $productsInCategory[$listing->fields['products_id']] . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name']. '</a></div><span class="Price">' . $lc_price . '</span></div><div class="featureButton">'.$lc_button.'</div><div class="product-bottombg"> </div></div></div>');

  $column ++;
  if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
    $column = 0;
    $rows ++;
  }
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module
> 
> PLEASE HELP, what code do I need to put in to get it to show my extra field PRODUCTS_RATING?  I know it is calling from a 2nd table, and thats about it.
> Would really appreciate some help.:ohmy:
13 Jan 2013, 8:44 PM
#129
petepdx avatar

petepdx

New Zenner

Join Date:
Jul 2012
Posts:
22
Plugin Contributions:
0

Re: How To Add New Product Fields?

To save time checking throught the whole thread is the initial submission the one to follow ?

-pete

6 Feb 2013, 9:35 AM
#130
sharon_j avatar

sharon_j

New Zenner

Join Date:
Dec 2012
Location:
Tampa,FL
Posts:
25
Plugin Contributions:
0

Re: How To Add New Product Fields?

When I need to add extra fields, there are two different plug ins that I use. One is the Products Cost Display, and the other is the UPC/ISBN extra fields. The Product Cost produces a field that only displays in admin. I use that one for the ones that I only want to display in admin. I just go through the files and change wherever the products cost is referenced and following that format, I change it to the field that I want. Then when you install the sql file, do the same thing, only in the sql file, you can also tell it where you want the field to display (after price, etc.) You just need to change the one word in the file. If I want it to also display on the front end, follow the same steps as with the Product Cost Display, only using the UPC/ISBN plug in, you can see there are a couple of other files that you need to edit. Then just following format in those files and of course replacing either upc or isbn with what ever you want. This works for fields where you want to add numerical data. To add fields where you want to add text, you need to edit the sql file. You have to make a change to Decimal and Default. To know what to put there, I just check my database, look at a text field, and use those parameters.

14 May 2013, 12:16 PM
#131
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: How To Add New Product Fields?

When I update the field colour in admin, it does not update the zen_products_extra_stuff table.

I have used the following SQL to math records.

INSERT products_extra_stuff (products_id, products_colour) SELECT products_id, 'your default value here' FROM products

Using Zen Cart 1.5.1

17 May 2013, 7:08 PM
#132
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: How To Add New Product Fields?

Bump...

Does anyone why the field will not get updated in the SQL table?

Using Zen Cart 1.5.1

20 Apr 2014, 7:01 PM
#133
vacuumwarlock avatar

vacuumwarlock

New Zenner

Join Date:
Mar 2014
Posts:
22
Plugin Contributions:
0

Re: How To Add New Product Fields?

What I am wondering due to the fact I don't know php or Zen Cart that well, YET, but in the examples everywhere no one ever says exactly where the sort for "colour" is even coming from. I can't just make something up if it isn't an attribute or something. So my question, is do these extra fields draw from something that was created in the products such as attributes?

8 Apr 2015, 11:56 AM
#134
pompidompie avatar

pompidompie

Zen Follower

Join Date:
Mar 2015
Posts:
105
Plugin Contributions:
0

Re: How To Add New Product Fields?

This is the answer to my question. I would like to add, deliverytime, shippingcosts and used material to de details. So therefor i want to try whats written in this thread. However, i bumped into a problem right away :laugh::blush:
I don't have much experience and being Dutch I sometime do not understand the words.
So my problem is this:

Create a new table to hold your additional fields and give it a name i.e. products_extra_stuff and add the products_id field (so we can relate our new table to the existing products table) and whatever fields you wish to add i.e. products_colour

Do I have to go to the database and then add something? I can see what, but i don't see where. Can someone please help me with this?

Language: Dutch
English: not so very good
Allready have a live shop, so building local/on my computer

15 Feb 2017, 11:17 AM
#135
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: How To Add New Product Fields?

Create a new table to hold your additional fields and give it a name i.e. products_extra_stuff and add the products_id field (so we can relate our new table to the existing products table) and whatever fields you wish to add i.e. products_colour

Ok. I have a newbie question: How can I add the products_id field to her new table?

I win newbie prize award :clap:

Debbie Harrison
DVH Design | Web Design blog

9 Oct 2019, 4:41 PM
#136
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: How To Add New Product Fields?

Hi

I have just new product fields to my test template and it looks ok. Using http://sitstandforbusiness.com/paral/fundamental-manual-standing-desk-c-22_73_88/fundamental-height-adjustable-sitstand-desk-with-manual-crank-adjustment-p-113.html as an example.

I have an issue with the product fields. For example, I can add the following to technical info

Attachment 18679

But when I save the changes and go back in I get

Attachment 18680

And this happens everytime I edit the product. It makes a mess.

I set up the product fields as text. I really can't think of what else I can do?

Please help.

Debbie Harrison
DVH Design | Web Design blog

9 Oct 2019, 5:26 PM
#137
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: How To Add New Product Fields?

dharrison:

I set up the product fields as text. I really can't think of what else I can do?

Please help.
Don't you just love HTML editors...

Click the source button and the HTML tags well hide.. In What-You-See-Is-What-You-Get mode the tags are not displayed, however they are created. In source mode you see all the HTML tags.

Dave
Always forward thinking... Lost my mind!

9 Oct 2019, 5:37 PM
#138
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: How To Add New Product Fields?

I'm slow on editing...
Info: to remove the editor only for this field, change the class from editorHook to noEditor.. This well make the field text only and no HTML editor well be used.

Dave
Always forward thinking... Lost my mind!

9 Oct 2019, 6:24 PM
#139
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: How To Add New Product Fields?

Hi David

The tag rendering exists on both text and visual editor.

If you look at the link I sent you can see what it looks like

Debbie Harrison
DVH Design | Web Design blog

9 Oct 2019, 10:35 PM
#140
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: How To Add New Product Fields?

dharrison:

Hi David

The tag rendering exists on both text and visual editor.

If you look at the link I sent you can see what it looks like
Yes, HTML editors add tags so you get what you see... The link shows the added tags in product description, then sanitized it on all other tabs. Could be an issues with the template display or how the text fields was saved.. If the new text fields are saving the same as the description field in update_product.php then it may be how the template is reading it into the tabs...

To give me a better idea, can you post just the input lines for the text field and the DB line for the save..
like.. collect_info.php

 <?php echo zen_draw_textarea_field('products_description[' . $languages[$i]['id'] . ']', 'soft', '100%', '30', htmlspecialchars((isset($products_description[$languages[$i]['id']])) ? stripslashes($products_description[$languages[$i]['id']]) : zen_get_products_description($pInfo->products_id, $languages[$i]['id']), ENT_COMPAT, CHARSET, TRUE), 'class="editorHook form-control"'); ?>

and update_product.php

'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),

I've not read the entire post, but use many added product fields..

Dave
Always forward thinking... Lost my mind!