Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-inventory-shipping-admin-ui
Controller
Adminhtml
SourceSelection
Validate.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
namespace
Magento\InventoryShippingAdminUi\Controller\Adminhtml\SourceSelection
;
9
10
use
Magento\Backend\App\Action
;
11
use
Magento\Backend\App\Action\Context
;
12
use
Magento\Framework\Controller\Result\JsonFactory
;
13
use
Magento\Framework\DataObject
;
14
use
Magento\Framework\Exception\LocalizedException
;
15
16
class
Validate
extends
Action
17
{
21
const
ADMIN_RESOURCE
=
'Magento_InventoryApi::source'
;
22
26
private
$resultJsonFactory;
27
32
public
function
__construct
(
33
Context
$context,
34
JsonFactory
$resultJsonFactory
35
) {
36
$this->resultJsonFactory = $resultJsonFactory;
37
parent::__construct($context);
38
}
39
43
public
function
execute
()
44
{
45
$response
=
new
DataObject
();
46
$response
->setError(
false
);
47
48
$sourceCode
= $this->
getRequest
()->getParam(
'sourceCode'
);
49
$items
= $this->
getRequest
()->getParam(
'items'
);
50
51
//TODO: This is simple check. Need to create separate service and add additional checks:
52
//TODO: 1. manage stock
53
//TODO: 2. sum of all qty less on equal to source available qty (for products that occur twice or more in order)
54
//TODO: 3. check total qty
55
try
{
56
$itemsToShip = [];
57
$totalQty = 0;
58
foreach
(
$items
as
$item
) {
59
if
(empty(
$item
[
'sources'
])) {
60
continue
;
61
}
62
foreach
(
$item
[
'sources'
] as
$source
) {
63
if
(
$source
[
'sourceCode'
] ==
$sourceCode
) {
64
if
(
$item
[
'isManageStock'
]) {
65
$qtyToCompare = (float)
$source
[
'qtyAvailable'
];
66
}
else
{
67
$qtyToCompare = (float)
$item
[
'qtyToShip'
];
68
}
69
if
((
float
)
$source
[
'qtyToDeduct'
] > $qtyToCompare) {
70
throw
new
LocalizedException
(
71
__
(
'Qty of %1 should be less or equal to %2'
,
$item
[
'sku'
],
$source
[
'qtyAvailable'
])
72
);
73
}
74
$itemsToShip[
$item
[
'sku'
]] = ($itemsToShip[
$item
[
'sku'
]] ?? 0) +
$source
[
'qtyToDeduct'
];
75
$totalQty += $itemsToShip[
$item
[
'sku'
]];
76
}
77
}
78
}
79
if
($totalQty == 0) {
80
throw
new
LocalizedException
(
81
__
(
'You should select one or more items to ship.'
)
82
);
83
}
84
}
catch
(
LocalizedException
$e) {
85
$response
->setError(
true
);
86
$response
->setMessages([$e->getMessage()]);
87
}
88
89
return
$this->resultJsonFactory->create()->setData(
$response
);
90
}
91
}
Magento\Framework\Exception\LocalizedException
Definition:
LocalizedException.php:17
$response
$response
Definition:
404.php:11
$source
$source
Definition:
source.php:23
Magento\Framework\Controller\Result\JsonFactory
Definition:
JsonFactory.php:12
__
__()
Definition:
__.php:13
$item
$item
Definition:
partial_invoice.php:27
Magento\Framework\DataObject
Definition:
DataObject.php:15
Magento\Framework\App\Action\AbstractAction\getRequest
getRequest()
Definition:
AbstractAction.php:60
Magento\InventoryShippingAdminUi\Controller\Adminhtml\SourceSelection\Validate
Definition:
Validate.php:16
Magento\InventoryShippingAdminUi\Controller\Adminhtml\SourceSelection\Validate\execute
execute()
Definition:
Validate.php:43
Magento\Backend\App\Action
Definition:
Action.php:17
$sourceCode
$sourceCode
Definition:
inventory.phtml:11
Magento\InventoryShippingAdminUi\Controller\Adminhtml\SourceSelection\Validate\ADMIN_RESOURCE
const ADMIN_RESOURCE
Definition:
Validate.php:21
Magento\InventoryShippingAdminUi\Controller\Adminhtml\SourceSelection
Definition:
Index.php:8
Magento\Backend\App\Action\Context
Definition:
Context.php:25
Magento\InventoryShippingAdminUi\Controller\Adminhtml\SourceSelection\Validate\__construct
__construct(Context $context, JsonFactory $resultJsonFactory)
Definition:
Validate.php:32
Magento\Backend\App\Action
Definition:
Context.php:6
$items
$items
Definition:
order_rollback.php:21
Magento\Framework\DataObject
Definition:
Cache.php:6