ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -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\Synonym;
use Magento\Backend\App\Action\Context;
use Magento\Backend\App\Action;
/**
* Class AbstractSynonym
*/
abstract class AbstractSynonym extends Action
{
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::synonym';
/**
* @var \Magento\Backend\Model\View\Result\ForwardFactory
*/
protected $resultForwardFactory;
/**
* @var \Amasty\ElasticSearch\Model\SynonymRepository
*/
protected $synonymRepository;
/**
* @var \Amasty\ElasticSearch\Model\SynonymFactory
*/
protected $synonymFactory;
/**
* @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\SynonymRepository $synonymRepository,
\Amasty\ElasticSearch\Model\SynonymFactory $synonymFactory,
\Magento\Framework\Registry $registry,
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
) {
parent::__construct($context);
$this->resultForwardFactory = $resultForwardFactory;
$this->synonymRepository = $synonymRepository;
$this->synonymFactory = $synonymFactory;
$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 Synonyms'));
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\Synonym;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Backend\App\Action;
use Amasty\ElasticSearch\Api\Data\SynonymInterface;
class Delete extends Action
{
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::synonym';
/**
* @var \Amasty\ElasticSearch\Model\SynonymRepository
*/
private $synonymRepository;
/**
* @var \Amasty\ElasticSearch\Model\ResourceModel\Synonym\CollectionFactory
*/
private $collectionFactory;
/**
* @var Filter
*/
private $filter;
/**
* @var \Magento\Framework\Indexer\IndexerRegistry
*/
private $indexerRegistry;
public function __construct(
Action\Context $context,
\Amasty\ElasticSearch\Model\SynonymRepository $synonymRepository,
\Amasty\ElasticSearch\Model\ResourceModel\Synonym\CollectionFactory $collectionFactory,
Filter $filter,
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
) {
parent::__construct($context);
$this->synonymRepository = $synonymRepository;
$this->collectionFactory = $collectionFactory;
$this->filter = $filter;
$this->indexerRegistry = $indexerRegistry;
}
/**
* {@inheritdoc}
*/
public function execute()
{
$idsToRemove = [];
$ids = $this->getRequest()->getParam(SynonymInterface::SYNONYM_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->synonymRepository->deleteById($id);
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
}
$this->messageManager->addSuccessMessage(
__('%1 synonym(s) was successfully removed', count($idsToRemove))
);
$this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
} else {
$this->messageManager->addErrorMessage(__('Please select Synonym(s)'));
}
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
}
@@ -0,0 +1,173 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\Synonym;
use Magento\Backend\App\Action;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\LocalizedException;
use Amasty\ElasticSearch\Api\Data\SynonymInterface;
use Magento\Framework\Exception\CouldNotSaveException;
use Amasty\ElasticSearch\Model\Indexer\Data\DataMapperResolver;
class DoImport extends Action
{
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::synonym';
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\SynonymRepository
*/
private $synonymRepository;
/**
* @var \Amasty\ElasticSearch\Model\SynonymFactory
*/
private $synonymFactory;
/**
* @var \Magento\Framework\File\Csv
*/
private $csv;
/**
* @var \Magento\Indexer\Model\IndexerFactory
*/
protected $indexerFactory;
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\SynonymRepository $synonymRepository,
\Amasty\ElasticSearch\Model\SynonymFactory $synonymFactory,
\Magento\Framework\File\Csv $csv,
\Magento\Indexer\Model\IndexerFactory $indexerFactory
) {
parent::__construct($context);
$this->filesystem = $filesystem;
$this->ioFile = $ioFile;
$this->fileUploaderFactory = $fileUploaderFactory;
$this->synonymRepository = $synonymRepository;
$this->synonymFactory = $synonymFactory;
$this->csv = $csv;
$this->indexerFactory = $indexerFactory;
}
/**
* {@inheritdoc}
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$data = $this->getRequest()->getPostValue();
$storeId = (int) $this->getRequest()->getParam(SynonymInterface::STORE_ID);
$count = 0;
if ($data) {
try {
$file = $this->uploadFile();
$csvData = $this->csv->getData($file);
foreach ($csvData as $data) {
$term = ($data && is_array($data)) ? implode(',', $data) : null;
if ($term) {
try {
$model = $this->synonymFactory->create()
->setStoreId($storeId)
->setTerm($term);
$this->synonymRepository->save($model);
} catch (AlreadyExistsException $ex) {
continue;
} catch (CouldNotSaveException $ex) {
continue;
}
$count++;
}
}
$this->invalidateIndex();
$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 ($count > 0) {
$this->messageManager->addSuccessMessage(__('%1 Synonym(s) has been imported', $count));
} 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('*/*/');
}
/**
* @return string
* @throws LocalizedException
* @throws \Exception
*/
private function uploadFile()
{
$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) {
throw new LocalizedException(__($ex->getMessage()));
}
if (isset($result['file']) && $this->ioFile->fileExists($path . '/' . $result['file'])) {
$file = $path . '/' . $result['file'];
} else {
throw new LocalizedException(__('Something wend wrong during saving file'));
}
return $file;
}
private function invalidateIndex()
{
$indexer = $this->indexerFactory->create()->load(DataMapperResolver::DEFAULT_DATA_INDEXER);
$indexer->invalidate();
}
}
@@ -0,0 +1,43 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\Synonym;
use Magento\Framework\Controller\ResultFactory;
use Amasty\ElasticSearch\Api\Data\SynonymInterface;
class Edit extends AbstractSynonym
{
/**
* {@inheritdoc}
*/
public function execute()
{
$stopWordId = (int)$this->getRequest()->getParam(SynonymInterface::SYNONYM_ID);
try {
if ($stopWordId) {
/** @var \Amasty\ElasticSearch\Model\Synonym $model */
$model = $this->synonymRepository->getById($stopWordId);
} else {
$model = $this->synonymFactory->create();
}
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
$this->messageManager->addErrorMessage(__('This Synonym no longer exists.'));
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$text = $model->getId() ? __('Edit Synonym "%1"', $model->getTerm()) : __('New Synonym');
$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\Synonym;
use Magento\Framework\Controller\ResultFactory;
class Import extends AbstractSynonym
{
/**
* {@inheritdoc}
*/
public function execute()
{
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$this->initPage($resultPage)
->getConfig()->getTitle()->prepend(__('Import Synonyms'));
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\Synonym;
use Magento\Framework\Controller\ResultFactory;
class Index extends AbstractSynonym
{
/**
* {@inheritdoc}
*/
public function execute()
{
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$this->initPage($resultPage)
->getConfig()->getTitle()->prepend(__('Manage Synonyms'));
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\Synonym;
class NewAction extends AbstractSynonym
{
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
$resultForward = $this->resultForwardFactory->create();
return $resultForward->forward('edit');
}
}
@@ -0,0 +1,55 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\Synonym;
use Amasty\ElasticSearch\Api\Data\SynonymInterface;
use Magento\Framework\Exception\NoSuchEntityException;
class Save extends AbstractSynonym
{
/**
* {@inheritdoc}
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$stopWordId = (int)$this->getRequest()->getParam(SynonymInterface::SYNONYM_ID);
try {
if ($stopWordId) {
/** @var \Amasty\ElasticSearch\Model\Synonym $model */
$model = $this->synonymRepository->getById($stopWordId);
} else {
$model = $this->synonymFactory->create();
}
$model->setTerm($this->getRequest()->getParam(SynonymInterface::TERM))
->setStoreId($this->getRequest()->getParam(SynonymInterface::STORE_ID));
$this->synonymRepository->save($model);
$this->messageManager->addSuccessMessage(__('You have saved the Synonym.'));
$this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate();
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
$this->messageManager->addErrorMessage(
__('A Synonym with the same term already exists in an associated store.')
);
} catch (NoSuchEntityException $exception) {
$this->messageManager->addErrorMessage(__('This Synonym no longer exists.'));
$resultRedirect = $this->resultRedirectFactory->create();
}
$matches = null;
preg_match('/(\+|-|\/|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/', $model->getTerm(), $matches);
if (count($matches)) {
$this->messageManager->addNoticeMessage(__(
'Synonyms with special symbols only works on elasticsearch engine v6.0 or higher.'
));
}
return $resultRedirect->setPath('*/*/');
}
}