jsonFactory = $jsonFactory; } /** * Inline edit action * * @return ResultInterface * @noinspection PhpDeprecationInspection */ public function execute() { /** @var Json $resultJson */ $resultJson = $this->jsonFactory->create(); $error = false; $messages = []; if ($this->getRequest()->getParam('isAjax')) { $postItems = $this->getRequest()->getParam('items', []); if (!count($postItems)) { $messages[] = __('Please correct the data sent.'); $error = true; } else { foreach (array_keys($postItems) as $modelId) { /** @var Location $model */ $model = $this->_objectManager->create(Location::class)->load($modelId); try { $model->setData(array_replace($model->getData(), $postItems[$modelId])); $model->save(); } catch (Exception $e) { $messages[] = "[Location ID: {$modelId}] {$e->getMessage()}"; $error = true; } } } } return $resultJson->setData([ 'messages' => $messages, 'error' => $error, ]); } }