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

How To Add New Product Fields?

Views: 83,922

Results 141 to 159 of 159
9 Oct 2019, 11:46 PM
#142
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?

lat9:

Debbie and Dave, that's a result of the zc155a+ admin sanitizer, er, sanitizing those additional text fields. See this Zen Cart documentation for more information: https://docs.zen-cart.com/Developer_Documentation/1.5.5/code_docs/admin_sanitization

Thanks @lat9.. that explains why I had to add some extra lines of code... I may have to play a bit to change my additional info fields too.

Dave
Always forward thinking... Lost my mind!

10 Oct 2019, 7:40 AM
#143
dharrison avatar

dharrison

Zen Follower

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

Re: How To Add New Product Fields?

Thanks lat9 and Dave

That does make sense but it is a bit teccie for my head.

Dave the new code for my product fields in collect_info are as follows:

<td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_textarea_field('products_features', 'soft', '100%', '10', $pInfo->products_features, zen_set_field_length(TABLE_PRODUCTS, 'products_features')); ?></td>

and update products (in the $sql_data_array):

'products_features' => zen_db_prepare_input($_POST['products_features'])

How can I improve on this?

Debbie Harrison
DVH Design | Web Design blog

13 Oct 2019, 12:47 PM
#144
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 @davewest

Did you get any joy doing this. I opted to use Numinix product fields but even that has come with issues.

Debbie Harrison
DVH Design | Web Design blog

13 Oct 2019, 1:26 PM
#145
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: How To Add New Product Fields?

Debbie, could you give a couple of examples of the information you expect to be entered in those "products_features"? Specifically, is this HTML content?

13 Oct 2019, 1:53 PM
#146
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 lat9

Absolutely. I achieved similar on this website https://shaftdirect.com/the-manual-sit-to-stand-range-c-85_134_130/manual-hand-crank-height-adjustable-desk-sit-or-stand-fss-p-210.html?zenid=112ba1d9f873ca03b1efc2b9f874d24a

Here all the tabs (except for gallery and finishes) show extra information about the products..

I'd love to achieve the same for this website - the only difference in this case is we also have Dutch and French translations.

I hope this helps.

Debbie Harrison
DVH Design | Web Design blog

13 Oct 2019, 2:34 PM
#147
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: How To Add New Product Fields?

Debbie, you can tell the admin sanitizer to leave the HTML content in that 'product_features' variable alone by creating a new .php file in the site's /admin/includes/extra_datafiles sub-directory, containing:

if (class_exists('AdminRequestSanitizer') && method_exists('AdminRequestSanitizer', 'getInstance')) {
    $site_sanitizer = AdminRequestSanitizer::getInstance();
    $site_sanitizer->addSimpleSanitization('PRODUCT_DESC_REGEX', array('product_features'));
}

Just use a unique name for the $site_sanitizer variable and, if you have other HTML-type content that should be 'left alone', just add those variables' names to that array, e.g. array('product_features', 'another_variable', 'yet_another_variable').

13 Oct 2019, 2:35 PM
#148
dharrison avatar

dharrison

Zen Follower

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

Re: How To Add New Product Fields?

Awesome I shall give that a try. Thanks Cindy. :)

Debbie Harrison
DVH Design | Web Design blog

13 Oct 2019, 3:46 PM
#149
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 @davewest

Did you get any joy doing this. I opted to use Numinix product fields but even that has come with issues.

Yes... I had to read back through this post, but I use a different method. Instead of a separate table, I use a function to maintain template table add-ons..

I use a field for more info, when it has something in it, it displays, empty it does not display.

The best way to do this type of edits is to copy another field that matches what you are after. in this case, products_description works for my more details.

Steps I did..

  1. add the field to products description table.. by adding it to my install function, I have some 20 fields I use.
if (!$sniffer->field_exists(TABLE_PRODUCTS_DESCRIPTION,'products_details')) $db->Execute("ALTER TABLE " . TABLE_PRODUCTS_DESCRIPTION . " ADD COLUMN products_details TEXT NULL DEFAULT NULL"); 
  1. edit all three files and copy fields of products_description then paste rename to my new name (products_details)
    Files: collect_info.php preview_info.php update_product.php all three if not already, should be in the product type folder.
  2. follow the sanitizer suggestion from Cindy.. Which works really grate.. Thanks Cindy for pointing that out..
    4 ) on the catalog side. add the new database field to the page main_template_vars.php Again, look for any of the products_description fields, copy, paste and rename products_details
  3. add the display code to the template page.. this is how I did it..
 <!-- bof product details -->
<?php if ($products_details != '') { ?>
<div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_details); ?></div>
<?php } ?>
 <!-- eof product details -->

Hopefully this helps a bit.. the main thing to take away is that the correct code is already in existing files, all you need do is copy and paste, rename the field and add to the database. In keeping it short what sounds simple may not be.. Hopefully in the future this well become easier with CITTINS..

Dave
Always forward thinking... Lost my mind!

13 Oct 2019, 5:15 PM
#150
dharrison avatar

dharrison

Zen Follower

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

Re: How To Add New Product Fields?

it works!!! :clap: Thank you both so much.

I only have one remaining issue: How do I set the language on the add/edit product screen? I have had a play but so far got nowhere.

In admin/includes/modules/product/collect_info.php I use

<tr>
          <td class="main" valign="top">Features (tab)</td>
<td class="main"><?php echo zen_draw_textarea_field('products_features', 'soft', '100%', '10', $pInfo->products_features, zen_set_field_length(TABLE_PRODUCTS, 'products_features')); ?></td> </tr>     

