Determines whether a custom radio button or checkbox list option is checked.
This event should be handled if you added custom radio-button and or checkbox list fields with
event.
public function subscribeEvents() {
Backend::$events->addEvent('shop:onExtendCustomerModel', $this, 'extend_customer_model');
Backend::$events->addEvent('shop:onExtendCustomerForm', $this, 'extend_customer_form');
Backend::$events->addEvent('shop:onGetCustomerFieldState', $this, 'get_customer_field_state');
}
public function extend_customer_model($customer, $context) {
$customer->add_relation('has_and_belongs_to_many', 'test_manufacturers',
array('class_name'=>'Shop_Manufacturer', 'join_table'=>'test_customers_manufacturers',
'primary_key'=>'customer_id', 'foreign_key'=>'manufacturer_id'
));
$customer->define_multi_relation_column('test_manufacturers', 'test_manufacturers', 'Multiple manufacturers ', '@name');
}
public function extend_customer_form($customer, $context) {
$customer->add_form_field('test_manufacturers')->tab('Customer')->renderAs(frm_checkboxlist);
}
public function get_customer_field_state($field, $value, $customer) {
if ($field == 'test_manufacturers') {
foreach ($customer->test_manufacturers as $record) {
if ($record instanceof Db_ActiveRecord) {
if ($record->id == $value)
return true;
}
elseif ($record == $value)
return true;
}
return false;
}
}