|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright © 2016 Ihor Vansach ([email protected]). All rights reserved. |
| 3 | + * Copyright © 2015-2017 Ihor Vansach ([email protected]). All rights reserved. |
4 | 4 | * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). |
5 | 5 | * |
6 | 6 | * Glory to Ukraine! Glory to the heroes! |
@@ -80,7 +80,7 @@ abstract class Actions extends \Magento\Backend\App\Action |
80 | 80 | */ |
81 | 81 | public function execute() |
82 | 82 | { |
83 | | - $_preparedActions = ['index', 'grid', 'new', 'edit', 'save', 'delete', 'config', 'massStatus']; |
| 83 | + $_preparedActions = ['index', 'grid', 'new', 'edit', 'save', 'duplicate', 'delete', 'config', 'massStatus']; |
84 | 84 | $_action = $this->getRequest()->getActionName(); |
85 | 85 | if (in_array($_action, $_preparedActions)) { |
86 | 86 | $method = '_'.$_action.'Action'; |
@@ -246,6 +246,34 @@ public function _saveAction() |
246 | 246 |
|
247 | 247 | } |
248 | 248 |
|
| 249 | + /** |
| 250 | + * Duplicat action |
| 251 | + * @return void |
| 252 | + */ |
| 253 | + protected function _duplicateAction() |
| 254 | + { |
| 255 | + try { |
| 256 | + $originModel = $this->_getModel(); |
| 257 | + if (!$originModel->getId()) { |
| 258 | + throw new \Exception("Item is not longer exist.", 1); |
| 259 | + } |
| 260 | + |
| 261 | + $model = $originModel->duplicate(); |
| 262 | + |
| 263 | + $this->messageManager->addSuccess(__('%1 has been duplicated.', $model->getOwnTitle())); |
| 264 | + $this->_redirect('*/*/edit', [$this->_idKey => $model->getId()]); |
| 265 | + } catch (Exception $e) { |
| 266 | + $this->messageManager->addException( |
| 267 | + $e, |
| 268 | + __('Something went wrong while saving this %1. %2', |
| 269 | + strtolower($model->getOwnTitle()), |
| 270 | + $e->getMessage() |
| 271 | + ) |
| 272 | + ); |
| 273 | + $this->_redirect('*/*/edit', [$this->_idKey => $originModel->getId()]); |
| 274 | + } |
| 275 | + } |
| 276 | + |
249 | 277 | /** |
250 | 278 | * Before model Save action |
251 | 279 | * @return void |
|
0 commit comments