Files
ltsecurityinc/app/code/JR/NetSuite/Controller/Adminhtml/OrderQueue/Import.php
T

67 lines
1.7 KiB
PHP
Executable File

<?php
namespace JR\NetSuite\Controller\Adminhtml\OrderQueue;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use JR\NetSuite\Cron\OrderSyncCron;
/**
* Class ClearHistory from controller
*/
class Import extends \Magento\Backend\App\Action
{
const MENU_ID = 'JR_NetSuite::orderqueue';
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @var OrderSyncCron
*/
protected $orderSyncCron;
/**
* @var \Magento\Framework\App\ResourceConnection
*/
protected $_resource;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
OrderSyncCron $orderSyncCron
) {
$this->_resource = $resource;
$this->resultPageFactory = $resultPageFactory;
$this->orderSyncCron = $orderSyncCron;
parent::__construct($context);
}
public function execute()
{
try {
$processed = 0;
// do {
$count = $this->orderSyncCron->processQueueItems();
if ($count) {
$processed += $count;
}
// } while ($count);
$this->messageManager->addSuccessMessage(__('A total of %1 orders imported.', $processed));
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
$this->_redirect('jr_netsuite/orderqueue/index');
}
/**
* @return bool
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed(static::MENU_ID);
}
}