ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
||||
|
||||
class Delete extends \JR\NetSuite\Controller\Adminhtml\Location
|
||||
{
|
||||
|
||||
/**
|
||||
* Delete action
|
||||
*
|
||||
* @return \Magento\Framework\Controller\ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
// check if we know what should be deleted
|
||||
$id = $this->getRequest()->getParam('location_id');
|
||||
if ($id) {
|
||||
try {
|
||||
// init model and delete
|
||||
$model = $this->_objectManager->create(\JR\NetSuite\Model\Location::class);
|
||||
$model->load($id);
|
||||
$model->delete();
|
||||
// display success message
|
||||
$this->messageManager->addSuccessMessage(__('You deleted the Location.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (\Exception $e) {
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
// go back to edit form
|
||||
return $resultRedirect->setPath('*/*/edit', ['location_id' => $id]);
|
||||
}
|
||||
}
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage(__('We can\'t find a Location to delete.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
||||
|
||||
class Edit extends \JR\NetSuite\Controller\Adminhtml\Location
|
||||
{
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @param \Magento\Backend\App\Action\Context $context
|
||||
* @param \Magento\Framework\Registry $coreRegistry
|
||||
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Magento\Framework\Registry $coreRegistry,
|
||||
\Magento\Framework\View\Result\PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @return \Magento\Framework\Controller\ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
// 1. Get ID and create model
|
||||
$id = $this->getRequest()->getParam('location_id');
|
||||
$model = $this->_objectManager->create(\JR\NetSuite\Model\Location::class);
|
||||
|
||||
// 2. Initial checking
|
||||
if ($id) {
|
||||
$model->load($id);
|
||||
if (!$model->getId()) {
|
||||
$this->messageManager->addErrorMessage(__('This Location no longer exists.'));
|
||||
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
$this->_coreRegistry->register('jr_netsuite_location', $model);
|
||||
|
||||
// 3. Build edit form
|
||||
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$this->initPage($resultPage)->addBreadcrumb(
|
||||
$id ? __('Edit Location') : __('New Location'),
|
||||
$id ? __('Edit Location') : __('New Location')
|
||||
);
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Locations'));
|
||||
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Location %1', $model->getId()) : __('New Location'));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use JR\NetSuite\Controller\Adminhtml\Location;
|
||||
|
||||
class Index extends Location
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\Result\PageFactory
|
||||
*/
|
||||
private $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @param \Magento\Backend\App\Action\Context $context
|
||||
* @param \Magento\Framework\Registry $coreRegistry
|
||||
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Magento\Framework\Registry $coreRegistry,
|
||||
\Magento\Framework\View\Result\PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the page defined in view/adminhtml/layout/jr_netsuite_location_index.xml
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Page $resultPage */
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$resultPage->setActiveMenu('JR_NetSuite::location');
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Locations'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class Save extends \Magento\Backend\App\Action
|
||||
{
|
||||
|
||||
protected $dataPersistor;
|
||||
|
||||
/**
|
||||
* @param \Magento\Backend\App\Action\Context $context
|
||||
* @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
|
||||
) {
|
||||
$this->dataPersistor = $dataPersistor;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save action
|
||||
*
|
||||
* @return \Magento\Framework\Controller\ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$data = $this->getRequest()->getPostValue();
|
||||
if ($data) {
|
||||
$id = $this->getRequest()->getParam('location_id');
|
||||
|
||||
$model = $this->_objectManager->create(\JR\NetSuite\Model\Location::class)->load($id);
|
||||
if (!$model->getId() && $id) {
|
||||
$this->messageManager->addErrorMessage(__('This Location no longer exists.'));
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
|
||||
$model->setData($data);
|
||||
|
||||
try {
|
||||
$model->save();
|
||||
$this->messageManager->addSuccessMessage(__('You saved the Location.'));
|
||||
$this->dataPersistor->clear('jr_netsuite_location');
|
||||
|
||||
if ($this->getRequest()->getParam('back')) {
|
||||
return $resultRedirect->setPath('*/*/edit', ['location_id' => $model->getId()]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Location.'));
|
||||
}
|
||||
|
||||
$this->dataPersistor->set('jr_netsuite_location', $data);
|
||||
return $resultRedirect->setPath('*/*/edit', ['location_id' => $this->getRequest()->getParam('location_id')]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user