Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

How to add a customize product admin fields in zencart by editing/adding extra codes

Problem: How to add a product custom field named length.

This to consider (modifications in):
1.) database
2.) scripts
-----------------------------------
1.) Database - a custom column should be add to the products table.
Execute this line (for column name products_length):
ALTER TABLE `products` ADD `products_length` INT NOT NULL AFTER `products_status`

2.) Scripts - we have to modify at least 4 files
a.) admin/includes/modules/products/collect_info.php - we need to query the field's value:

Find this line:

if (isset($_GET['pID']) && empty($_POST)) {
$product = $db->Execute("select pd.products_name, pd.products_description, pd.products_url,

//And add the following line:
p.products_length, //(just look at the pattern)


*we need to show the fields in the product page, so add this line (maybe under Product Qty Min/Unit Mix: or where ever you want):

<tr>
<td class="main"><?php echo TEXT_PRODUCTS_LENGTH; ?></td>
<td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_length', ($pInfo->products_length == 0 ? 0 : $pInfo->products_length)); ?></td>
</tr>

b.) admin/includes/languages/english/product.php - this is where we will define the label for the field, just add this line:


define('TEXT_PRODUCTS_LENGTH','Length:');


c.) admin/includes/modules/update_product.php - we need to update the update statement.
Find this line:


$sql_data_array = array('products_quantity' => $products_quantity,


And insert this line:

'products_length' => zen_db_prepare_input($_POST['products_length']),


If you are not familiar with how a query works, just look at the pattern. Easy right?

Well, I guess that's it we have a custom length field. This field can be shown in the frontend but we have to modify the respective file.
How to add a customize product admin fields in zencart by editing/adding extra codes How to add a customize product admin fields in zencart by editing/adding extra codes Reviewed by czetsuya on Wednesday, May 20, 2009 Rating: 5

7 comments:

Anonymous said...

I think it's

admin/includes/modules/product/collect_info.php

not

admin/includes/modules/products/collect_info.php

in my ZC install anyway...

thanks for the guide, just what I was looking for!

Anonymous said...

Anonymous,

Yes you'r right it should be:

admin/includes/modules/product/collect_info.php

Thanks for correcting.

Anonymous said...

Thanks for information. It made my life so much easier.

Ryan Bishop said...

As of 3.0, It looks like you also have to define the template variables in

/includes/modules/pages/product_info/main_template_vars.php

Just wanted to say thanks for a great tutorial! It got me through 90% of a technical hitch with a ZC theme

keith said...

Can someone please help with this? I have changed the appropriate files as indicated above but the sql script is not working. I am getting the following error "1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''products'' at line 1
in:
[show fields from znc_'products']
If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you left no blank fields.". Also which file do you need to changed to get this to show on the front end.

Thanks,

Keith

jag said...

hi i have tried this and nothing shows up at all, really at a loss how to do this.
jacqui

JoanneM said...

I was wondering if this mod would work with Zen Cart 1.5.1 version. I just want to add the keywords on the new product page - I tried this, but it didn't work - didn't recognize the new column added, in version 1.5.1

Thanks!

Powered by Blogger.