Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Adding a custom product field - How To Rate Topic   - - - - -

 
  • storm
  • Senior Member
  • Members
  • Join Date: 26-Sep 07
  • 126 posts

Posted 12 December 2007 - 06:04 PM #1

I saw a couple messages regarding this in searches, but just thought I'd post what I have found so far in my customization experience.

This covers adding a field when viewing a single products detail page or the multiple product edit screen

Single Product Detail (when clicking on a product's name in the Manage Products screen)

- for this demonstration, let's say we are adding a field to enter a custom URL in the product_descriptions table

1) Add database field cstmPageUrl in table, product_descriptions
2) Add new input field in /skins/basic/admin/products_pages/product_update.tpl

<tr>
<td class="field-name" nowrap="nowrap">{$lang.cstmPageUrl}:</td>
<td > </td>
<td>
<input type="text" name="product_description[cstmPageUrl]" size="55" value="{$product_data.cstmPageUrl|escape:html}" class="input-text" style="width: 85%" /></td>
</tr>

3) Add new field to Language definitions
- Go to Admin screen, Admin->Languages
- add new field for cstmPageUrl

Multiple Product Detail (when checking multiple products and then choosing "Select Fields to Edit" in the Manage Products screen)

1) Repeat step 1 & 3 above for adding the field to the table and to the Language table if it hasn't been done already
2) In include/admin/products.php
a) add to the bottom of the array $selected_fields (~line 604) - this will add the field to the "Select fields to edit"

array(
'name' => '[description][cstmPageUrl]',
'text' => fn_get_lang_var('cstmPageUrl')
),

B) add to the bottom of the array $field_groups (~line 835) and pick the group you want to the field to show in i.e. Group D would be 'D'. Each display column on the results page has a different letter. You can view the smarty debug screen to see which columns are available.

'cstmPageUrl' => 'products_description',

Hope that makes sense. I just quickly jotted down what I did. Please test with a backup first.

Thanks.
Version 1.3.5 sp1

 
  • cheebs
  • Senior Member
  • Members
  • Join Date: 18-Dec 07
  • 142 posts

Posted 18 December 2007 - 09:04 AM #2

Excellent post on adding another field to a product description. I'm trying to add some cost related fields to the product in the products_prices table by following your guide, but I'm not seeing anything update when I upload my changes.

Can you elaborate on this for a price/cost type field??

This would REALLY help me. Thanks!

Example (standard cost field)

<tr>
<td class="field-name" nowrap="nowrap">{$lang.std_cost} ({$currencies.$primary_currency.symbol}) :</td>
<td > </td>
<td>
<input type="text" name="product_price[std_cost]" size="10" value="{$product_data.std_cost|default:'0.00'}" class="input-text" /></td>
</tr>

 
  • jobosales
  • Senior Member
  • Members
  • Join Date: 04-Nov 06
  • 3114 posts

Posted 18 December 2007 - 09:10 AM #3

Cheebs-

Take a look at the post below - it soundslike this is what you want and does not require any changes to the code:

http://forum.cs-cart...711&postcount=3

Bob
CS-Cart 2.0.14 (testing)

 
  • storm
  • Senior Member
  • Members
  • Join Date: 26-Sep 07
  • 126 posts

Posted 18 December 2007 - 04:06 PM #4

Let me know if the using the Feature option works for you, otherwise i can look into how to add it to the product_price table.
Version 1.3.5 sp1

 
  • cheebs
  • Senior Member
  • Members
  • Join Date: 18-Dec 07
  • 142 posts

Posted 18 December 2007 - 07:03 PM #5

First of all, thanks for the quick response! I'm so glad I found and purchased this software, and community support is a huge element to success.

The features option looks really good, and the downside of hard-coding in these fields is that when its time to run CS-cart upgrades, it certainly wont be straightforward.

On the other hand, with these extra fields in the database, I can import (say, cost) from my older database, and export the information easier. I'll also be able to run some external cost analysis reports if there are dedicated fields. I'll explore the features section more, but Storm, it would be great if you could help me and others get a better idea of what I'm doing wrong on these fields.

I think once I get a better pattern down of how to add specific types of fields, especially cost/price type fields, anyone wanting to expand on these will have an easier time.

:) Thanks!!!

 
  • storm
  • Senior Member
  • Members
  • Join Date: 26-Sep 07
  • 126 posts

Posted 18 December 2007 - 08:03 PM #6

The features option is sometimes a little limiting for me as well. It is a hassle to create the custom fields, but if you're creating 1, then it's almost no additional trouble to create 10.

I think you almost had it in your code (assuming you have added the field to the table already)