I know a language id needs to go in there somewhere, could anyone advise?

Debbie Harrison
DVH Design | Web Design blog

13 Oct 2019, 5:59 PM
#151
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: How To Add New Product Fields?

Debbie, you'll want to 'model' your additional language field(s) changes based on those that are in the 'base' Zen Cart for a product's description. Note that I'm using the file structure for zc156; if your store is still on zc155, they might be in different spots.

Affected modules:

  • /admin/includes/modules/product/collect_info.php (create an 'array' of products_features).
  • /admin/includes/modules/product/preview_info.php (display those arrays of information, if applicable, and make sure to record the arrays into a to-be-posted variable for the product's insert/update action.
  • /admin/includes/modules/update_product.php (add the language-specific 'features' on the database insert/update).

Search each file for the use of **products_description **and mimic the processing for the **products_features **information. Note that on a product's edit, the language-specific description is pulled from the database via a function (not sure how you've got that set up for the products_features).

14 Oct 2019, 9:01 PM
#152
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 lat9

I have had a play tonight and it would work except for on update_product.php where it fails to retain the information.

Ironically I stumbled on a post I wrote on the other thread about 4 years ago where the language tag was causing all the issues (funny how times change). https://www.zen-cart.com/showthread.php?57924-How-To-Add-new-Properties-to-your-Products&p=1271232#post1271232

It seems that all the product fields worthy of a language setup are sitting in the products_desription table. I have tried to add my field to this, but nothing seems to work.

Please advise. :)

Debbie Harrison
DVH Design | Web Design blog

16 Oct 2019, 11:07 AM
#153
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 always appreciate your advice, more so at the moment because anyhting I try just doesn't work.

where I am trying to copy the pattern for products_url and products_description I get error messages.

I tried to add product_features to around line 113 of admin/includs/modules/update_products.php

$languages = zen_get_languages();
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
      $language_id = $languages[$i]['id'];

      $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
                              'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
                            [B]  'products_features' => zen_db_prepare_input($_POST['products_features'][$language_id]),[/B]
                              'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));

I am assuming this is because the name description and url fields are all in table_products_description as opposed to table_product where my new fields sit.

Please help. :down:

Debbie Harrison
DVH Design | Web Design blog

16 Oct 2019, 11:48 AM
#154
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: How To Add New Product Fields?

Debbie, what errors are you receiving when you try to save that information? The line of inserted code you posted looks good.

How many occurrences of products_features to you find in each of the three changed modules?

16 Oct 2019, 2:25 PM
#155
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

I always appreciate your advice, more so at the moment because anyhting I try just doesn't work.

where I am trying to copy the pattern for products_url and products_description I get error messages.

I tried to add product_features to around line 113 of admin/includs/modules/update_products.php

$languages = zen_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$language_id = $languages[$i]['id'];

  $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
                          'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
                        [B]  'products_features' => zen_db_prepare_input($_POST['products_features'][$language_id]),[/B]
                          'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));
> 
> I am assuming this is because the name description and url fields are all in table_products_description as opposed to table_product where my new fields sit. 
> 
> Please help.  :down:
Was wounding what table structure you was using.. URL's and such that don't need translation can go into the product table our your own table easily enough, product descriptions should have the ability to be translated into other languages. They could go into the products description table our a table you created with a language id. 

The code section you posted is using the products_description table..  did you get the posted value.. its at the top of the page..

elseif ((isset($_POST['products_model']) ? $_POST['products_model'] : '') . (isset($_POST['products_url']) ? implode('', $_POST['products_url']) : '') . (isset($_POST['products_name']) ? implode('', $_POST['products_name']) : '') . (isset($_POST['products_description']) ? implode('', $_POST['products_description']) : '') . (isset($_POST['[B]products_features[/B]']) ? implode('', $_POST['[B]products_features[/B]']) : '') != '') {

Dave
Always forward thinking... Lost my mind!

16 Oct 2019, 10:29 PM
#156
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 DaveWest

No I didn't get that code at the top of the page. My version of Zencart being used is 1.5.5e if that makes any difference.

It has been suggested (thanks lat9) that I need to add these fields to the table products_description in order to set the language. So will try that and let you know

Debbie Harrison
DVH Design | Web Design blog

17 Oct 2019, 3:30 PM
#157
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 DaveWest

No I didn't get that code at the top of the page. My version of Zencart being used is 1.5.5e if that makes any difference.
Yes... code sample as i'm working in ZC1.5.6, but the line is there simplified in 1.5.5, which is why the suggestion of copy, paste and modify to what you need...

Dave
Always forward thinking... Lost my mind!

18 Oct 2019, 11:07 AM
#158
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 Dave & lat9

So far so good, I can add product fields to the products_description and there are now no errors. But when I complete the new fields, update and go back into them, my new product fields are empty.

:wacko:

Debbie Harrison
DVH Design | Web Design blog

18 Oct 2019, 3:19 PM
#159
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 Dave & lat9

So far so good, I can add product fields to the products_description and there are now no errors. But when I complete the new fields, update and go back into them, my new product fields are empty.

:wacko:
Form process:
collect_info.php gets the form data inputs which posts to preview_info.php which then has to re-post the data to update_product.php which then saves/updates the sql tables. Look at preview and see if your fields have a hidden form field to pass the data on as products_description does.
From ZC1.5.5e update_product.php line 151:

echo zen_draw_hidden_field('products_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_description[$languages[$i]['id']]), ENT_COMPAT, CHARSET, TRUE));

Dave
Always forward thinking... Lost my mind!