Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / How-To: Add new Properties to your Products

How-To: Add new Properties to your Products

Views: 144,059

Results 1 to 20 of 272
8 Feb 2007, 7:05 PM
#1
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Location:
Vienna
Posts:
38
Plugin Contributions:
0

How-To: Add new Properties to your Products

hi folks,

this is a little howto add new properties to general products
(like guarantee time, color, oem-number, compatible models, whatsoever)1. think
decide which new properties you want to add to your products
(in this example we take guarantee-time (in months) and color)
.
2. db manipulation
open the table "products" in your zencart-database and insert new rows at the end of the table called "products_guarantee" and "products_color"
*ALTER TABLE zencart_products ADD products_guarantee INT NOT NULL , ADD products_color VARCHAR( 32 ) NOT NULL;
.
*
3. edit 'collect_info.php' (in /admin/includes/modules/product/)1. at the very beginning there is the variable $parameters set. add your row-names to the end:
'products_guarantee' => '0', 'products_color' => '' );
.

2. just below there is the db-query set [$product = $db->Execute("...]
add your rows with a 'p.' in front (before the "from ..." part)
*select ......., p.products_guarantee, p.products_color from ....
.
3. now you can add the input fields in the product-mask (lets say somewhere around line 450 or so):

<tr> <td class="main">Guarantee Time (in months)</td> <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_guarantee', $pInfo->products_guarantee, zen_set_field_length(TABLE_PRODUCTS, 'products_guarantee')); ?></td> </tr><tr> <td class="main">Color</td> <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_color', $pInfo->products_color, zen_set_field_length(TABLE_PRODUCTS, 'products_color')); ?></td> </tr> .* 4. **edit 'preview_info.php' ** (in /admin/includes/modules/product/) somewhere around line 10 is the variable $product set. like in step 3.2 add the new rows with a 'p.' in front just before the 'from' *select ......., p.products_guarantee, p.products_color from .... .* 5. **finally, edit ****'update_product.php' ** (in /admin/includes/modules/) around line 20 is the $sql_data_array set. add to the last lines before ');' the new rownames. *$sql_data_array = .......... 'products_guarantee' => zen_db_prepare_input($_POST['products_guarantee']), 'products_color' => zen_db_prepare_input($_POST['products_color']) ); .* 6. ***Setup All Done! . ***.*:D . .*Of course, now we want to display our cool new properties . . 7. **edit 'main_template_vars.php'** (in /includes/modules/pages/product_info/) around line 46 you find the variable $sql set. like in step 3.2 add the new rows with a 'p.' in front just before the 'from' *select ......., p.products_guarantee, p.products_color from .... .* 8. **last step: display the new infos edit 'tpl_product_info_display.php'** (in /includes/templates/template_default/templates/) now, wherever you want, you can add to the html: *<?php echo $product_info->fields['products_guarantee']; ?>* and *<?php echo $product_info->fields['products_color']; ?>* enjoy!

ps: now i'm feeling really fucked up : P

:blink::blink::blink:

written by chris at linuxuser.at

9 Feb 2007, 10:40 PM
#2
bunyip avatar

bunyip

Totally Zenned

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

Re: How-To: Add new Properties to your Products

Personally, I prefer to put new product properties into a separate table rather than the products table - you never know when the core code is going to change and perhaps encounter problems if you've added extra fields to a table (ever have a mysql error telling you the column count doesn't match?). It's a little more work to achieve the same result, but could save lots of time bug-hunting in the future.

9 Feb 2007, 10:43 PM
#3
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

That's a really good point. I added a new field as described above but may go back at some point (in my copious free time - ha!) and change it to a separate table.

4 May 2007, 3:03 PM
#4
roblaw avatar

roblaw

New Zenner

Join Date:
Mar 2007
Posts:
16
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

I would like to make the output conditional upon a value being present in the DB. Could you expand on your PHP a little bit. I am having a little trouble with the logic.

Guarantee: <?php echo $product_info->fields['products_guarantee']; ?>
*Color: <?php echo $product_info->fields['products_color']; ?>

I would only like this to display if a value is present. I can't seem to come up with a conditional statement that works properly.

