6 declare(strict_types=1);
18 use Psr\Log\LoggerInterface;
30 private $bulkSessionProductsStorage;
35 private $bulkInventoryTransfer;
40 private $bulkOperationsConfig;
50 private $massSchedule;
71 LoggerInterface $logger,
74 parent::__construct($context);
76 $this->bulkSessionProductsStorage = $bulkSessionProductsStorage;
77 $this->bulkInventoryTransfer = $bulkInventoryTransfer;
78 $this->authSession = $context->getAuth();
79 $this->bulkOperationsConfig = $bulkOperationsConfig;
80 $this->massSchedule = $massSchedule;
92 private function runSynchronousOperation(
95 string $destinationSource,
98 $count = $this->bulkInventoryTransfer->execute(
$skus, $originSource, $destinationSource, $unassignSource);
99 $this->messageManager->addSuccessMessage(
__(
'Bulk operation was successful: %count inventory transfers.', [
113 private function runAsynchronousOperation(
115 string $originSource,
116 string $destinationSource,
119 $batchSize = $this->bulkOperationsConfig->getBatchSize();
120 $userId = (int) $this->authSession->getUser()->getId();
122 $skusChunks = array_chunk(
$skus, $batchSize);
124 foreach ($skusChunks as $skuChunk) {
127 'originSource' => $originSource,
128 'destinationSource' => $destinationSource,
129 'unassignFromOrigin' => $unassignSource,
133 $this->massSchedule->publishMass(
134 'async.V1.inventory.bulk-product-source-transfer.POST',
140 $this->messageManager->addSuccessMessage(
__(
'Your request was successfully queued for asynchronous execution'));
148 $originSource = $this->
getRequest()->getParam(
'origin_source',
'');
149 $destinationSource = $this->
getRequest()->getParam(
'destination_source',
'');
151 $skus = $this->bulkSessionProductsStorage->getProductsSkus();
152 $unassignSource = (bool) $this->
getRequest()->getParam(
'unassign_origin_source',
false);
154 $async = $this->bulkOperationsConfig->isAsyncEnabled();
158 $this->runAsynchronousOperation(
$skus, $originSource, $destinationSource, $unassignSource);
160 $this->runSynchronousOperation(
$skus, $originSource, $destinationSource, $unassignSource);
162 }
catch (\Exception $e) {
163 $this->logger->error($e->getMessage());
164 $this->messageManager->addErrorMessage(
__(
'Something went wrong during the operation.'));
168 return $result->setPath(
'catalog/product/index');
foreach($websiteCodes as $websiteCode) $skus
__construct(Action\Context $context, BulkInventoryTransferInterface $bulkInventoryTransfer, BulkSessionProductsStorage $bulkSessionProductsStorage, BulkOperationsConfig $bulkOperationsConfig, LoggerInterface $logger, MassSchedule $massSchedule)