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

How-To: Add new Properties to your Products

Views: 144,143

Results 41 to 60 of 272
7 Aug 2007, 12:28 AM
#41
magneteye avatar

magneteye

Zen Follower

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

How-To: Add new Properties to your Products

I was able to get text area to work by copying the Description code. You need to duplicate it all over the files and do a similar table in your db.

I tried to copy the manufacturers_id for a pull down, but it didn't work. I am thinking cause that code works differently. It pulls the manufacturers names form a table that is populated by the admin. I just want to do it myself one time with 6 values. I haven't been able to get a working pull down yet. and no one has yet to have answers for me on this forum. :unsure:

7 Aug 2007, 11:15 PM
#42
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

Still hoping for someone to cue in on how to get 6 options in a pull down menu as a new product property...

What I really don't understand about all this is why is it so hard to do? I used a different cart like 5 years ago, and it let you set these up really easily in the admin. I really think this should be a feature of the cart as it makes customizing product types and properties so easy. This is a pain for anyone needing specialized fields.

7 Aug 2007, 11:36 PM
#43
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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

magneteye:

I tried to copy the manufacturers_id for a pull down, but it didn't work. I am thinking cause that code works differently. It pulls the manufacturers names form a table that is populated by the admin.yes, that works differently, although there are similarities.
magneteye:

I just want to do it myself one time with 6 values. I haven't been able to get a working pull down yet. and no one has yet to have answers for me on this forum. :unsure:

Somewhere in the top of your product type's collect_info.php script, put something like this:```
$my_list_of_options = array();
$my_list_of_options[] = array('id' => 'Name of option 1', 'text' => 'Name of option 1');
$my_list_of_options[] = array('id' => 'Name of option 2', 'text' => 'Name of option 2');
$my_list_of_options[] = array('id' => 'Name of option 3', 'text' => 'Name of option 3');
$my_list_of_options[] = array('id' => 'Name of option 4', 'text' => 'Name of option 4');
$my_list_of_options[] = array('id' => 'Name of option 5', 'text' => 'Name of option 5');
$my_list_of_options[] = array('id' => 'Name of option 6', 'text' => 'Name of option 6');


Then, later where you want the pulldown to display, echo something like this:

zen_draw_pull_down_menu('my_selected_option_from_database', $my_list_of_options, $pInfo->my_selected_option_from_database)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

8 Aug 2007, 3:02 AM
#44
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

Dr Byte. I really appreciate your response. I can kind of get what you have there. Any tips on setting up the tables in the database? I think I did that wrong when i first tried.

8 Aug 2007, 4:08 AM
#45
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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

magneteye:

Dr Byte. I really appreciate your response. I can kind of get what you have there. Any tips on setting up the tables in the database? I think I did that wrong when i first tried.

Sorry, I have no idea what you've done to get where you're at. The process of adding new fields is not something that is described in one page. It requires significant understanding of databases, database structures, coding methodologies, etc. It's not for the faint of heart.
I've not read all your posts in this thread, and I suspect that some steps are right, and others are not understanding.
The first post in this thread covers the "big picture" of the concepts, and probably worked great for the original poster's initial needs. That doesn't mean it necessarily meets "your" needs fully.

How many fields are you trying to add?
What is their purpose? What is the business need you're trying to solve?
How is each being used?
What fields have you created in the database?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

9 Aug 2007, 7:36 AM
#46
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

Dr. Byte... to answer your questions:

How many fields are you trying to add?Six fields.

What is their purpose?Sizes of clothing.

What is the business need you're trying to solve?Consignment (used) clothing. Items sold only once, then removed from product database. See the link in my sig to see the site.

What fields have you created in the database?I created a table called products_sizes and added 6 fields, one for each size (small, medium, large, xlarge, petite, plus sizes). I think I may need to have a primary key setup?

I basically just want to be able to select the size in admin when adding a product. Then the size is displayed on the product page. Lastly, I want to add the sizes to the end of my categories menu so a user can shop by size.

12 Aug 2007, 4:20 AM
#47
poolprorich avatar

poolprorich

Zen Follower

Join Date:
Aug 2007
Location:
Tampa FL.
Posts:
143
Plugin Contributions:
0

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

Dr. Byte,
a quick question about the drop down menu, if i wanted to have a drop down of lets say 6 images to be placed in a product how would i link the image to what you have displayed:
$my_list_of_options = array();
$my_list_of_options[] = array('id' => 'Name of option 1', 'text' => 'Name of option 1');
$my_list_of_options[] = array('id' => 'Name of option 2', 'text' => 'Name of option 2');
$my_list_of_options[] = array('id' => 'Name of option 3', 'text' => 'Name of option 3');
$my_list_of_options[] = array('id' => 'Name of option 4', 'text' => 'Name of option 4');
$my_list_of_options[] = array('id' => 'Name of option 5', 'text' => 'Name of option 5');
$my_list_of_options[] = array('id' => 'Name of option 6', 'text' => 'Name of option 6');

the drop down would have text for the admin to chose from but the result would be an image displayed in the product display for the customer

