How to add fields to a product

From aMember Pro Documentation
Revision as of 03:06, 3 November 2015 by Caesar (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Add this code to site.php file:

Am_Di::getInstance()->productTable->customFields()->add(new Am_CustomFieldText('field_name', 'Field Title'));

List of available additional field types:

  • Am_CustomFieldHidden
  • Am_CustomFieldText
  • Am_CustomFieldSelect
  • Am_CustomFieldRadio
  • Am_CustomFieldCheckbox

To retrieve value of such field for specific product from product record you can use the following code:

$product = Am_Di::getInstance()->productTable->load(1); //retrieve product record with id = 1
$product->data()->get('field_name');