ltsecurityinc安防产品在线商城代码
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\App\Action;
|
||||
|
||||
/**
|
||||
* Class AbstractStopWord
|
||||
*/
|
||||
abstract class AbstractStopWord extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::stop_words';
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Model\View\Result\ForwardFactory
|
||||
*/
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\StopWordRepository
|
||||
*/
|
||||
protected $stopWordRepository;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\StopWordFactory
|
||||
*/
|
||||
protected $stopWordFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Indexer\IndexerRegistry
|
||||
*/
|
||||
protected $indexerRegistry;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
|
||||
\Amasty\ElasticSearch\Model\StopWordRepository $ruleRepository,
|
||||
\Amasty\ElasticSearch\Model\StopWordFactory $stopWordFactory,
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
$this->stopWordRepository = $ruleRepository;
|
||||
$this->stopWordFactory = $stopWordFactory;
|
||||
$this->registry = $registry;
|
||||
$this->indexerRegistry = $indexerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Backend\Model\View\Result\Page $resultPage
|
||||
* @return \Magento\Backend\Model\View\Result\Page
|
||||
*/
|
||||
protected function initPage($resultPage)
|
||||
{
|
||||
$resultPage->setActiveMenu('Amasty_ElasticSearch::Amasty_ElasticSearch');
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Manage Stop Words'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Magento\Backend\App\Action;
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
|
||||
class Delete extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::stop_words';
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\StopWordRepository
|
||||
*/
|
||||
private $stopWordRepository;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\ResourceModel\StopWord\CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @var Filter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Indexer\IndexerRegistry
|
||||
*/
|
||||
private $indexerRegistry;
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
\Amasty\ElasticSearch\Model\StopWordRepository $stopWordRepository,
|
||||
\Amasty\ElasticSearch\Model\ResourceModel\StopWord\CollectionFactory $collectionFactory,
|
||||
Filter $filter,
|
||||
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
|
||||
) {
|
||||
parent::__construct($context);
|
||||
|
||||
$this->stopWordRepository = $stopWordRepository;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->filter = $filter;
|
||||
$this->indexerRegistry = $indexerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$idsToRemove = [];
|
||||
|
||||
$ids = $this->getRequest()->getParam(StopWordInterface::STOP_WORD_ID);
|
||||
if ($ids) {
|
||||
$idsToRemove = [$ids];
|
||||
}
|
||||
|
||||
if ($this->getRequest()->getParam(Filter::SELECTED_PARAM)
|
||||
|| $this->getRequest()->getParam(Filter::EXCLUDED_PARAM)
|
||||
) {
|
||||
$idsToRemove = $this->filter->getCollection($this->collectionFactory->create())->getAllIds();
|
||||
}
|
||||
if ($idsToRemove) {
|
||||
foreach ($idsToRemove as $id) {
|
||||
try {
|
||||
$this->stopWordRepository->deleteById($id);
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('%1 stop word(s) was successfully removed', count($idsToRemove))
|
||||
);
|
||||
$this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
|
||||
} else {
|
||||
$this->messageManager->addErrorMessage(__('Please select Stop Word(s)'));
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
|
||||
class DoImport extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::stop_words';
|
||||
public const MEDIA_PATH = 'amasty/elastic/import';
|
||||
public const FILE_WAS_NOT_UPLOADED_CODE_ERROR = '666';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filesystem\Io\File
|
||||
*/
|
||||
private $ioFile;
|
||||
|
||||
/**
|
||||
* @var \Magento\MediaStorage\Model\File\UploaderFactory
|
||||
*/
|
||||
private $fileUploaderFactory;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\StopWordRepository
|
||||
*/
|
||||
private $stopWordRepository;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\StopWordFactory
|
||||
*/
|
||||
private $stopWordFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Indexer\IndexerRegistry
|
||||
*/
|
||||
private $indexerRegistry;
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
\Magento\Framework\Filesystem $filesystem,
|
||||
\Magento\Framework\Filesystem\Io\File $ioFile,
|
||||
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
|
||||
\Amasty\ElasticSearch\Model\StopWordRepository $stopWordRepository,
|
||||
\Amasty\ElasticSearch\Model\StopWordFactory $stopWordFactory,
|
||||
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->filesystem = $filesystem;
|
||||
$this->ioFile = $ioFile;
|
||||
$this->fileUploaderFactory = $fileUploaderFactory;
|
||||
$this->stopWordRepository = $stopWordRepository;
|
||||
$this->stopWordFactory = $stopWordFactory;
|
||||
$this->indexerRegistry = $indexerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$data = $this->getRequest()->getPostValue();
|
||||
$storeId = (int) $this->getRequest()->getParam(StopWordInterface::STORE_ID);
|
||||
if ($data) {
|
||||
try {
|
||||
//upload images
|
||||
$path = $this->filesystem->getDirectoryRead(
|
||||
DirectoryList::MEDIA
|
||||
)->getAbsolutePath(
|
||||
self::MEDIA_PATH
|
||||
);
|
||||
|
||||
$this->ioFile->checkAndCreateFolder($path);
|
||||
|
||||
try {
|
||||
/** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
|
||||
$uploader = $this->fileUploaderFactory->create(['fileId' => 'amasty_elastic_file_upload']);
|
||||
$uploader->setAllowedExtensions(['csv']);
|
||||
$uploader->setAllowRenameFiles(true);
|
||||
$result = $uploader->save($path);
|
||||
} catch (\Exception $ex) {
|
||||
$this->messageManager->addErrorMessage(__($ex->getMessage()));
|
||||
return $resultRedirect->setPath('*/*/import');
|
||||
}
|
||||
|
||||
if (isset($result['file']) && $this->ioFile->fileExists($path . '/' . $result['file'])) {
|
||||
$file = $path . '/' . $result['file'];
|
||||
} else {
|
||||
$this->messageManager->addErrorMessage(__('Something wend wrong during saving file'));
|
||||
return $resultRedirect->setPath('*/*/import');
|
||||
}
|
||||
|
||||
$count = $this->stopWordRepository->importStopWords($file, $storeId);
|
||||
$this->ioFile->rm($file);
|
||||
} catch (LocalizedException $ex) {
|
||||
$this->messageManager->addErrorMessage($ex->getMessage());
|
||||
return $resultRedirect->setPath('*/*/import');
|
||||
} catch (\Exception $ex) {
|
||||
$this->messageManager->addErrorMessage(__('Something went wrong. Please try again'));
|
||||
return $resultRedirect->setPath('*/*/import');
|
||||
}
|
||||
|
||||
if (isset($count)) {
|
||||
$this->messageManager->addSuccessMessage(__('%1 Stop Word(s) has been imported', $count));
|
||||
$this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
|
||||
} else {
|
||||
$this->messageManager->addWarningMessage('Imported file was empty or all terms are already exist');
|
||||
}
|
||||
} else {
|
||||
$this->messageManager->addErrorMessage('There are no data to import');
|
||||
return $resultRedirect->setPath('*/*/import');
|
||||
}
|
||||
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
|
||||
class Edit extends AbstractStopWord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$stopWordId = (int)$this->getRequest()->getParam(StopWordInterface::STOP_WORD_ID);
|
||||
|
||||
try {
|
||||
if ($stopWordId) {
|
||||
/** @var \Amasty\ElasticSearch\Model\StopWord $model */
|
||||
$model = $this->stopWordRepository->getById($stopWordId);
|
||||
} else {
|
||||
$model = $this->stopWordFactory->create();
|
||||
}
|
||||
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
$this->messageManager->addErrorMessage(__('This Stop Word no longer exists.'));
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
|
||||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
||||
|
||||
$text = $model->getId() ? __('Edit Stop Word "%1"', $model->getTerm()) : __('New Stop Word');
|
||||
$this->initPage($resultPage)->getConfig()->getTitle()->prepend($text);
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
|
||||
class Import extends AbstractStopWord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
||||
|
||||
$this->initPage($resultPage)
|
||||
->getConfig()->getTitle()->prepend(__('Import Stop Words'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
|
||||
class Index extends AbstractStopWord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
||||
|
||||
$this->initPage($resultPage)
|
||||
->getConfig()->getTitle()->prepend(__('Manage Stop Words'));
|
||||
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
class NewAction extends AbstractStopWord
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
return $resultForward->forward('edit');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Controller\Adminhtml\Stopword;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
|
||||
class Save extends AbstractStopWord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$stopWordId = (int)$this->getRequest()->getParam(StopWordInterface::STOP_WORD_ID);
|
||||
|
||||
try {
|
||||
if ($stopWordId) {
|
||||
/** @var \Amasty\ElasticSearch\Model\StopWord $model */
|
||||
$model = $this->stopWordRepository->getById($stopWordId);
|
||||
} else {
|
||||
$model = $this->stopWordFactory->create();
|
||||
}
|
||||
|
||||
$model->setTerm($this->getRequest()->getParam(StopWordInterface::TERM))
|
||||
->setStoreId($this->getRequest()->getParam(StopWordInterface::STORE_ID));
|
||||
$this->stopWordRepository->save($model);
|
||||
$this->messageManager->addSuccessMessage(__('You have saved the Stop Word.'));
|
||||
$this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
|
||||
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('A Stop Word with the same term already exists in an associated store.')
|
||||
);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
$this->messageManager->addErrorMessage(__('This Stop Word no longer exists.'));
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
}
|
||||
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user