64 lines
2.0 KiB
PHP
Executable File
64 lines
2.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright © All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
|
|
|
class InlineEdit extends \Magento\Backend\App\Action
|
|
{
|
|
|
|
protected $jsonFactory;
|
|
|
|
/**
|
|
* @param \Magento\Backend\App\Action\Context $context
|
|
* @param \Magento\Framework\Controller\Result\JsonFactory $jsonFactory
|
|
*/
|
|
public function __construct(
|
|
\Magento\Backend\App\Action\Context $context,
|
|
\Magento\Framework\Controller\Result\JsonFactory $jsonFactory
|
|
) {
|
|
parent::__construct($context);
|
|
$this->jsonFactory = $jsonFactory;
|
|
}
|
|
|
|
/**
|
|
* Inline edit action
|
|
*
|
|
* @return \Magento\Framework\Controller\ResultInterface
|
|
*/
|
|
public function execute()
|
|
{
|
|
/** @var \Magento\Framework\Controller\Result\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 \JR\NetSuite\Model\Location $model */
|
|
$model = $this->_objectManager->create(\JR\NetSuite\Model\Location::class)->load($modelid);
|
|
try {
|
|
$model->setData(array_merge($model->getData(), $postItems[$modelid]));
|
|
$model->save();
|
|
} catch (\Exception $e) {
|
|
$messages[] = "[Location ID: {$modelid}] {$e->getMessage()}";
|
|
$error = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $resultJson->setData([
|
|
'messages' => $messages,
|
|
'error' => $error
|
|
]);
|
|
}
|
|
} |