Redirect to import CSV after create a new list

assuncao

Member
I'd like if is it easy to redirect the customer to import a CSV file right after a new list was created? Currently it is is redirected to the list update. I'm developer, but as this system is huge, I didn't find where I should change to make it possible. Any help would be appreciated.
 
I made it! I just don't know if this is the best way, I added the following code to line 27 of customer/views/lists/form.php:

if (!$list->isNewRecord) {
$this->redirect("/customer/lists/".$list->list_uid."/import");
}

EDIT: if someone is looking forward this workaround, please check bellow the solution provided by twisted1919. That's the correct way!
 
Last edited:
Here's the right way to do it, via an extension:
PHP:
if ( Yii::app()->apps->isAppName('customer') ) {
   
Yii::app()->hooks->addAction('controller_action_save_data', function($collection){
    if ( $collection->controller->id != 'lists' ||  $collection->controller->action->id != 'create' ) {
        return;
    }
    if ( ! $collection->success ) {
       return;
    }
    $list = $collection->list;
    $collection->controller->redirect(array('list_import/index', 'list_uid' => $list->list_uid));
});

}

You can put this code in an extension, or you can create a file in apps called custom-init.php and place it there.
This is also safe at upgrades.
 
Here's the right way to do it, via an extension:
PHP:
if ( Yii::app()->apps->isAppName('customer') ) {
  
Yii::app()->hooks->addAction('controller_action_save_data', function($collection){
    if ( $collection->controller->id != 'lists' ||  $collection->controller->action->id != 'create' ) {
        return;
    }
    if ( ! $collection->success ) {
       return;
    }
    $list = $collection->list;
    $collection->controller->redirect(array('list_import/index', 'list_uid' => $list->list_uid));
});

}

You can put this code in an extension, or you can create a file in apps called custom-init.php and place it there.
This is also safe at upgrades.
Just some observation: the file is init-custom.php, not custom-init.php. Thank you a lot! Works really fine! That's really the best way to do!
 
Back
Top