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,77 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Plugin\CatalogSearch\Block\Result;
use Amasty\ElasticSearch\Model\Config;
use Amasty\ElasticSearch\Model\Search\SubQuery\Helper as SubQueryHelper;
use Amasty\ElasticSearch\ViewModel\CatalogSearch\FurtherQueryViewModel;
use Magento\CatalogSearch\Block\Result as ResultBlock;
use Magento\Framework\View\Element\BlockFactory;
use Magento\Framework\View\Element\Template;
class AddSecondSearchQueryInput
{
private const TEMPLATE_NAME = 'Amasty_ElasticSearch::search/result/further_input.phtml';
/**
* @var Config
*/
private $config;
/**
* @var BlockFactory
*/
private $blockFactory;
/**
* @var FurtherQueryViewModel
*/
private $furtherQueryViewModel;
/**
* @var SubQueryHelper
*/
private $subQueryHelper;
public function __construct(
Config $config,
BlockFactory $blockFactory,
FurtherQueryViewModel $furtherQueryViewModel,
SubQueryHelper $subQueryHelper
) {
$this->config = $config;
$this->blockFactory = $blockFactory;
$this->furtherQueryViewModel = $furtherQueryViewModel;
$this->subQueryHelper = $subQueryHelper;
}
/**
* Add further query block for search result block if allowed.
*
* @see ResultBlock::toHtml()
*/
public function afterToHtml(ResultBlock $subject, string $result): string
{
if (!$subject->getResultCount() && $this->subQueryHelper->getQueryText() === null) {
return $result;
}
if ($this->config->isFurtherQueryAllowed()) {
$furtherBlock = $this->blockFactory->createBlock(Template::class, ['data' => [
'template' => self::TEMPLATE_NAME,
'furtherQueryViewModel' => $this->furtherQueryViewModel
]]);
$result = preg_replace('@<div[^>]*>@s', '$0' . $furtherBlock->toHtml(), $result, 1);
}
return $result;
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Plugin\CatalogSearch\Controller\Result\Index;
use Amasty\ElasticSearch\Model\Search\SubQuery\Helper as SubQueryHelper;
use Magento\CatalogSearch\Controller\Result\Index as CatalogSearchController;
use Magento\Framework\App\RequestInterface;
class RegisterSubQuery
{
/**
* @var RequestInterface
*/
private $request;
/**
* @var SubQueryHelper
*/
private $subQueryHelper;
public function __construct(RequestInterface $request, SubQueryHelper $subQueryHelper)
{
$this->request = $request;
$this->subQueryHelper = $subQueryHelper;
}
/**
* Register sub query from request.
*
* @see CatalogSearchController::execute
*/
public function beforeExecute(): void
{
$subQueryText = $this->request->getParam($this->subQueryHelper->getQueryParamName());
if ($subQueryText !== null) {
$this->subQueryHelper->setQueryText($subQueryText);
}
}
}
@@ -0,0 +1,114 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Plugin\CatalogSearch\Model\ResourceModel\Fulltext;
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection as FulltextCollection;
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
use Psr\Log\LoggerInterface;
class Collection
{
/**
* @var ToolbarModel
*/
private $toolbarModel;
/**
* @var MessageManagerInterface
*/
private $messageManager;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var \Amasty\Base\Model\MagentoVersion
*/
private $magentoVersion;
public function __construct(
\Amasty\Base\Model\MagentoVersion $magentoVersion,
ToolbarModel $toolbarModel,
MessageManagerInterface $messageManager,
LoggerInterface $logger
) {
$this->toolbarModel = $toolbarModel;
$this->messageManager = $messageManager;
$this->logger = $logger;
$this->magentoVersion = $magentoVersion;
}
/**
* @param FulltextCollection $collection
* @param bool $printQuery
* @param bool $logQuery
* @return array
*/
public function beforeLoad(FulltextCollection $collection, $printQuery = false, $logQuery = false)
{
if (!$collection->isLoaded() && $this->isLessThan22()) {
$this->setRelevanceOrder($collection);
}
return [$printQuery, $logQuery];
}
/**
* @param FulltextCollection $collection
*/
public function beforeGetSize(FulltextCollection $collection)
{
if (!$collection->isLoaded() && $this->isLessThan22()) {
$this->setRelevanceOrder($collection);
}
}
private function isLessThan22()
{
return version_compare($this->magentoVersion->get(), '2.2', '<');
}
/**
* @param FulltextCollection $collection
* @return FulltextCollection
*/
private function setRelevanceOrder(FulltextCollection $collection)
{
$direction = strtolower($this->toolbarModel->getDirection());
if ($direction) {
$collection->setOrder('relevance', $direction);
} else {
$collection->setOrder('relevance');
}
return $collection;
}
/**
* @param $subject
* @param \Closure $proceed
* @return array|mixed
*/
public function aroundGetFacetedData($subject, \Closure $proceed, $argument)
{
try {
$result = $proceed($argument);
} catch (StateException $exception) {
$this->messageManager->addErrorMessage(__('Sorry, search engine is currently unavailable'));
$this->logger->error($exception->getMessage());
$result = [];
}
return $result;
}
}
@@ -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\Plugin\CatalogSearch\Model\Search;
use Magento\CatalogSearch\Model\Search\RequestGenerator as SearchRequestGenerator;
class RequestGenerator
{
/**
* @var \Amasty\Base\Model\MagentoVersion
*/
private $magentoVersion;
public function __construct(\Amasty\Base\Model\MagentoVersion $magentoVersion)
{
$this->magentoVersion = $magentoVersion;
}
/**
* @param SearchRequestGenerator $subject
* @param array $requests
* @return array
*/
public function afterGenerate(SearchRequestGenerator $subject, $requests)
{
//TODO deprecated. remove in next releases
if (version_compare($this->magentoVersion->get(), '2.2.0', '<')) {
foreach ($requests as $requestContainer => &$request) {
if (isset($request['queries'][$requestContainer]['queryReference'])
&& !empty($request['queries'][$requestContainer]['queryReference'])
) {
foreach ($request['queries'][$requestContainer]['queryReference'] as &$reference) {
$reference['clause'] = 'must';
}
}
}
}
return $requests;
}
}