Any help is greatly appreciated.

Thanks.
*

5 May 2007, 7:09 AM
#5
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Location:
Vienna
Posts:
38
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

*Guarantee:

<?php if (!empty(**$product_info->fields['products_guarantee'])) **echo $product_info->fields['products_guarantee']; ?>*
7 May 2007, 2:46 PM
#6
roblaw avatar

roblaw

New Zenner

Join Date:
Mar 2007
Posts:
16
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Crazy Chris,

Thanks for the help.

roblaw

22 May 2007, 4:55 PM
#7
sirbuck avatar

sirbuck

Zen Follower

Join Date:
Jan 2007
Location:
Carlsbad, CA
Posts:
161
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

crazy_chris:

*Guarantee:

<?php if (!empty(**$product_info->fields['products_guarantee'])) **echo $product_info->fields['products_guarantee']; ?>*

Very useful! Thanks guys

1 Jun 2007, 1:52 AM
#8
thedean avatar

thedean

New Zenner

Join Date:
Mar 2007
Posts:
11
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

bunyip:

Personally, I prefer to put new product properties into a separate table rather than the products table - you never know when the core code is going to change and perhaps encounter problems if you've added extra fields to a table (ever have a mysql error telling you the column count doesn't match?). It's a little more work to achieve the same result, but could save lots of time bug-hunting in the future.

It makes sense to do the separate table so what needs to be done to integrate it? I understand how to make a new table in MySQL without any problems but I'm fairly new in working with PHP code. So do you have the changes available to share so some of us can set it up this way?

19 Jul 2007, 3:15 PM
#9
alex_clarke avatar

alex_clarke

Totally Zenned

Join Date:
Mar 2006
Posts:
909
Plugin Contributions:
1

Re: How-To: Add new Properties to your Products

bunyip:

Personally, I prefer to put new product properties into a separate table rather than the products table - you never know when the core code is going to change and perhaps encounter problems if you've added extra fields to a table (ever have a mysql error telling you the column count doesn't match?). It's a little more work to achieve the same result, but could save lots of time bug-hunting in the future.

Have you (or has anyone else) done this? If so, would they be willing to share the code?

21 Jul 2007, 9:34 AM
#10
k4satin avatar

k4satin

New Zenner

Join Date:
Mar 2006
Location:
Sacramento, CA
Posts:
93
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Wow, I wish I'd seen this sooner. I've spent so much time reading 23 pages of piece-meal instructions on the Additional Products Fields contribution, only to find out that TheOracle is no longer around to help me make it work. His contribution still involves editing so many files that this seems just as good.

I would love to see step-by-step instructions like those from crazy_chris but using the new table, like the others have suggested.

Alternatively, is there a way to manually asign product id numbers? My main problem is that I want to show both the manufacturer's model number & my sku number. The dev team seems to suggest using the 'model' field for your sku, but I need both. Using my sku as the id would be ideal.

Thanks in advance for any suggestions!

21 Jul 2007, 9:57 AM
#11
alex_clarke avatar

alex_clarke

Totally Zenned

Join Date:
Mar 2006
Posts:
909
Plugin Contributions:
1

Re: How-To: Add new Properties to your Products

Why not set your SKU number as the products model number (standard Zen Cart functionality) and then add an extra field (as post 1 in this thread explains) for your Manufacturers model number?

21 Jul 2007, 10:08 AM
#12
k4satin avatar

k4satin

New Zenner

Join Date:
Mar 2006
Location:
Sacramento, CA
Posts:
93
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Thanks for the suggestion. That's what I was planning to do (or vice versa), now that I found this. (Unless someone has a better idea...) Does it matter which one is the new field and which uses the 'model' field? Would both fields be visible to the search function? Would I be able to limit one of the fields to not allow duplication (for my skus)?

I was originally trying to use TheOracle's contribution to create the extra field, but it's more trouble than it's worth.

I guess the only thing I'm waiting on now is the code for a new table instead of adding to the existing one. When it comes time to upgrade, I wouldn't want to lose the new field.

One more question - would Easy Populate be able to enter data into the new field? Would it matter for Easy Populate if it's added to the existing table or a new one?

