76 lines
2.2 KiB
PHP
Executable File
76 lines
2.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* @author Olegnax
|
|
* @package Olegnax_GoogleMap
|
|
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
|
|
|
use Exception;
|
|
use Magento\Backend\App\Action;
|
|
use Magento\Backend\App\Action\Context;
|
|
use Magento\Framework\Controller\Result\Json;
|
|
use Magento\Framework\Controller\Result\JsonFactory;
|
|
use Magento\Framework\Controller\ResultInterface;
|
|
use Olegnax\GoogleMap\Model\Location;
|
|
|
|
class InlineEdit extends Action
|
|
{
|
|
|
|
protected $jsonFactory;
|
|
|
|
/**
|
|
* @param Context $context
|
|
* @param JsonFactory $jsonFactory
|
|
*/
|
|
public function __construct(
|
|
Context $context,
|
|
JsonFactory $jsonFactory
|
|
) {
|
|
parent::__construct($context);
|
|
$this->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,
|
|
]);
|
|
}
|
|
}
|