1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Getnet. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See LICENSE for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Getnet\SubSellerMagento\Controller\Adminhtml\Subseller; |
10
|
|
|
|
11
|
|
|
use Magento\Framework\Controller\ResultFactory; |
12
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
13
|
|
|
|
14
|
|
|
class Save extends \Getnet\SubSellerMagento\Controller\Adminhtml\Subseller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Save Sub Seller and Data. |
18
|
|
|
* |
19
|
|
|
* @return \Magento\Backend\Model\View\Result\Redirect |
20
|
|
|
*/ |
21
|
|
|
public function execute() |
22
|
|
|
{ |
23
|
|
|
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ |
24
|
|
|
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); |
25
|
|
|
$subSellerPost = $this->getRequest()->getPostValue(); |
|
|
|
|
26
|
|
|
if ($subSellerPost) { |
27
|
|
|
$sellerId = $this->getRequest()->getParam('sellerid'); |
28
|
|
|
if ($sellerId) { |
29
|
|
|
try { |
30
|
|
|
$this->_subSellerRepository->get($sellerId); |
31
|
|
|
} catch (NoSuchEntityException $e) { |
32
|
|
|
unset($subSellerPost['sellerid']); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
try { |
37
|
|
|
$subSellerData = $this->subSellerConverter->populateSubSellerData($subSellerPost); |
38
|
|
|
$this->_subSellerRepository->save($subSellerData); |
39
|
|
|
|
40
|
|
|
$this->messageManager->addSuccess(__('You saved the sub seller.')); |
|
|
|
|
41
|
|
|
|
42
|
|
|
return $resultRedirect->setPath('*/*/'); |
43
|
|
|
} catch (\Magento\Framework\Exception\LocalizedException $e) { |
44
|
|
|
$this->_objectManager->get(\Magento\Backend\Model\Session::class)->setFormData($subSellerPost); |
45
|
|
|
$this->messageManager->addError($e->getMessage()); |
|
|
|
|
46
|
|
|
} catch (\Exception $e) { |
47
|
|
|
$this->messageManager->addError($e->getMessage()); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*'))); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $resultRedirect->setPath('subseller/subseller'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|