Difference between revisions of "How to add fields to a product"

From aMember Pro Documentation
Jump to: navigation, search
 
Line 1: Line 1:
 
Add this code to [[site.php file]]:
 
Add this code to [[site.php file]]:
 
<source>
 
<source>
<?php
 
 
Am_Di::getInstance()->productTable->customFields()->add(new Am_CustomFieldText('field_name', 'Field Title'));
 
Am_Di::getInstance()->productTable->customFields()->add(new Am_CustomFieldText('field_name', 'Field Title'));
 
</source>
 
</source>

Latest revision as of 03:06, 3 November 2015

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');