any help i would be gratfull
thanks in advance
rich

12 Aug 2007, 7:01 PM
#48
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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

hostmonster:

Dr. Byte,
a quick question about the drop down menu, if i wanted to have a drop down of lets say 6 images to be placed in a product how would i link the image to what you have displayed:
$my_list_of_options = array();
$my_list_of_options[] = array('id' => 'Name of option 1', 'text' => 'Name of option 1');
$my_list_of_options[] = array('id' => 'Name of option 2', 'text' => 'Name of option 2');
$my_list_of_options[] = array('id' => 'Name of option 3', 'text' => 'Name of option 3');
$my_list_of_options[] = array('id' => 'Name of option 4', 'text' => 'Name of option 4');
$my_list_of_options[] = array('id' => 'Name of option 5', 'text' => 'Name of option 5');
$my_list_of_options[] = array('id' => 'Name of option 6', 'text' => 'Name of option 6');

the drop down would have text for the admin to chose from but the result would be an image displayed in the product display for the customer

any help i would be gratfull
thanks in advance
rich

The whole issue is a complex topic. The first post in this thread covers the overall concepts.
You'll need to create a database field to store the choice. Then create the forms for selecting the desired option when entering/editing the products, make sure the info gets saved, and then in the display template make sure the page displays the proper image based on the entry.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Aug 2007, 7:41 AM
#49
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

Dr Byte, did you see my reply up a couple from what you asked me last about what I was trying to do... my pulldown question got kinda hijacked here. I am still trying to figure it out.

Thanks!

15 Aug 2007, 12:04 PM
#50
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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

magneteye:

Six fields.

Sizes of clothing.This would be a classic reason for using attributes.

magneteye:

I created a table called products_sizes and added 6 fields, one for each size (small, medium, large, xlarge, petite, plus sizes).
If I correctly read your proposed structure for the products_sizes table as being a reference table, your needs are more directly reflective of pulling data from the Manufacturers table and simply storing the selected choice into your new "product_size" field in your products table:

  • query the table
  • build an array of its entries
  • display a pulldown
  • store the selected entry
  • then in the storefront, display information appropriately based on the selected setting
  • and build your shop-by-size choices in the category menu

magneteye:

Lastly, I want to add the sizes to the end of my categories menu so a user can shop by size.
That's yet another kettle of fish ... and doing it by using normal attributes would be admittedly more difficult. Using a dedicated size table as you're considering may be a touch easier. Nevertheless, I recall a contribution floating around some time back that had code for shop-by-size in it. It should be in the downloads section if you want to use it as a reference. I think it was attribute-based.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Aug 2007, 9:01 PM
#51
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

ok, but doesn't using attributes on the user side? Meaning, when a user is say looking a tshirt, and they wantr to order it and they select their size. Isn't tht how the attributes work? That NOT what I need. Since the clothes being sold are always just one set size by the admin.

Shopping by size doesn't have to be part of the category menu I guess, I could just make it a pull down menu or other type just below the category menu in a sidebox.

15 Aug 2007, 10:33 PM
#52
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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

magneteye:

ok, but doesn't using attributes on the user side? Meaning, when a user is say looking a tshirt, and they wantr to order it and they select their size. Isn't tht how the attributes work? That NOT what I need. Since the clothes being sold are always just one set size by the admin.Fair enough. Then attributes won't be your solution. My other comments still apply.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

22 Sep 2007, 8:09 PM
#53
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

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

Just for the record, re: post 19 (product details list and not getting your new field to display by itself), before the output <ul> section there is an if() test which only displays the list if one of its elements has a value or is set to display.

Add your field to that test and it will trigger the list to show.

3 Oct 2007, 12:41 AM
#54
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Location:
California
Posts:
628
Plugin Contributions:
0

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

Has anyone been able to add additional product fields using a separate table? Can you provide an easy 'how-to' for us with little knowledge such as the one shown here?

Not sure if this has been posted on the wish-list, but this, along with the ability to add additional customer info fields, is essential to any growing business and probalby should be a standard feature of ZenCart.

6 Nov 2007, 6:59 PM
#55
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

crazy_chris:

*Guarantee:

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

This is supposedly only going to output if something exists, but it am placing my items in a list and can't seem to figure out how to make it NOT show the list bullets (and list title) when it is empty. Can anyone help?

EDIT:

I figured it out on my own:

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

BUT, I can't figure out how to hide the list title if nothing exists in any of my 4 new fields that create the list.

Here's the code as is, and obviously the "Product Features" is always there at this point:

<p><strong>Product Features:</strong></p> <ul> <?php if (!empty($product_info->fields['products_feature1'])) echo '<li>' . $product_info->fields['products_feature1'] . '</li>'; ?> <?php if (!empty($product_info->fields['products_feature2'])) echo '<li>' . $product_info->fields['products_feature2'] . '</li>'; ?> <?php if (!empty($product_info->fields['products_feature3'])) echo '<li>' . $product_info->fields['products_feature3'] . '</li>'; ?> <?php if (!empty($product_info->fields['products_feature4'])) echo '<li>' . $product_info->fields['products_feature4'] . '</li>'; ?> </ul>

