-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Msi stock ui aggregation #39
Changes from 76 commits
be1d21e
dfd6a47
67775b7
fbb4515
1755600
3514312
35a65fb
01e5081
9cb1802
e712957
d51900e
04b31b5
b659579
9788440
2530ee2
9fab8e2
314a859
394aa38
81f5921
e600552
d2d5028
4947eb3
b27c53b
2ec7748
32f80ff
1e020f2
78cec9f
aad1755
d0a7ede
ac93d41
7630364
629bfa8
7b5a1a1
06ac206
fc83584
984ce8b
5296b0d
760cca9
5647da2
0acae24
c995aee
d18bf44
7603f58
10cd6bf
f3de3dc
7272f26
1e39c8f
e6b74fb
e170309
8dd48da
d9230f8
ae3dfef
be564cd
a0f2f49
a88fe92
67da5db
3c6bde2
2017309
e3061b7
46f4835
855d483
866b7e1
f6012a0
d2e743f
66cd1cd
1cac332
aa9eb08
725112d
dd8ef3a
4be0150
b0d34c1
1738b3a
1b93290
73de6f4
e1ced8d
268a279
009a2b1
9175a99
770bc26
90d0194
e1ea6e5
956747b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
|
||
/** | ||
* Class Edit | ||
* Edit Controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better not to provide such comments, because developer undestands that it's it's better to provide description what the class does or responsible for , to make description valueable |
||
*/ | ||
class Edit extends Action | ||
{ | ||
|
@@ -42,7 +42,7 @@ public function __construct( | |
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
use Magento\Framework\Controller\ResultFactory; | ||
|
||
/** | ||
* Class Index | ||
* Index Controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you give such description, you should specify Index Controller of which Entity. This is Source Index Controller. |
||
*/ | ||
class Index extends Action | ||
{ | ||
|
@@ -20,7 +20,7 @@ class Index extends Action | |
const ADMIN_RESOURCE = 'Magento_Inventory::source'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
|
||
/** | ||
* Class InlineEdit | ||
* InlineEdit Controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
*/ | ||
class InlineEdit extends Action | ||
{ | ||
|
@@ -51,7 +51,7 @@ public function __construct( | |
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,14 @@ | |
use Magento\Framework\Api\DataObjectHelper; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Framework\Exception\InputException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Registry; | ||
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; | ||
use Magento\InventoryApi\Api\SourceRepositoryInterface; | ||
|
||
/** | ||
* Class Save | ||
* Save Controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix description |
||
*/ | ||
class Save extends Action | ||
{ | ||
|
@@ -28,11 +27,6 @@ class Save extends Action | |
*/ | ||
const ADMIN_RESOURCE = 'Magento_Inventory::source'; | ||
|
||
/** | ||
* Registry source_id key | ||
*/ | ||
const REGISTRY_SOURCE_ID_KEY = 'source_id'; | ||
|
||
/** | ||
* @var SourceInterfaceFactory | ||
*/ | ||
|
@@ -48,11 +42,6 @@ class Save extends Action | |
*/ | ||
private $dataObjectHelper; | ||
|
||
/** | ||
* @var Registry | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var CarrierRequestDataHydrator | ||
*/ | ||
|
@@ -64,39 +53,34 @@ class Save extends Action | |
* @param SourceRepositoryInterface $sourceRepository | ||
* @param DataObjectHelper $dataObjectHelper | ||
* @param CarrierRequestDataHydrator $carrierRequestDataHydrator | ||
* @param Registry $registry | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
SourceInterfaceFactory $sourceFactory, | ||
SourceRepositoryInterface $sourceRepository, | ||
DataObjectHelper $dataObjectHelper, | ||
Registry $registry, | ||
CarrierRequestDataHydrator $carrierRequestDataHydrator | ||
) { | ||
parent::__construct($context); | ||
$this->sourceFactory = $sourceFactory; | ||
$this->sourceRepository = $sourceRepository; | ||
$this->dataObjectHelper = $dataObjectHelper; | ||
$this->registry = $registry; | ||
$this->carrierRequestDataHydrator = $carrierRequestDataHydrator; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
$resultRedirect = $this->resultRedirectFactory->create(); | ||
$requestData = $this->getRequest()->getParam('general'); | ||
if ($this->getRequest()->isPost() && $requestData) { | ||
$requestData = $this->getRequest()->getParams(); | ||
if ($this->getRequest()->isPost() && !empty($requestData['general'])) { | ||
try { | ||
$sourceId = !empty($requestData[SourceInterface::SOURCE_ID]) | ||
? $requestData[SourceInterface::SOURCE_ID] : null; | ||
$sourceId = !empty($requestData['general'][SourceInterface::SOURCE_ID]) | ||
? $requestData['general'][SourceInterface::SOURCE_ID] : null; | ||
|
||
$sourceId = $this->processSave($sourceId, $requestData); | ||
// Keep data for plugins on Save controller. Now we can not call separate services from one form. | ||
$this->registry->register(self::REGISTRY_SOURCE_ID_KEY, $sourceId); | ||
|
||
$this->messageManager->addSuccessMessage(__('The Source has been saved.')); | ||
$this->processRedirectAfterSuccessSave($resultRedirect, $sourceId); | ||
|
@@ -107,11 +91,8 @@ public function execute() | |
} catch (CouldNotSaveException $e) { | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
$this->processRedirectAfterFailureSave($resultRedirect, $sourceId); | ||
} catch (InputException $e) { | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
$this->processRedirectAfterFailureSave($resultRedirect, $sourceId); | ||
} catch (Exception $e) { | ||
$this->messageManager->addErrorMessage(__('Could not save source')); | ||
$this->messageManager->addErrorMessage(__('Could not save source.')); | ||
$this->processRedirectAfterFailureSave($resultRedirect, $sourceId); | ||
} | ||
} else { | ||
|
@@ -134,8 +115,8 @@ private function processSave($sourceId, array $requestData) | |
/** @var SourceInterface $source */ | ||
$source = $this->sourceFactory->create(); | ||
} | ||
$this->dataObjectHelper->populateWithArray($source, $requestData, SourceInterface::class); | ||
$source = $this->carrierRequestDataHydrator->hydrate($source, $requestData); | ||
$this->dataObjectHelper->populateWithArray($source, $requestData['general'], SourceInterface::class); | ||
$source = $this->carrierRequestDataHydrator->hydrate($source, $requestData['general']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have two separate hydration here in the controller code? $this->dataObjectHelper->populateWithArray($source, $requestData['general'], SourceInterface::class);
$source = $this->carrierRequestDataHydrator->hydrate($source, $requestData['general']); controlelr should accept the only Hydrator dependency . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to discuss how to do it better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
$sourceId = $this->sourceRepository->save($source); | ||
return $sourceId; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Inventory\Controller\Adminhtml\Stock; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Backend\Model\View\Result\Page; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\InventoryApi\Api\StockRepositoryInterface; | ||
use Magento\InventoryApi\Api\Data\StockInterface; | ||
|
||
/** | ||
* Edit Controller | ||
*/ | ||
class Edit extends Action | ||
{ | ||
/** | ||
* @see _isAllowed() | ||
*/ | ||
const ADMIN_RESOURCE = 'Magento_Inventory::stock'; | ||
|
||
/** | ||
* @var StockRepositoryInterface | ||
*/ | ||
private $stockRepository; | ||
|
||
/** | ||
* @param Context $context | ||
* @param StockRepositoryInterface $stockRepository | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
StockRepositoryInterface $stockRepository | ||
) { | ||
parent::__construct($context); | ||
$this->stockRepository = $stockRepository; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
$stockId = $this->getRequest()->getParam(StockInterface::STOCK_ID); | ||
try { | ||
$stock = $this->stockRepository->get($stockId); | ||
|
||
/** @var Page $result */ | ||
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); | ||
$result->setActiveMenu('Magento_Inventory::stock') | ||
->addBreadcrumb(__('Edit Stock'), __('Edit Stock')); | ||
$result->getConfig() | ||
->getTitle() | ||
->prepend(__('Edit Stock: %1', $stock->getName())); | ||
} catch (NoSuchEntityException $e) { | ||
/** @var Redirect $result */ | ||
$result = $this->resultRedirectFactory->create(); | ||
$this->messageManager->addErrorMessage( | ||
__('Stock with id "%1" does not exist.', $stockId) | ||
); | ||
$result->setPath('*/*'); | ||
} | ||
return $result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Inventory\Controller\Adminhtml\Stock; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\Model\View\Result\Page; | ||
use Magento\Framework\Controller\ResultFactory; | ||
|
||
/** | ||
* Index Controller | ||
*/ | ||
class Index extends Action | ||
{ | ||
/** | ||
* @see _isAllowed() | ||
*/ | ||
const ADMIN_RESOURCE = 'Magento_Inventory::stock'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
/** @var Page $resultPage */ | ||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); | ||
$resultPage->setActiveMenu('Magento_Inventory::stock') | ||
->addBreadcrumb(__('Sources'), __('List')); | ||
$resultPage->getConfig()->getTitle()->prepend(__('Manage Stock')); | ||
return $resultPage; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Inventory\Controller\Adminhtml\Stock; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Controller\Result\Json; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\EntityManager\HydratorInterface; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong dependency, it's better to avoid dependencies on EntityiManager component, because it's deprecated one. In this particular case - you can make hydration with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\InventoryApi\Api\StockRepositoryInterface; | ||
use Magento\InventoryApi\Api\Data\StockInterface; | ||
|
||
/** | ||
* InlineEdit Controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix description for all controller classes |
||
*/ | ||
class InlineEdit extends Action | ||
{ | ||
/** | ||
* @see _isAllowed() | ||
*/ | ||
const ADMIN_RESOURCE = 'Magento_Inventory::stock'; | ||
|
||
/** | ||
* @var HydratorInterface | ||
*/ | ||
private $hydrator; | ||
|
||
/** | ||
* @var StockRepositoryInterface | ||
*/ | ||
private $stockRepository; | ||
|
||
/** | ||
* @param Context $context | ||
* @param HydratorInterface $hydrator | ||
* @param StockRepositoryInterface $stockRepository | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
HydratorInterface $hydrator, | ||
StockRepositoryInterface $stockRepository | ||
) { | ||
parent::__construct($context); | ||
$this->hydrator = $hydrator; | ||
$this->stockRepository = $stockRepository; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
$errorMessages = []; | ||
$request = $this->getRequest(); | ||
$requestData = $request->getParam('items', []); | ||
|
||
if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) { | ||
foreach ($requestData as $itemData) { | ||
try { | ||
$stock = $this->stockRepository->get( | ||
$itemData[StockInterface::STOCK_ID] | ||
); | ||
$stock = $this->hydrator->hydrate($stock, $itemData); | ||
$this->stockRepository->save($stock); | ||
} catch (NoSuchEntityException $e) { | ||
$errorMessages[] = __( | ||
'[ID: %1] The Stock does not exist.', | ||
$itemData[StockInterface::STOCK_ID] | ||
); | ||
} catch (CouldNotSaveException $e) { | ||
$errorMessages[] = | ||
__('[ID: %1] ', $itemData[StockInterface::STOCK_ID]) | ||
. $e->getMessage(); | ||
} | ||
} | ||
} else { | ||
$errorMessages[] = __('Please correct the data sent.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please correct the sent data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
} | ||
|
||
/** @var Json $resultJson */ | ||
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
$resultJson->setData([ | ||
'messages' => $errorMessages, | ||
'error' => count($errorMessages), | ||
]); | ||
return $resultJson; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Populate Source by carrier code links