Add fields to a product
Add this code to site.php file:
//Add Text Field
Am_Di::getInstance()->productTable->customFields()
->add(new Am_CustomFieldText('field_name', 'Field Title'));
//Add Select Field
Am_Di::getInstance()->productTable->customFields()
->add(new Am_CustomFieldSelect('another_name', 'Another Title', null, null, ['options' => ['1' => '11', '2' => '22']]));
List of available additional field types:
- Am_CustomFieldHidden
- Am_CustomFieldText
- Am_CustomFieldTextarea
- Am_CustomFieldSelect
- Am_CustomFieldMulti_Select
- Am_CustomFieldRadio
- Am_CustomFieldCheckbox
- Am_CustomFieldSingle_Checkbox
- Am_CustomFieldDate
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');