54 lines
1.5 KiB
PHP
Executable File
54 lines
1.5 KiB
PHP
Executable File
<?php
|
|
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
|
|
|
use Magento\Backend\App\Action\Context;
|
|
use Magento\Framework\View\Result\PageFactory;
|
|
use JR\NetSuite\Service\LocationsSyncService;
|
|
use JR\NetSuite\Controller\Adminhtml\Location;
|
|
|
|
/**
|
|
* Class Fetch from controller
|
|
*/
|
|
class Fetch extends Location
|
|
{
|
|
const MENU_ID = 'JR_NetSuite::location';
|
|
|
|
protected $resultPageFactory;
|
|
|
|
/**
|
|
* @var LocationsSyncService
|
|
*/
|
|
protected $locationsSyncService;
|
|
|
|
public function __construct(
|
|
\Magento\Backend\App\Action\Context $context,
|
|
\Magento\Framework\Registry $coreRegistry,
|
|
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
|
|
LocationsSyncService $locationsSyncService
|
|
) {
|
|
$this->resultPageFactory = $resultPageFactory;
|
|
$this->locationsSyncService = $locationsSyncService;
|
|
|
|
parent::__construct($context, $coreRegistry);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$result = $this->locationsSyncService->sync();
|
|
|
|
if ($result['error']) {
|
|
$this->messageManager->addErrorMessage(__('Error while fetching data from NetSuite. ' . $result['message']));
|
|
} else {
|
|
$this->messageManager->addSuccessMessage(__('Data fetched successfully. ' . $result['message']));
|
|
}
|
|
$this->_redirect('jr_netsuite/location/index');
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
protected function _isAllowed()
|
|
{
|
|
return $this->_authorization->isAllowed(static::MENU_ID);
|
|
}
|
|
} |