This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

shop:onExtendOptionMatrix event

Triggered by Shop_OptionMatrixRecord
Author LemonStand eCommerce Inc.

Event handler signature

public array event_onExtendOptionMatrix(Shop_OptionMatrixRecord $model, string $context)
$model Shop_OptionMatrixRecord option Matrix record.
$context string specifies the form execution context.
{return} array returns an array of column definitions.
Allows to add new columns to the Option Matrix table. Before you add new columns you should add corresponding columns to shop_option_matrix_records table, unless you are adding an image column. The event handler should return an array of new column definitions. Array keys should correspond the table column names. Array values are associative arrays containing the column configuration. Example:
public function subscribeEvents() 
{
  Backend::$events->add_event('shop:onExtendOptionMatrix', $this, 'extend_option_matrix');
}

public function extend_option_matrix($model, $context) 
{
  $result = array(
    'x_custom_int_column'=>array(
        'title'=>'Custom integer', 
        'type'=>'text', 
        'align'=>'right', 
        'width'=>50, 
        'column_group'=>'Custom'
    ),
    'x_custom_date_column'=>array(
        'title'=>'Custom date', 
        'align'=>'right', 
        'type'=>'text', 
        'width'=>95, 
        'editor_class'=>'Db_GridDateEditor', 
        'column_group'=>'Custom'
    ),
    'x_custom_drop_down'=>array(
        'title'=>'Custom date', 
        'type'=>'dropdown', 
        'width'=>100, 
        'column_group'=>'Custom', 
        'option_keys'=>array(1, 2), 
        'option_values'=>array('Value 1', 'Value 2')
    )
  );

  return $result;
}
Column definitions support the following parameters:
  • title - defines the column title, required.
  • type - defines the column type, required. Supported values are text, dropdown, checkbox, popup (applicable for image columns only).
  • align - defines the column value alignment, required. Supported values are "left", "right".
  • width - defines the column width, required.
  • column_group - defines the column group name, required.
  • editor_class - class name for a popup editor. Required value for date columns is Db_GridDateEditor. It is the only supported popup editor for API fields.
  • option_keys - defines option keys for drop-down menus. Required if the column type is dropdown.
  • option_values - defines option values for drop-down menus. Required if the column type is dropdown.
  • editor_class - specifies a popup editor class. Required if the column type is popup. The only supported value is Db_GridImagesEditor.
  • images_field - specifies an images column name. Required if the editor_class is Db_GridImagesEditor.
API columns are supported by CSV operations and can be accessed with Shop_Product::om(), Shop_OrderItem::om() and Shop_CartItem::om() methods.
In order to add an images field you should first define an images relation with the shop:onExtendOptionMatrixRecordModel event. The following example adds Extra Images column to the Option Matrix:
public function subscribeEvents() 
{
  Backend::$events->add_event('shop:onExtendOptionMatrix', $this, 'extend_option_matrix');
  Backend::$events->add_event('shop:onExtendOptionMatrixRecordModel', $this, 'extend_option_matrix_model');
}

public function extend_option_matrix($model, $context) 
{
  $result = array(
    'x_extra_images'=>array(
      'title'=>'Extra image', 
      'type'=>'popup', 
      'editor_class'=>'Db_GridImagesEditor', 
      'images_field'=>'x_extra_images', 
      'width'=>100, 
      'column_group'=>'Custom')
  );

  if ($context != 'grid')
    $model->add_form_field('x_extra_images')->renderAs(frm_file_attachments)->renderFilesAs('image_list');

  return $result;
}

public function extend_option_matrix_model($model, $context)
{
  $front_end = Db_ActiveRecord::$execution_context == 'front-end';

  $model->add_relation('has_many', 'x_extra_images', array(
    'class_name'=>'Db_File', 
    'foreign_key'=>'master_object_id',
    'conditions'=>"master_object_class='Shop_OptionMatrixRecord' and field='x_extra_images'",
    'order'=>'sort_order, id',
    'delete' => true)
  );

  $model->define_multi_relation_column('x_extra_images', 'x_extra_images', 'Extra images', $front_end ? null : '@name')->invisible();
}