[ic] Adding Fields

Dan Browning interchange-users@interchange.redhat.com
Tue Nov 6 19:41:21 2001


> > How can I add more fields?
> > 
> > Example: Create new item... I want more than just Product
> > Name, Description, Category, Price, Weight, etc.
> > 
> > Modify which files to accomplish this?
> > 
> > Jim.
> 
> Below is a HOWTO posted to the list a while back.
> 
> Dan Browning

Okay, that one wasn't very verbose.  Here's three more: 

Zack Johson:  (TIPS: Adding a new mysql table to IC)
	
http://interchange.redhat.com/archive/interchange-users/2001/msg09174.ht
ml
Corey Gilmore: modifying columns
	(below)
Mark Johnson: general description
	(below even further)

I hope that helps,

Dan Browning
Kavod Technologies




From: interchange-users-admin@interchange.redhat.com on behalf of Corey
Gilmore [cfg@dln.uvm.edu]
Sent: Thursday, September 27, 2001 7:20 AM
To: interchange-users@interchange.redhat.com
Subject: Tips and Tricks -- Modifying Columns (was Re: [ic] TIPS: Adding
a new mysql table to IC)

On Thu, 27 Sep 2001, Zack Johnson wrote:

> > I know I've fought this before.  Like if you add a column in mysql
and
>
> Not to be a bugbear, but this is beyond the scope of my little
micro-HOWTO
> on adding new tables.  You are talking about modifying existing
tables.
> Perhaps you could write-up a micro-HOWTO on modifying mysql tables?

Using IC 4.6.5, when I want to add a new column to the products
database,
I do this:

Load mysql, add a new column.

ALTER TABLE products ADD COLUMN prod_summary varchar(255);

The column is now in the database.

Edit catalogdir/catalog/dbconf/mysql/products.mysql

It should look something like
# MiniVend database definition
Database  products  products.txt __SQLDSN__
#ifdef SQLUSER
Database  products  USER         __SQLUSER__
#endif
#ifdef SQLPASS
Database  products  PASS         __SQLPASS__
#endif
Database  products  KEY          sku
...

We need to add our new column to this list
Add
Database  products  COLUMN_DEF   "prod_summary=(VARCHAR255)"
to the end of the file, save changes and close.

Here, I Apply Changes within the Admin UI.  This may not be necessary,
but
doesn't seem to hurt.

I jump over to the Admin UI, and goto the Administration section.
Choose Knar and edit the variable table (default).

Search for the UI_ITEM_FIELDS variable.

It will resemble
sku description comment category type image display price nontaxable
related featured required inactive weight shipping

These fields are the ones that are shown when you edit/create a product.
If you only wanted to view/edit the sku, description, comment and
category
you would just add those fields.

The order the column names appear in the UI_ITEM_FIELDS variable
determines the order they will appear in when an Item is edited.

Add prod_summary (our new column name) where ever you want it to show.
Lets put it after comment.

sku description comment prod_summary category type image display price
nontaxable related  featured required inactive weight shipping

Click OK.  Now to synchronize the products.txt with the database, you
need
to export.


Goto Tables in the Admin UI, and export the products table using the
default settings.  I Apply Changes once more here.

Now go and edit an item.  The new field prod_summary will appear.  Click
'meta' and you can edit your display settings.

I've found (with 4.6.5) that after I edit the meta for the field, it
returns me to the previous page - without any other fields.  I click OK
until I return to the main Items page, and THEN the meta information is
saved.

This is a little rough, and some of the information may be extraneous,
but I have finance homework due in 30 minutes ;)

.cfg



#########################################
#########################################



I missed the beginning of this discussion, so I'm not sure exactly where
your problem lies. But, I can give you an overview of this particular
question.


There are two equally important portions of a table definition in
Interchange if you are using a SQL database. There is the dbconf file,
which defines the database-dependent definitions of the table, and there
is the data file, which defines the field names (mandatory) and the
start-up data (optional). So, at a minimum, you need a dbconf file which
defines the DSN, and a data file that has all the fields present. If
this is all you have, then your data file must be tab delimited, and the
first field in your data file is assumed to be the primary key.


Beyond this, you can define any number of various parameters about your
table in the dbconf file. You can specify which field is the KEY, you
can declare a DEFAULT_TYPE, which will be applied to every field found
in your data file unless you supply an independent COLUMN_DEF. There are
many other definitions you can apply in the dbconf file, too. Check out
http://developer.akopia.com/cgi-bin/ic/dev/icdatabase


So, when Interchange starts up and sees a table that has a data file and
dbconf file, it checks for a file named table_name.sql in your products/
dir. If it does not find one, it will DROP the table in the database,
CREATE a new one according to the parameters set in the dbconf file and
the field names from the data file, and INSERT any rows of data that are
in the data file. If it does find the .sql file, it will pass over the
DROP, CREATE, and INSERT portion.


You can define a table to use only the data it already has, essentially
behaving by default as though the .sql file is always present, by the
catalog directive 'NoImport  table_name'. This will ensure that
pre-existing data are NEVER removed from the DROP, CREATE sequence. See
http://developer.akopia.com/cgi-bin/ic/dev/icconfig_120.html


Even in the case of using a NoImport table, you should still have data
file with all your fields defined. Interchange maintains its own
metadata about the tables, and field names are derived by default from
the data file. It may be the case that IC will use the SQL table to
determine field names under certain circumstances, but I would not rely
on that.



-- 
Mark Johnson
Senior Systems Architect - Professional Services
Red Hat, Inc.