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-catalog-admin-ui
Controller
Adminhtml
Source
BulkAssignPost.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
namespace
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Source
;
9
10
use
Magento\AsynchronousOperations\Model\MassSchedule
;
11
use
Magento\Backend\App\Action
;
12
use
Magento\Backend\Model\Auth
;
13
use
Magento\Framework\Controller\ResultFactory
;
14
use
Magento\Framework\Exception\BulkException
;
15
use
Magento\Framework\Exception\LocalizedException
;
16
use
Magento\Framework\Validation\ValidationException
;
17
use
Magento\InventoryCatalogAdminUi\Model\BulkOperationsConfig
;
18
use
Magento\InventoryCatalogAdminUi\Model\BulkSessionProductsStorage
;
19
use
Magento\InventoryCatalogApi\Api\BulkSourceAssignInterface
;
20
use Psr\Log\LoggerInterface;
21
22
class
BulkAssignPost
extends
Action
23
{
27
const
ADMIN_RESOURCE
=
'Magento_Catalog::products'
;
28
32
private
$bulkSessionProductsStorage;
33
37
private
$bulkSourceAssign;
38
42
private
$massSchedule;
43
47
private
$authSession;
48
52
private
$bulkOperationsConfig;
53
57
private
$logger;
58
68
public
function
__construct
(
69
Action
\
Context
$context,
70
BulkSourceAssignInterface
$bulkSourceAssign,
71
BulkSessionProductsStorage
$bulkSessionProductsStorage,
72
BulkOperationsConfig
$bulkOperationsConfig,
73
MassSchedule
$massSchedule,
74
LoggerInterface $logger
75
) {
76
parent::__construct($context);
77
78
$this->bulkSessionProductsStorage = $bulkSessionProductsStorage;
79
$this->bulkSourceAssign = $bulkSourceAssign;
80
$this->massSchedule = $massSchedule;
81
$this->authSession = $context->getAuth();
82
$this->bulkOperationsConfig = $bulkOperationsConfig;
83
$this->logger =
$logger
;
84
}
85
92
private
function
runSynchronousOperation(array
$skus
, array $sourceCodes): void
93
{
94
$count
= $this->bulkSourceAssign->execute(
$skus
, $sourceCodes);
95
$this->messageManager->addSuccessMessage(
__
(
'Bulk operation was successful: %count assignments.'
, [
96
'count'
=>
$count
97
]));
98
}
99
107
private
function
runAsynchronousOperation(array
$skus
, array $sourceCodes): void
108
{
109
$batchSize = $this->bulkOperationsConfig->getBatchSize();
110
$userId = (int) $this->authSession->getUser()->getId();
111
112
$skusChunks = array_chunk(
$skus
, $batchSize);
113
$operations
= [];
114
foreach
($skusChunks as $skuChunk) {
115
$operations
[] = [
116
'skus'
=> $skuChunk,
117
'sourceCodes'
=> $sourceCodes,
118
];
119
}
120
121
$this->massSchedule->publishMass(
122
'async.V1.inventory.bulk-product-source-assign.POST'
,
123
$operations
,
124
null
,
125
$userId
126
);
127
128
$this->messageManager->addSuccessMessage(
__
(
'Your request was successfully queued for asynchronous execution'
));
129
}
130
134
public
function
execute
()
135
{
136
$sourceCodes = $this->
getRequest
()->getParam(
'sources'
, []);
137
$skus = $this->bulkSessionProductsStorage->getProductsSkus();
138
139
$async = $this->bulkOperationsConfig->isAsyncEnabled();
140
141
try
{
142
if
($async) {
143
$this->runAsynchronousOperation(
$skus
, $sourceCodes);
144
}
else
{
145
$this->runSynchronousOperation(
$skus
, $sourceCodes);
146
}
147
}
catch
(\Exception $e) {
148
$this->logger->error($e->getMessage());
149
$this->messageManager->addErrorMessage(
__
(
'Something went wrong during the operation.'
));
150
}
151
152
$result
= $this->resultFactory->create(
ResultFactory::TYPE_REDIRECT
);
153
return
$result
->setPath(
'catalog/product/index'
);
154
}
155
}
Magento\InventoryCatalogAdminUi\Model\BulkSessionProductsStorage
Definition:
BulkSessionProductsStorage.php:16
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Source\BulkAssignPost\ADMIN_RESOURCE
const ADMIN_RESOURCE
Definition:
BulkAssignPost.php:27
$result
$result
Definition:
product_configurable_not_available_rollback.php:26
Magento\Framework\Exception\LocalizedException
Definition:
LocalizedException.php:17
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Source
Definition:
BulkAssign.php:8
$operations
$operations
Definition:
bulk.php:55
Magento\Framework\Exception\BulkException
Definition:
BulkException.php:16
Magento\InventoryCatalogAdminUi\Model\BulkOperationsConfig
Definition:
BulkOperationsConfig.php:12
$count
$count
Definition:
recent.phtml:13
Magento\Framework\Controller\ResultFactory
Definition:
ResultFactory.php:17
__
__()
Definition:
__.php:13
$skus
foreach($websiteCodes as $websiteCode) $skus
Definition:
assign_products_to_websites.php:23
$logger
$logger
Definition:
health_check.php:20
Magento\Framework\App\Action\AbstractAction\getRequest
getRequest()
Definition:
AbstractAction.php:60
Magento\Backend\App\Action
Definition:
Action.php:17
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Source\BulkAssignPost\execute
execute()
Definition:
BulkAssignPost.php:134
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Source\BulkAssignPost
Definition:
BulkAssignPost.php:22
Magento\InventoryCatalogApi\Api\BulkSourceAssignInterface
Definition:
BulkSourceAssignInterface.php:15
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Source\BulkAssignPost\__construct
__construct(Action\Context $context, BulkSourceAssignInterface $bulkSourceAssign, BulkSessionProductsStorage $bulkSessionProductsStorage, BulkOperationsConfig $bulkOperationsConfig, MassSchedule $massSchedule, LoggerInterface $logger)
Definition:
BulkAssignPost.php:68
Magento\AsynchronousOperations\Model\MassSchedule
Definition:
MassSchedule.php:29
Magento\Framework\Controller\ResultFactory\TYPE_REDIRECT
const TYPE_REDIRECT
Definition:
ResultFactory.php:24
Magento\Backend\App\Action\Context
Definition:
Context.php:25
Magento\Framework\Validation\ValidationException
Definition:
ValidationException.php:21
Magento\Backend\Model\Auth
Definition:
SessionTest.php:6
Magento\Backend\App\Action
Definition:
Context.php:6