<tr>
<td class="field-name" nowrap="nowrap">{$lang.std_cost} ({$currencies.$primary_currency.symbol}) :</td>
<td > </td>
<td>
<input type="text" name="product_price[std_cost]" size="10" value="{$product_data.std_cost|default:'0.00'}" class="input-text" /></td>
</tr>

Instead of product_price, I think it should be just price as below:

<tr>
<td class="field-name" nowrap="nowrap">{$lang.std_cost} ({$currencies.$primary_currency.symbol}) :</td>
<td > </td>
<td>
<input type="text" name="price[std_cost]" size="10" value="{$product_data.std_cost|default:'0.00'}" class="input-text" /></td>
</tr>

Hopefully that works.
Version 1.3.5 sp1

 
  • cheebs
  • Senior Member
  • Members
  • Join Date: 18-Dec 07
  • 142 posts

Posted 18 December 2007 - 10:06 PM #7

Hmmm... I tried that and also product.data, and every other combination but it still doesnt want to save the value.

Also, I added the field to the products_prices table. Should it go somewhere else? (I first tried just the products table, then moved the field to the products_prices table)

Thanks!

 
  • cheebs
  • Senior Member
  • Members
  • Join Date: 18-Dec 07
  • 142 posts

Posted 18 December 2007 - 10:13 PM #8

I just tried it in the product_descriptions table (adding the cost field to the descriptions table) and it works. But I'd rather not have any cost fields in this table if possible.

Just thought I'd throw that in. Anybody know of limitations of adding fields in other tables like the products_prices table, and getting them to update in the backend??

Thanks!

 
  • storm
  • Senior Member
  • Members
  • Join Date: 26-Sep 07
  • 126 posts

Posted 18 December 2007 - 11:39 PM #9

I think you'd be best off putting it in the products table or the products_descriptions table.

I think the pricing table works a little different since it may allow multiple entries for pricing depending on membership type.

So you will have duplicate data issues if you try that.
Version 1.3.5 sp1

 
  • YouRockDaddy
  • Senior Member
  • Members
  • Join Date: 11-Apr 06
  • 319 posts

Posted 12 May 2008 - 05:47 PM #10

Thanks for a great post Strom.

I have a question, I need my new field to be returned on products_multicolumns.tpl as well as products_details.tbl. While product_details.tpl works fine, products_multicolumns.tpl does not. I made the changes to products_multicolumns.tpl, but my new field does not get returned. Do you know what PHP page I edit to added this new field to the array or query for this page?

There's what I did for my custom field addition:

I needed a field to display the unit name like Dozen next to the price on the product page like

$24.95/Dozen

I decided to add my custom filed in the 'products' table as this is just a small field that will needed to be returned at the same item the other fields in this table did.

These are the mods I needed to make to have it work with this table rather then the 'product_descriptions'

Hopefully this post helps someone as Storms did for me.

1. I added a field called unit to the table products

2. Added new field to Language definitions

3. In products.php I added this, changing [description] to [data] in my code to accommodate for the different table

array(
'name' => '[data][unit]',
'text' => fn_get_lang_var('unit')
),

4. In product_update.tpl I added this, changing product_description to product_data to accommodate for the different table

<tr>
<td class="field-name" nowrap="nowrap">{$lang.unit}:</td>
<td> </td>
<td>
<input type="text" name="product_data[unit]" size="10" value="{$product_data.unit|escape:html}" class="input-text"/></td>
</tr>

5. Then added in section B // short inputs, changing products_description to products_data to accommodate for the different table

'unit' => 'products_data',

5. Then in product_details.tpl I added

{$product.unit}

 
  • storm
  • Senior Member
  • Members
  • Join Date: 26-Sep 07
  • 126 posts

Posted 13 May 2008 - 03:04 PM #11

Hello Marc,

Thanks for your kind words. Unfortunately I am not actively developing for CS-Cart anymore so I can't recall how to do that exactly. I looked through the code and what is happening is the multicolumns.tpl is receiving a smaller set of data than the details.tpl

It would be best to try to trace back through the files to see where that query is coming from.

It might be somewhere where this function is called:

fn_gather_additional_product_data()

Sorry can't be of further help.
Version 1.3.5 sp1

 
  • gugga7
  • Senior Member
  • Members
  • Join Date: 16-Mar 08
  • 277 posts

Posted 13 May 2008 - 03:12 PM #12

I would like to add a product feature as an icon, I have products with several country origins on my website and would like to be able to upload icons that say: "Made in USA" or "Made in Mexico", etc... how can I tweak what's been shared above to achieve that?