ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Controller\Adminhtml;
|
||||
|
||||
use Magento\Backend\Model\View\Result\Page;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
|
||||
abstract class Request extends \Magento\Backend\App\Action
|
||||
{
|
||||
public const CURRENT_REQUEST_MODEL = 'amasty_hideprice_request_model';
|
||||
|
||||
/**
|
||||
* @var \Amasty\HidePrice\Model\RequestRepository
|
||||
*/
|
||||
protected $requestRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
protected $coreRegistry;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Amasty\HidePrice\Model\RequestRepository $requestRepository,
|
||||
\Magento\Framework\Registry $coreRegistry
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->requestRepository = $requestRepository;
|
||||
$this->coreRegistry = $coreRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization level of a basic admin session
|
||||
*
|
||||
* @see _isAllowed()
|
||||
*/
|
||||
public const ADMIN_RESOURCE = 'Amasty_HidePrice::request';
|
||||
|
||||
/**
|
||||
* Initiate action
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
protected function _initAction()
|
||||
{
|
||||
/** @var Page $resultPage */
|
||||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
||||
$resultPage->setActiveMenu(self::ADMIN_RESOURCE);
|
||||
$resultPage->addBreadcrumb(__('Amasty Hide Price'), __('Amasty Hide Price'));
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Requests'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Controller\Adminhtml\Request;
|
||||
|
||||
|
||||
class Delete extends \Amasty\HidePrice\Controller\Adminhtml\Request
|
||||
{
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Amasty\HidePrice\Model\RequestRepository $requestRepository,
|
||||
\Magento\Framework\Registry $coreRegistry,
|
||||
\Psr\Log\LoggerInterface $logger
|
||||
) {
|
||||
parent::__construct($context, $requestRepository, $coreRegistry);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$id = $this->getRequest()->getParam('id');
|
||||
if ($id) {
|
||||
try {
|
||||
$this->requestRepository->deleteById($id);
|
||||
$this->messageManager->addSuccessMessage(__('Request was deleted.'));
|
||||
$this->_redirect('amasty_hideprice/*/');
|
||||
|
||||
return;
|
||||
} catch (\Magento\Framework\Exception\LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('Can\'t delete item right now. Please review the log and try again.')
|
||||
);
|
||||
$this->logger->critical($e);
|
||||
$this->_redirect('amasty_hideprice/*/edit', ['id' => $id]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->messageManager->addErrorMessage(__('Can\'t find a item to delete.'));
|
||||
$this->_redirect('amasty_hideprice/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Controller\Adminhtml\Request;
|
||||
|
||||
use Amasty\HidePrice\Model\Source\Status;
|
||||
|
||||
class Edit extends \Amasty\HidePrice\Controller\Adminhtml\Request
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$id = $this->getRequest()->getParam('id');
|
||||
if ($id) {
|
||||
try {
|
||||
$model = $this->requestRepository->get($id);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
$this->messageManager->addErrorMessage(__('This request no longer exists.'));
|
||||
$this->_redirect('amasty_hideprice/*');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$this->messageManager->addErrorMessage(__('This request no longer exists.'));
|
||||
$this->_redirect('amasty_hideprice/*');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->coreRegistry->register(\Amasty\HidePrice\Controller\Adminhtml\Request::CURRENT_REQUEST_MODEL, $model);
|
||||
|
||||
$this->_initAction();
|
||||
|
||||
$this->_view->getPage()->getConfig()->getTitle()->prepend(
|
||||
__('Get a Quote Request from ') . $model->getName()
|
||||
);
|
||||
|
||||
$this->_view->renderLayout();
|
||||
|
||||
/* change request status to viewed*/
|
||||
if ($model->getStatus() == Status::PENDING) {
|
||||
$model->setStatus(Status::VIEWED);
|
||||
$this->requestRepository->save($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Controller\Adminhtml\Request;
|
||||
|
||||
class Index extends \Amasty\HidePrice\Controller\Adminhtml\Request
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$this->_initAction();
|
||||
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Get a Quote Requests'));
|
||||
$this->_view->renderLayout();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Controller\Adminhtml\Request;
|
||||
|
||||
class MassDelete extends \Amasty\HidePrice\Controller\Adminhtml\Request
|
||||
{
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
/**
|
||||
* @var \Amasty\HidePrice\Model\ResourceModel\Request\CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Amasty\HidePrice\Model\RequestRepository $requestRepository,
|
||||
\Magento\Framework\Registry $coreRegistry,
|
||||
\Psr\Log\LoggerInterface $logger,
|
||||
\Amasty\HidePrice\Model\ResourceModel\Request\CollectionFactory $collectionFactory
|
||||
) {
|
||||
parent::__construct($context, $requestRepository, $coreRegistry);
|
||||
$this->logger = $logger;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$requestIds = $this->getRequest()->getParam('request_ids');
|
||||
if (!is_array($requestIds)) {
|
||||
$this->messageManager->addErrorMessage(__('Please select items.'));
|
||||
} else {
|
||||
try {
|
||||
/** @var \Amasty\HidePrice\Model\ResourceModel\Request\Collection $collection */
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->deleteByIds($requestIds);
|
||||
|
||||
$this->messageManager->addSuccessMessage(__('Get a Quote requests are deleted.'));
|
||||
} catch (\Magento\Framework\Exception\LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('Can\'t delete items right now. Please review the log and try again.')
|
||||
);
|
||||
$this->logger->critical($e);
|
||||
}
|
||||
}
|
||||
$this->_redirect('amasty_hideprice/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Controller\Adminhtml\Request;
|
||||
|
||||
use Amasty\HidePrice\Model\Source\Status;
|
||||
use Amasty\HidePrice\Model\Validator;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
|
||||
class Send extends \Amasty\HidePrice\Controller\Adminhtml\Request
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Mail\Template\TransportBuilder
|
||||
*/
|
||||
private $transportBuilder;
|
||||
|
||||
/**
|
||||
* @var \Amasty\HidePrice\Helper\Data
|
||||
*/
|
||||
private $helper;
|
||||
|
||||
/**
|
||||
* @var \Magento\Store\Model\StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @var Validator
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\App\Action\Context $context,
|
||||
\Amasty\HidePrice\Model\RequestRepository $requestRepository,
|
||||
\Magento\Framework\Registry $coreRegistry,
|
||||
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
|
||||
\Amasty\HidePrice\Helper\Data $helper,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
Validator $validator = null // TODO move to not optional
|
||||
) {
|
||||
parent::__construct($context, $requestRepository, $coreRegistry);
|
||||
$this->transportBuilder = $transportBuilder;
|
||||
$this->helper = $helper;
|
||||
$this->storeManager = $storeManager;
|
||||
$this->validator = $validator ?? ObjectManager::getInstance()->get(Validator::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$id = $this->getRequest()->getParam('request_id');
|
||||
|
||||
$message = $this->getRequest()->getParam('email_text');
|
||||
if (!$this->validator->isNotEmpty(trim($message))) {
|
||||
$this->messageManager->addErrorMessage(__('Please enter a Email Text.'));
|
||||
$this->_redirect('*/*/edit', ['id' => $id]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
try {
|
||||
$model = $this->requestRepository->get($id);
|
||||
|
||||
$emailTo = $model->getEmail();
|
||||
$sender = $this->helper->getModuleConfig('general/sender');
|
||||
$template = $this->helper->getModuleConfig('general/template');
|
||||
if ($this->sendEmail($model, $sender, $emailTo, $template, $message)) {
|
||||
$model->setStatus(Status::ANSWERED);
|
||||
$model->setMessageText($message);
|
||||
$this->requestRepository->save($model);
|
||||
$this->messageManager->addSuccessMessage(__('Email Answer was sent.'));
|
||||
}
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
$this->messageManager->addErrorMessage(__('This request no longer exists.'));
|
||||
}
|
||||
} else {
|
||||
$this->messageManager->addErrorMessage(__('Please select request id.'));
|
||||
}
|
||||
|
||||
$this->_redirect('amasty_hideprice/*/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Amasty\HidePrice\Model\Request $model
|
||||
* @param $sender
|
||||
* @param $emailTo
|
||||
* @param $template
|
||||
* @param $message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function sendEmail(\Amasty\HidePrice\Model\Request $model, $sender, $emailTo, $template, $message)
|
||||
{
|
||||
try {
|
||||
$store = $this->storeManager->getStore($model->getStoreId());
|
||||
$data = [
|
||||
'website_name' => $store->getWebsite()->getName(),
|
||||
'group_name' => $store->getGroup()->getName(),
|
||||
'store_name' => $store->getName(),
|
||||
'store' => $store,
|
||||
'request' => $model,
|
||||
'message' => $message,
|
||||
'customer_name' => $model->getName()
|
||||
];
|
||||
|
||||
$transport = $this->transportBuilder->setTemplateIdentifier(
|
||||
$template
|
||||
)->setTemplateOptions(
|
||||
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $store->getId()]
|
||||
)->setTemplateVars(
|
||||
$data
|
||||
)->setFrom(
|
||||
$sender
|
||||
)->addTo(
|
||||
$emailTo,
|
||||
$model->getName()
|
||||
)->getTransport();
|
||||
|
||||
$transport->sendMessage();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user