Custom Fields In Product, How To

we need to add some custom fields to the product. and be able to import/export those fields.



I have added features for these fields and can import/export, but do not like them showing under ‘feature’ in the product UI on the storefront.



I can add them to the product table, but if the product table changes, then I am exposed during any upgrades… ( I added the fields and did an addon with schemas/exim to map the fields to user field names. import/export work. )… have to develop UI for backend and front end.



these should really be in their own table, created with addon install.

I have done that… but don’t know how to map the schema/exim to point the logical fields to the separate table fields… the separate table uses the product table product id as the key to the additional data.

we do not want a two pass import/export… this is multi-vendor, don’t want to train them on these kinds of issues.



want csv column name matches product data field name on import/export.



I can’t post to the developer section



Sam

hi Sam,



you can check file app/addons/seo/schemas/exim/products.post.php

$schema['references'] is used to make mysql join to your new table

$schema['export_fields']['SEO name'] - this element is needed to add new column for export/import



best regards,

WSA team

thank you vrey interesting… there are a number of statements in the SOE products.post.php file



is there any doc on these? I don't understand the relationship between the references and the use of the function

no documentation for this yet

please send here scheme of your new database table so we could assist

two tables, created by addon install.

second table initial data inserted by addon install.



table1

numbers used in product search if present


# id number of product extended by this table row
product_id int not null default 0

# extended part numbers
# none required. all text..
oem_number text not null default ''
alternate_number text not null default ''
nantional_stock_number text not null default ''

# some qualifier data for the part
# vendor would use qualifier value string on import, get qualifier value on export

# product admin shows this as an optional single selection dropdown
# zero means no selection
# qualifier table id number, type = 1
qualifier_type_1 int not null default 0

# qualifier table id number, type = 2
# product admin shows this as an optional single selection dropdown
qualifier_type_2 int not null default 0

table 2
qualifier_type_table
# want to admin the two types in separate UI like feature or option
# might want to add another similar type later


# unique id of each row
# used in table 1 qualifier fields
id int(11) not null default 0 auto_increment

# either 1 or 2, could be extended in future
type int not null default 0

# the value for this row
# if the value changes, don't need to update 100,000 product records
value text not null default ''

# the description of this value, could be translateable
description text not null default ''

here is correct reference:


$schema['references']['your_table1'] = array(
'reference_fields' => array('product_id' => '#key'),
'join_type' => 'LEFT'
);




using this reference you can export/import any column from your_table1, e.g.



$schema['export_fields']['Your field name'] => array(

'table' => 'your_table1',

'db_field' => '[color=#282828][font=arial, verdana, tahoma, sans-serif]oem_number text[/font][/color]',

);



using of fields from your_table2 is a complex task and advanced queries are needed so we advise you to check Features field in the “app/schemas/exim/products.php” file



if more details are needed, please don't hesitate to contact us



best regards,

WSA team

thank you. I understand about the complexity of the related table… will contact



features UI would work nicely, if not called 'features'!

you are welcome!

I have the secondary table working for import/export…



is there doc on what the available data items are for passing to the functions?



#key and #this, see a couple examples of %something%.



anyhow, on to adding content to the product page.



is there an easy sample the does the end to end…



data from the database , then add something to the product …



the tutorial addes something to the admin page, not a usable page for product or category, or…



seems there needs to be some tpl file the maps variables to html

and then some script that gets data out of the database.



also need to read in admin of product to put data back into the database.



don't want a tab, like feature… as this data is used so often.

well, this turned out not to be too bad.



I ended up needing a hook in the products/update.tpl file



an addon packaging question



when you need to put in a hookfile, the location is INSIDE the actual folder for the product…



the doc says



An add-on can use the following directories in addition to the required one:[indent][list]

[]var/themes_repository/basic/templates/addons/—customer area templates

[
]design/backend/templates/addons/—administration panel templates

[*]var/themes_repository/basic/mail/templates/addons/—e-mail templates

[/list][/indent]



does this mean in the addon zip file to have the 'var' and design folder trees?

isn't that a security risk, some addon can just whack product files in the same tree?

Themes go in var, backbend goes in design. Any add-on can include anything it wants in its archive

Themes go in var, backbend goes in design. Any add-on can include anything it wants in its archive. No greater security risk than installing an add-on to begin with.

can I modify the product files in an addon's addon.xml? I think I can call functions as part of install



I need to insert my hook in the product update template if its not there.



I can do it with grep and sed. never tried this with python.

[quote name='sdetweil' timestamp='1431224724' post='213854']

can I modify the product files in an addon's addon.xml? I think I can call functions as part of install



I need to insert my hook in the product update template if its not there.



I can do it with grep and sed. never tried this with python.

[/quote]



the anwer is yes!.. just added it to init.php

read all the lines into an array… 500 is not too much

loop thru the lines to find the one with the right tag,

back up a few, check thru the few lines for a hook definition.

if not present, insert into the array the new line in the right spot



then later, if we changed the array, write a new file

rename the original file, rename the new to be the original name



careful, init.php is launched with some other folder as current directory, so use the filename to

figure out where the file to modify is located relative to the addon install location

Yes, you can have a 'functions' container within the xml file and use preinstall, install and uninstall for the 'on' verb.

Generally addons add data to products using the 'product_data' table and using a unique 'type' for the addon. The addon then has pre/post controllers that retrieve that data for the products and they are then generally managed in the 'Add-ons' area.



It would be very rare for you to need to modify the product templates or products table to get data support for your addon. Suggest you look at how various addons manage data such as SEO and/or bestsellers, etc. I'm assuming you've read the documenation on addon.xml and for how to add an addon to cs-cart.

[quote name='tbirnseth' timestamp='1431286182' post='213885']

Yes, you can have a 'functions' container within the xml file and use preinstall, install and uninstall for the 'on' verb.

Generally addons add data to products using the 'product_data' table and using a unique 'type' for the addon. The addon then has pre/post controllers that retrieve that data for the products and they are then generally managed in the 'Add-ons' area.



It would be very rare for you to need to modify the product templates or products table to get data support for your addon. Suggest you look at how various addons manage data such as SEO and/or bestsellers, etc. I'm assuming you've read the documenation on addon.xml and for how to add an addon to cs-cart.

[/quote]



thanks… I have an addon, and it works well. The way we wanted to display the extra data, we needed a hook in the backend product update template. All works great with the added hook to position the data where we want it.



just needed to add the one line to create the template hook as part of the addon install, instead of doing it by hand.

one more thing to do… add the custom part number fields to the search engine.