User Tools

Site Tools


urapidflow:customization:observer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

urapidflow:customization:observer [2014/04/29 15:39]
jamby77 created
urapidflow:customization:observer [2014/04/29 15:39] (current)
jamby77
Line 1: Line 1:
 +===== 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:
 +
 +<file php 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;
 +        }
 +    }
 +}
 +</file>
urapidflow/customization/observer.1398785955.txt.bz2 · by jamby77