Thanks!

24 Jul 2007, 11:15 AM
#13
shirster avatar

shirster

Zen Follower

Join Date:
Sep 2005
Location:
Hong Kong
Posts:
301
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

I'm also interested in this but would love to put the extra fields in a separated table... anyone?

Thanks in advance !
Shirley :)

25 Jul 2007, 5:17 PM
#14
qm360 avatar

qm360

New Zenner

Join Date:
Jul 2007
Posts:
40
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

I am using Easy Populate and when I import I get this error:

No model field in record. This line was not imported

28 Jul 2007, 7:20 AM
#15
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

I would also love an answer to the extra tables. and I am using Easy Populate as well.

maybe 1.4 could even have an 'add custom fields' button built in!??! :D
that would be cool.

Thanks in advance...

30 Jul 2007, 4:37 AM
#16
magneteye avatar

magneteye

Zen Follower

Join Date:
Mar 2007
Location:
Portland, OR
Posts:
163
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

hey, trying this out. but how do I create dropdowns and text areas? you only give examples of a text field.

I tried changing zen_set_field_length to zen_draw_textarea_field but it gave me errors.

31 Jul 2007, 7:44 AM
#17
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Thanks Chris! it worked perfect for me.

If you have a chance to respond,

Do you have any thoughts on:

separate tables instead,

easy populate,

and having these new fields included in the search fields!!

just a wishlist.

thanks again for your time in that step-by-step

1 Aug 2007, 8:12 AM
#18
magneteye avatar

magneteye

Zen Follower

Join Date:
Mar 2007
Location:
Portland, OR
Posts:
163
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Oh man, this is a pain in my arse. Ok, so i think i got the text area going. I am able to use my new product property in the admin. it is there in the databse. The problem now is the output. I check my file over and over, I did just as instructed, but it's nto working right.

Nothing shows up unless ANOTHER property is also displayed (model, quantity,etc).

What in the hell can this mean? I am pulling my hair out over this. Been spending the last 2 days trying different things with the code.

PLEASE someone help me!

thanks.

1 Aug 2007, 8:37 AM
#19
magneteye avatar

magneteye

Zen Follower

Join Date:
Mar 2007
Location:
Portland, OR
Posts:
163
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Argh. Ok, the problem seems to be with this part of the code:

<ul id="productDetailsList" class="floatingBox back">
 
  <?php echo (($flag_show_product_info_model == 1 and $products_model !='') ? '<li>' . TEXT_PRODUCT_MODEL . $products_model . '</li>' : '') . "\n"; ?>
  <?php echo (($flag_show_product_info_weight == 1 and $products_weight !=0) ? '<li>' . TEXT_PRODUCT_WEIGHT .  $products_weight . TEXT_PRODUCT_WEIGHT_UNIT . '</li>'  : '') . "\n"; ?>
  <?php echo (($flag_show_product_info_quantity == 1) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>'  : '') . "\n"; ?>
 <?php echo (($flag_show_product_info_manufacturer == 1 and !empty($manufacturers_name)) ? '<li>' . TEXT_PRODUCT_MANUFACTURER . $manufacturers_name . '</li>' : '') . "\n"; ?>
</ul>
```If I try to put the new property inside here it doesnt work, if i put it above this it does. This sucks because I am trying to control the way this information is presented.  I want it in the same List, and in the order I want.

So, any ideas how to make it display correctly within the above code?

thanks again!
3 Aug 2007, 8:50 AM
#20
magneteye avatar

magneteye

Zen Follower

Join Date:
Mar 2007
Location:
Portland, OR
Posts:
163
Plugin Contributions:
0

Re: How-To: Add new Properties to your Products

Well, after 2 days of madness and no replies....I got it to work somewhat.

Ok, so who knows how to do this but with something that has options for the admin to choose from? This purpose of this site is to sell used clothes, and when someone adds a new product, we want to be able to choose the size from a drop down list. this is NOT an attribute for the customer, this is for admin to set for one item.

Also, wondering how we could display this in a pull down for the customer side, so they can shop by size.

Any help is much appreciated!