User Tools

Site Tools


urapidflow:customization:observer

Sample code for Observer used to add a column to profile on the fly

The following must be part of Magento extension and method should be registered as observer to urapidflow_profile_action event:

Observer.php
<?php
 
class Unirgy_RfUrlPrice_Model_Observer
{
    /**
     * @var string
     */
    protected $columnName = 'sample_column';
 
    /**
     * @param Varien_Event_Observer $observer
     */
    public function urapidflow_profile_action( $observer )
    {
        $action  = $observer->getData( 'action' );
        $profile = $observer->getData( 'profile' );
        $proceed = $profile->getData( 'options/export/conf_child_url' );
        if ( !$proceed ) {
            return;
        }
 
        switch ( $action ) {
            case 'start':
                $columns = $profile->getColumns();
                foreach ( $columns as $col ) {
                    if ( $col[ 'field' ] == $this->columnName ) {
                        // column present, no need to do anything
                        return;
                    }
                }
 
                $columns[ ] = array(
                    'field' => $this->columnName
                );
 
                $profile->setData( 'columns', $columns );
                break;
            case 'stop': // in case we don't want to save the column, we remove it here
            case 'finish':
                $columns = $profile->getColumns();
                foreach ( $columns as $idx => $col ) {
                    if ( $col[ 'field' ] == $this->columnName ) {
                        unset( $columns[ $idx ] );
                    }
                }
 
                $profile->setData( 'columns', $columns );
                break;
            default :
                return;
                break;
        }
    }
}
urapidflow/customization/observer.txt · Last modified: 2014/04/29 15:39 by jamby77