LemonStand Documentation

shop:onGetCustomerFieldOptions event

The shop:onGetCustomerFieldOptions event allows to populate drop-down, radio- or checkbox list fields, which you added with the shop:onExtendCustomerForm event, with custom options. Usually you do not need to use this event for fields which represent data relations. But if you want a standard field (corresponding an integer-typed database column, for example), to be rendered as a drop-down list, you should handle this event in your module.

The event handler should accept 2 parameters - the field name and a current field value. If the current field value is -1, the handler should return an array containing a list of options. If the current field value is not -1, the handler should return a string, corresponding the value.

Event handler example:

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:onGetCustomerFieldOptions', $this, 'get_customer_field_options');
}

public function extend_customer_model($customer, $context)
{
   $customer->define_column('x_drop_down', 'Some drop-down menu');
}

public function extend_customer_form($customer, $context)
{
   $customer->add_form_field('x_drop_down')->tab('Customer')->renderAs(frm_dropdown);
}

public function get_customer_field_options($field_name, $current_key_value)
{
  if ($field_name == 'x_drop_down')
  {
    $options = array(
      0 => 'Option 1',
      1 => 'Option 2',
      2 => 'Option 3'
    );
    
    if ($current_key_value == -1)
      return $options;
    
    if (array_key_exists($current_key_value, $options))
      return $options[$current_key_value];
  }
}

Next: shop:onExtendCustomerPreviewToolbar event
Previous: cms:onExtendPageForm event
Return to Handling LemonStand events