13 Nov 2007, 9:51 AM
#56
rwoody avatar

rwoody

Totally Zenned

Join Date:
Aug 2004
Location:
Fountain Hills, AZ
Posts:
476
Plugin Contributions:
0

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

gjh42:

Just for the record, re: post 19 (product details list and not getting your new field to display by itself), before the output <ul> section there is an if() test which only displays the list if one of its elements has a value or is set to display.

Add your field to that test and it will trigger the list to show.

I'm working on a product type;however it really only is adding one field to the products table for that product type. I'm having the same issue - getting the field to display on the products detail page. I've done this before, in an older version with no problems - but for some reason its giving me fits this time (I'm upgrading).
The admin side works perfectly - all data is collected and displayed properly.

I did as you stated above and listed the field in the test - Here is the code from that section (product_candle is the product type - burn_time is the field - )

<!--bof Product details list  -->
<?php if ( (($flag_show_product_candle_info_model == 1 and $products_model != '') or <?php if ( (($flag_show_product_candle_info_burn_time == 1 and $products_burn_time != '') or ($flag_show_product_candle_info_weight == 1 and $products_weight !=0) or ($flag_show_product_candle_info_quantity == 1) or ($flag_show_product_candle_info_manufacturer == 1 and !empty($manufacturers_name))) ) { ?>
<ul id="productDetailsList" class="floatingBox back">
  <?php echo (($flag_show_product_candle_info_model == 1 and $products_model !='') ? '<li>' . TEXT_PRODUCT_MODEL . $products_model . '</li>' : '') . "\n"; ?>
  <?php echo (($flag_show_product_candle_info_burn_time == 1 and $products_burn_time !='') ? '<li>' . TEXT_PRODUCT_BURNTIME . $products_burn_time . '</li>' : '') . "\n"; ?>
  <?php echo (($flag_show_product_candle_info_weight == 1 and $products_weight !=0) ? '<li>' . TEXT_PRODUCT_WEIGHT .  $products_weight . TEXT_PRODUCT_WEIGHT_UNIT . '</li>'  : '') . "\n"; ?>
  <?php echo (($flag_show_product_candle_info_quantity == 1) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>'  : '') . "\n"; ?>
  <?php echo (($flag_show_product_candle_info_manufacturer == 1 and !empty($manufacturers_name)) ? '<li>' . TEXT_PRODUCT_MANUFACTURER . $manufacturers_name . '</li>' : '') . "\n"; ?>
</ul>

Any suggestions?:blink:

20 Nov 2007, 10:05 PM
#57
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

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

Hey this is a great tutorial thanks,

I have a question, I want to use textarea instead of the input field, I looked to see how the description field was coded so I copied and replaced “zen_draw_input_field” with “zen_draw_textarea_field” and Zen Cart did not like that at all, how can I change the input field to a textarea?

Warning: Missing argument 4 for zen_draw_textarea_field()
20 Nov 2007, 10:29 PM
#58
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

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

Ok I got it to work using the following code, I hope others find this useful

<?php echo zen_draw_textarea_field('products_YOUR-FIELD-NAME[' . $languages[$i]['id'] . ']', 'soft', '100%', '10', $pInfo->products_YOUR-FIELD-NAME, zen_set_field_length(TABLE_PRODUCTS, 'products_YOUR-FIELD-NAME')); ?>
9 Jan 2008, 9:03 PM
#59
jagge avatar

jagge

Zen Follower

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

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

Hi,
this issue is really bothering me as well. I will soon go insane on this!
I also needs extra fields to choose from in admin. Some of them should be textfields, some would be dropdown with values and some would need checkboxes.

In other carts I worked with this was not usually a problem and with Zencart that is bright and good on everything else I cant understand why this have to be such an issue.

For my needs It would be enough to be able to create attributes in normal way but then only use them for adminpart. No customers should be able to choose anything (like magneticeyes needs)

I really need to get this issue fixed somehow. If someone feels like they could fix this i´m willing to pay him/her to do it.

Best regards,
Ola

11 Jan 2008, 7:50 PM
#60
dbrewster avatar

dbrewster

Zen Follower

Join Date:
Jul 2005
Location:
Charlottesville, VA
Posts:
376
Plugin Contributions:
0

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

jagge:

I really need to get this issue fixed somehow. If someone feels like they could fix this i´m willing to pay him/her to do it.

There is a message board in this forum for hiring custom coding work. I've done that very successfully, worked with a developer in another country, in fact, who was familiar enough with ZC and he was able to deliver what I needed very nicely, at a fair price. What you describe is trivial for an experienced developer who knows ZC, but if you're not handy with PHP and SQL, adding extra product attribute fields is not a simple thing. It would be lovely to automate custom fields in some future edition of ZC, it would make creating custom product types a breeze, wouldn't it! The custom code will need to be nested inside several files according to the current code structure. This creates future maintenance chores for you, as you must manually merge and update files for each future ZC release. Just some things to think about.

---Diana