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,82 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
use Amasty\ElasticSearch\Model\RelevanceRuleFactory;
use Amasty\ElasticSearch\Model\RelevanceRuleRepository;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\ForwardFactory;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Store\Model\StoreManagerInterface;
abstract class AbstractRelevance extends Action
{
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::relevance_rules';
public const CURRENT_RULE = 'amasty_elastic_relevance_rule';
/**
* @var ForwardFactory
*/
protected $resultForwardFactory;
/**
* @var RelevanceRuleRepository
*/
protected $ruleRepository;
/**
* @var RelevanceRuleFactory
*/
protected $ruleFactory;
/**
* @var Registry
*/
protected $registry;
/**
* @var TimezoneInterface
*/
protected $timezone;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
public function __construct(
Context $context,
ForwardFactory $resultForwardFactory,
RelevanceRuleRepository $ruleRepository,
RelevanceRuleFactory $ruleFactory,
Registry $registry,
TimezoneInterface $timezone,
StoreManagerInterface $storeManager
) {
parent::__construct($context);
$this->resultForwardFactory = $resultForwardFactory;
$this->ruleRepository = $ruleRepository;
$this->ruleFactory = $ruleFactory;
$this->registry = $registry;
$this->timezone = $timezone;
$this->storeManager = $storeManager;
}
/**
* @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 Relevance Rules'));
return $resultPage;
}
}
@@ -0,0 +1,77 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Backend\App\Action;
class Delete extends Action
{
public const ADMIN_RESOURCE = 'Amasty_ElasticSearch::relevance_rules';
/**
* @var \Amasty\ElasticSearch\Model\RelevanceRuleRepository
*/
private $relevanceRuleRepository;
/**
* @var \Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule\CollectionFactory
*/
private $collectionFactory;
/**
* @var Filter
*/
private $filter;
public function __construct(
Action\Context $context,
\Amasty\ElasticSearch\Model\RelevanceRuleRepository $relevanceRuleRepository,
\Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule\CollectionFactory $collectionFactory,
Filter $filter
) {
parent::__construct($context);
$this->relevanceRuleRepository = $relevanceRuleRepository;
$this->collectionFactory = $collectionFactory;
$this->filter = $filter;
}
/**
* @inheritdoc
*/
public function execute()
{
if ($this->getRequest()->getParam(Filter::SELECTED_PARAM)
|| $this->getRequest()->getParam(Filter::EXCLUDED_PARAM)
) {
$ids = $this->filter->getCollection($this->collectionFactory->create())->getAllIds();
} else {
$ids = (array)$this->getRequest()->getParam(RelevanceRuleInterface::RULE_ID);
}
if ($ids) {
foreach ($ids as $id) {
try {
$this->relevanceRuleRepository->deleteById($id);
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
}
$this->messageManager->addSuccessMessage(
__('%1 rule(s) was successfully removed', count($ids))
);
} else {
$this->messageManager->addErrorMessage(__('Please select Relevance Rule(s)'));
}
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
}
@@ -0,0 +1,41 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Magento\Framework\Controller\ResultFactory;
class Edit extends AbstractRelevance
{
/**
* @inheritdoc
*/
public function execute()
{
$ruleId = (int)$this->getRequest()->getParam(RelevanceRuleInterface::RULE_ID);
try {
if ($ruleId) {
/** @var \Amasty\ElasticSearch\Model\RelevanceRule $model */
$model = $this->ruleRepository->get($ruleId);
} else {
$model = $this->ruleFactory->create();
}
$this->registry->register(self::CURRENT_RULE, $model);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->messageManager->addErrorMessage(__('This Relevance Rule is no longer exists.'));
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$text = $model->getId() ? $model->getTitle() : __('New Relevance Rule');
$this->initPage($resultPage)->getConfig()->getTitle()->prepend($text);
return $resultPage;
}
}
@@ -0,0 +1,22 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
use Magento\Framework\Controller\ResultFactory;
class Index extends AbstractRelevance
{
/**
* @inheritdoc
*/
public function execute()
{
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $this->initPage($resultPage);
}
}
@@ -0,0 +1,20 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
class NewAction extends AbstractRelevance
{
/**
* @inheritdoc
*/
public function execute()
{
$resultForward = $this->resultForwardFactory->create();
return $resultForward->forward('edit');
}
}
@@ -0,0 +1,42 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
class NewConditionHtml extends AbstractRelevance
{
/**
* @inheritdoc
*/
public function execute()
{
$ruleId = $this->getRequest()->getParam('id');
$formName = $this->getRequest()->getParam('form_namespace');
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
$type = $typeArr[0];
$model = $this->_objectManager->create($type)
->setId($ruleId)
->setType($type)
->setRule($this->_objectManager->create(\Magento\CatalogRule\Model\Rule::class))
->setPrefix('conditions');
if (!empty($typeArr[1])) {
$model->setAttribute($typeArr[1]);
}
if ($model instanceof \Magento\Rule\Model\Condition\AbstractCondition) {
$model->setJsFormObject($this->getRequest()->getParam('form'));
$model->setFormName($formName);
$html = $model->asHtmlRecursive();
} else {
$html = '';
}
$this->getResponse()->setBody($html);
}
}
@@ -0,0 +1,115 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Amasty\ElasticSearch\Model\Source\RelevanceRuleModificationType;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Stdlib\DateTime;
class Save extends AbstractRelevance
{
/**
* @inheritdoc
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$rule = (int)$this->getRequest()->getParam(RelevanceRuleInterface::RULE_ID);
$data = $this->getRequest()->getPostValue();
try {
if ($rule) {
/** @var \Amasty\ElasticSearch\Model\RelevanceRule $model */
$model = $this->ruleRepository->get($rule);
} else {
$model = $this->ruleFactory->create();
}
$data = $this->prepareData($data, $model);
$model->setData($data);
$this->ruleRepository->save($model);
$this->messageManager->addSuccessMessage(__('You have saved the Rule.'));
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
$this->messageManager->addErrorMessage(
__('Relevance Rule with the same term already exists in an associated store.')
);
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
$this->messageManager->addErrorMessage(__('This Relevance Rule no longer exists.'));
$resultRedirect = $this->resultRedirectFactory->create();
}
return $resultRedirect->setPath('*/*/');
}
/**
* @param array $data
* @param \Amasty\ElasticSearch\Model\RelevanceRule $rule
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function prepareData(array $data, \Amasty\ElasticSearch\Model\RelevanceRule $rule)
{
if (empty($data[RelevanceRuleInterface::RULE_ID])) {
$data[RelevanceRuleInterface::RULE_ID] = null;
}
$data[RelevanceRuleInterface::MULTIPLIER] = max(
min($data[RelevanceRuleInterface::MULTIPLIER], 100),
1
);
if ($data['modification_type'] === RelevanceRuleModificationType::DECREASE) {
$data[RelevanceRuleInterface::MULTIPLIER] *= -1;
}
if (isset($data['rule']) && isset($data['rule']['conditions'])) {
$conditions = $data['rule']['conditions'];
unset($data['rule']);
$data[RelevanceRuleInterface::CONDITIONS] = $rule->getConditionsSerialized($conditions);
}
$data[RelevanceRuleInterface::FROM_DATE] = $this->prepareDates($data[RelevanceRuleInterface::FROM_DATE]);
$data[RelevanceRuleInterface::TO_DATE] = $this->prepareDates($data[RelevanceRuleInterface::TO_DATE]);
$data = $this->prepareRuleStatus($data);
return $data;
}
private function prepareDates(string $date): ?string
{
return $date ? $this->timezone->date($date)->format(DateTime::DATE_PHP_FORMAT) : '';
}
private function prepareRuleStatus(array $data): array
{
$websiteId = $data[RelevanceRuleInterface::WEBSITE_ID] ?? false;
if ($websiteId) {
try {
$website = $this->storeManager->getWebsite($websiteId);
if (!empty($data[RelevanceRuleInterface::FROM_DATE])
&& !empty($data[RelevanceRuleInterface::TO_DATE])
&& !$this->timezone->isScopeDateInInterval(
$website,
$data[RelevanceRuleInterface::FROM_DATE],
$data[RelevanceRuleInterface::TO_DATE]
)
) {
$data[RelevanceRuleInterface::IS_ENABLED] = false;
}
} catch (LocalizedException $e) {
;// do nothing
}
}
return $data;
}
}