Skip to content

Commit 994c7ed

Browse files
author
Valeriy Nayda
authored
Merge pull request #39 from magento-engcom/msi-stock-ui-aggregation
WIP: Msi stock ui aggregation
2 parents 9100fa9 + 956747b commit 994c7ed

File tree

94 files changed

+3907
-1419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3907
-1419
lines changed

app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\InventoryApi\Api\Data\SourceInterface;
1616

1717
/**
18-
* Class Edit
18+
* Edit Controller
1919
*/
2020
class Edit extends Action
2121
{
@@ -42,7 +42,7 @@ public function __construct(
4242
}
4343

4444
/**
45-
* {@inheritdoc}
45+
* @inheritdoc
4646
*/
4747
public function execute()
4848
{

app/code/Magento/Inventory/Controller/Adminhtml/Source/Index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Controller\ResultFactory;
1111

1212
/**
13-
* Class Index
13+
* Index Controller
1414
*/
1515
class Index extends Action
1616
{
@@ -20,7 +20,7 @@ class Index extends Action
2020
const ADMIN_RESOURCE = 'Magento_Inventory::source';
2121

2222
/**
23-
* {@inheritdoc}
23+
* @inheritdoc
2424
*/
2525
public function execute()
2626
{

app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
use Magento\Backend\App\Action;
99
use Magento\Backend\App\Action\Context;
10+
use Magento\Framework\Api\DataObjectHelper;
1011
use Magento\Framework\Controller\Result\Json;
1112
use Magento\Framework\Controller\ResultFactory;
12-
use Magento\Framework\EntityManager\HydratorInterface;
1313
use Magento\Framework\Exception\CouldNotSaveException;
1414
use Magento\Framework\Exception\NoSuchEntityException;
1515
use Magento\InventoryApi\Api\SourceRepositoryInterface;
1616
use Magento\InventoryApi\Api\Data\SourceInterface;
1717

1818
/**
19-
* Class InlineEdit
19+
* InlineEdit Controller
2020
*/
2121
class InlineEdit extends Action
2222
{
@@ -26,9 +26,9 @@ class InlineEdit extends Action
2626
const ADMIN_RESOURCE = 'Magento_Inventory::source';
2727

2828
/**
29-
* @var HydratorInterface
29+
* @var DataObjectHelper
3030
*/
31-
private $hydrator;
31+
private $dataObjectHelper;
3232

3333
/**
3434
* @var SourceRepositoryInterface
@@ -37,21 +37,21 @@ class InlineEdit extends Action
3737

3838
/**
3939
* @param Context $context
40-
* @param HydratorInterface $hydrator
40+
* @param DataObjectHelper $dataObjectHelper
4141
* @param SourceRepositoryInterface $sourceRepository
4242
*/
4343
public function __construct(
4444
Context $context,
45-
HydratorInterface $hydrator,
45+
DataObjectHelper $dataObjectHelper,
4646
SourceRepositoryInterface $sourceRepository
4747
) {
4848
parent::__construct($context);
49-
$this->hydrator = $hydrator;
49+
$this->dataObjectHelper = $dataObjectHelper;
5050
$this->sourceRepository = $sourceRepository;
5151
}
5252

5353
/**
54-
* {@inheritdoc}
54+
* @inheritdoc
5555
*/
5656
public function execute()
5757
{
@@ -65,7 +65,7 @@ public function execute()
6565
$source = $this->sourceRepository->get(
6666
$itemData[SourceInterface::SOURCE_ID]
6767
);
68-
$source = $this->hydrator->hydrate($source, $itemData);
68+
$this->dataObjectHelper->populateWithArray($source, $itemData, SourceInterface::class);
6969
$this->sourceRepository->save($source);
7070
} catch (NoSuchEntityException $e) {
7171
$errorMessages[] = __(
@@ -79,7 +79,7 @@ public function execute()
7979
}
8080
}
8181
} else {
82-
$errorMessages[] = __('Please correct the data sent.');
82+
$errorMessages[] = __('Please correct the sent data.');
8383
}
8484

8585
/** @var Json $resultJson */

app/code/Magento/Inventory/Controller/Adminhtml/Source/NewAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Controller\ResultFactory;
1212

1313
/**
14-
* Class NewAction
14+
* NewAction Controller
1515
*/
1616
class NewAction extends Action
1717
{
@@ -21,7 +21,7 @@ class NewAction extends Action
2121
const ADMIN_RESOURCE = 'Magento_Inventory::source';
2222

2323
/**
24-
* {@inheritdoc}
24+
* @inheritdoc
2525
*/
2626
public function execute()
2727
{

app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
use Exception;
99
use Magento\Backend\App\Action;
1010
use Magento\Backend\App\Action\Context;
11-
use Magento\Framework\Api\DataObjectHelper;
1211
use Magento\Framework\Controller\Result\Redirect;
1312
use Magento\Framework\Exception\CouldNotSaveException;
1413
use Magento\Framework\Exception\NoSuchEntityException;
15-
use Magento\Framework\Registry;
1614
use Magento\InventoryApi\Api\Data\SourceInterface;
1715
use Magento\InventoryApi\Api\Data\SourceInterfaceFactory;
1816
use Magento\InventoryApi\Api\SourceRepositoryInterface;
1917

2018
/**
21-
* Class Save
19+
* Save Controller
2220
*/
2321
class Save extends Action
2422
{
@@ -38,48 +36,38 @@ class Save extends Action
3836
private $sourceRepository;
3937

4038
/**
41-
* @var DataObjectHelper
39+
* @var SourceHydrator
4240
*/
43-
private $dataObjectHelper;
44-
45-
/**
46-
* @var CarrierRequestDataHydrator
47-
*/
48-
private $carrierRequestDataHydrator;
41+
private $sourceHydrator;
4942

5043
/**
5144
* @param Context $context
5245
* @param SourceInterfaceFactory $sourceFactory
5346
* @param SourceRepositoryInterface $sourceRepository
54-
* @param DataObjectHelper $dataObjectHelper
55-
* @param CarrierRequestDataHydrator $carrierRequestDataHydrator
47+
* @param SourceHydrator $sourceHydrator
5648
*/
5749
public function __construct(
5850
Context $context,
5951
SourceInterfaceFactory $sourceFactory,
6052
SourceRepositoryInterface $sourceRepository,
61-
DataObjectHelper $dataObjectHelper,
62-
CarrierRequestDataHydrator $carrierRequestDataHydrator
53+
SourceHydrator $sourceHydrator
6354
) {
6455
parent::__construct($context);
6556
$this->sourceFactory = $sourceFactory;
6657
$this->sourceRepository = $sourceRepository;
67-
$this->dataObjectHelper = $dataObjectHelper;
68-
$this->carrierRequestDataHydrator = $carrierRequestDataHydrator;
58+
$this->sourceHydrator = $sourceHydrator;
6959
}
7060

7161
/**
72-
* {@inheritdoc}
62+
* @inheritdoc
7363
*/
7464
public function execute()
7565
{
7666
$resultRedirect = $this->resultRedirectFactory->create();
7767
$requestData = $this->getRequest()->getParams();
7868
if ($this->getRequest()->isPost() && !empty($requestData['general'])) {
7969
try {
80-
$sourceId = !empty($requestData['general'][SourceInterface::SOURCE_ID])
81-
? $requestData['general'][SourceInterface::SOURCE_ID] : null;
82-
70+
$sourceId = $requestData['general'][SourceInterface::SOURCE_ID] ?? null;
8371
$sourceId = $this->processSave($sourceId, $requestData);
8472

8573
$this->messageManager->addSuccessMessage(__('The Source has been saved.'));
@@ -92,7 +80,7 @@ public function execute()
9280
$this->messageManager->addErrorMessage($e->getMessage());
9381
$this->processRedirectAfterFailureSave($resultRedirect, $sourceId);
9482
} catch (Exception $e) {
95-
$this->messageManager->addErrorMessage(__('Could not save source'));
83+
$this->messageManager->addErrorMessage(__('Could not save source.'));
9684
$this->processRedirectAfterFailureSave($resultRedirect, $sourceId);
9785
}
9886
} else {
@@ -115,8 +103,7 @@ private function processSave($sourceId, array $requestData)
115103
/** @var SourceInterface $source */
116104
$source = $this->sourceFactory->create();
117105
}
118-
$this->dataObjectHelper->populateWithArray($source, $requestData['general'], SourceInterface::class);
119-
$source = $this->carrierRequestDataHydrator->hydrate($source, $requestData);
106+
$source = $this->sourceHydrator->hydrate($source, $requestData);
120107

121108
$sourceId = $this->sourceRepository->save($source);
122109
return $sourceId;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use Magento\Shipping\Model\Config;
1414

1515
/**
16-
* Class CarrierRequestDataHydrator
16+
* Populate Source by carrier code links
1717
*/
18-
class CarrierRequestDataHydrator
18+
class SourceCarrierHydrator
1919
{
2020
/**
2121
* @var SourceCarrierLinkInterface
@@ -35,8 +35,6 @@ class CarrierRequestDataHydrator
3535
private $shippingConfig;
3636

3737
/**
38-
* CarrierRequestDataHydrator constructor
39-
*
4038
* @param SourceCarrierLinkInterfaceFactory $carrierLinkFactory
4139
* @param DataObjectHelper $dataObjectHelper
4240
* @param Config $shippingConfig
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Inventory\Controller\Adminhtml\Source;
7+
8+
use Magento\Framework\Api\DataObjectHelper;
9+
use Magento\InventoryApi\Api\Data\SourceInterface;
10+
11+
/**
12+
* Populate Source by data. Specified for form structure
13+
*
14+
* @api
15+
*/
16+
class SourceHydrator
17+
{
18+
/**
19+
* @var DataObjectHelper
20+
*/
21+
private $dataObjectHelper;
22+
23+
/**
24+
* @var SourceCarrierHydrator
25+
*/
26+
private $sourceCarrierHydrator;
27+
28+
/**
29+
* @param DataObjectHelper $dataObjectHelper
30+
* @param SourceCarrierHydrator $sourceCarrierHydrator
31+
*/
32+
public function __construct(
33+
DataObjectHelper $dataObjectHelper,
34+
SourceCarrierHydrator $sourceCarrierHydrator
35+
) {
36+
$this->dataObjectHelper = $dataObjectHelper;
37+
$this->sourceCarrierHydrator = $sourceCarrierHydrator;
38+
}
39+
40+
/**
41+
* @param SourceInterface $source
42+
* @param array $data
43+
* @return SourceInterface
44+
*/
45+
public function hydrate(SourceInterface $source, array $data)
46+
{
47+
$this->dataObjectHelper->populateWithArray($source, $data['general'], SourceInterface::class);
48+
$source = $this->sourceCarrierHydrator->hydrate($source, $data['general']);
49+
return $source;
50+
}
51+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Inventory\Controller\Adminhtml\Stock;
7+
8+
use Magento\Backend\App\Action;
9+
use Magento\Backend\App\Action\Context;
10+
use Magento\Backend\Model\View\Result\Page;
11+
use Magento\Framework\Controller\Result\Redirect;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\InventoryApi\Api\StockRepositoryInterface;
15+
use Magento\InventoryApi\Api\Data\StockInterface;
16+
17+
/**
18+
* Edit Controller
19+
*/
20+
class Edit extends Action
21+
{
22+
/**
23+
* @see _isAllowed()
24+
*/
25+
const ADMIN_RESOURCE = 'Magento_Inventory::stock';
26+
27+
/**
28+
* @var StockRepositoryInterface
29+
*/
30+
private $stockRepository;
31+
32+
/**
33+
* @param Context $context
34+
* @param StockRepositoryInterface $stockRepository
35+
*/
36+
public function __construct(
37+
Context $context,
38+
StockRepositoryInterface $stockRepository
39+
) {
40+
parent::__construct($context);
41+
$this->stockRepository = $stockRepository;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function execute()
48+
{
49+
$stockId = $this->getRequest()->getParam(StockInterface::STOCK_ID);
50+
try {
51+
$stock = $this->stockRepository->get($stockId);
52+
53+
/** @var Page $result */
54+
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
55+
$result->setActiveMenu('Magento_Inventory::stock')
56+
->addBreadcrumb(__('Edit Stock'), __('Edit Stock'));
57+
$result->getConfig()
58+
->getTitle()
59+
->prepend(__('Edit Stock: %1', $stock->getName()));
60+
} catch (NoSuchEntityException $e) {
61+
/** @var Redirect $result */
62+
$result = $this->resultRedirectFactory->create();
63+
$this->messageManager->addErrorMessage(
64+
__('Stock with id "%1" does not exist.', $stockId)
65+
);
66+
$result->setPath('*/*');
67+
}
68+
return $result;
69+
}
70+
}

0 commit comments

Comments
 (0)