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,18 @@
<?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\Model\ResourceModel\RelevanceRule\AdditionalSaveActions;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
interface CRUDCallbackInterface
{
public function execute(RelevanceRuleInterface $rule): void;
}
@@ -0,0 +1,33 @@
<?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\Model\ResourceModel\RelevanceRule\AdditionalSaveActions;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor;
class InvalidateFulltextIndex implements CRUDCallbackInterface
{
/**
* @var Processor
*/
private $catalogSearchIndexProcessor;
public function __construct(
Processor $catalogSearchIndexProcessor
) {
$this->catalogSearchIndexProcessor = $catalogSearchIndexProcessor;
}
public function execute(RelevanceRuleInterface $rule): void
{
$this->catalogSearchIndexProcessor->markIndexerAsInvalid();
}
}
@@ -0,0 +1,35 @@
<?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\Model\ResourceModel\RelevanceRule\AdditionalSaveActions;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Amasty\ElasticSearch\Model\Indexer\RelevanceRule\RuleProductProcessor;
class ReindexRules implements CRUDCallbackInterface
{
/**
* @var RuleProductProcessor
*/
private $ruleProductProcessor;
public function __construct(
RuleProductProcessor $ruleProductProcessor
) {
$this->ruleProductProcessor = $ruleProductProcessor;
}
public function execute(RelevanceRuleInterface $rule): void
{
if (!$this->ruleProductProcessor->isIndexerScheduled()) {
$this->ruleProductProcessor->reindexRow($rule->getId());
}
}
}
@@ -0,0 +1,63 @@
<?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\Model\ResourceModel\RelevanceRule;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Amasty\ElasticSearch\Model\Indexer\RelevanceRule\IndexBuilder;
use Magento\Framework\App\ResourceConnection;
class BoostMultipliersProvider
{
/**
* @var ResourceConnection
*/
private $resourceConnection;
public function __construct(
ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}
/**
* @param int $websiteId
* @param int[]|null $productIds
*
* @return float[]
*/
public function getBoostMultipliers(int $websiteId, ?array $productIds = null): array
{
$connection = $this->resourceConnection->getConnection();
$select = $connection->select();
$select->from($this->resourceConnection->getTableName(IndexBuilder::TABLE_NAME), []);
$select->columns([
IndexBuilder::PRODUCT_ID => IndexBuilder::PRODUCT_ID,
RelevanceRuleInterface::MULTIPLIER => new \Zend_Db_Expr(sprintf(
'GREATEST(SUM(GREATEST(%1$s, 0)), 1) / GREATEST(ABS(SUM(LEAST((%1$s), 0))), 1)',
RelevanceRuleInterface::MULTIPLIER
))
]);
$select->where(
$connection->prepareSqlCondition(RelevanceRuleInterface::WEBSITE_ID, ['eq' => $websiteId])
);
$select->group(IndexBuilder::PRODUCT_ID);
if ($productIds !== null) {
$select->where(
$connection->prepareSqlCondition(IndexBuilder::PRODUCT_ID, ['in' => $productIds])
);
}
$rawMultipliers = (array) $connection->fetchPairs($select);
return array_map('floatval', $rawMultipliers);
}
}
@@ -0,0 +1,66 @@
<?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\Model\ResourceModel\RelevanceRule;
use Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule\AdditionalSaveActions\CRUDCallbackInterface;
use ArrayIterator;
use IteratorAggregate;
class CRUDCallbackPull implements IteratorAggregate
{
public const SORT_ORDER = 'sortOrder';
public const ACTION = 'action';
/**
* @var array[]
*
* @example [
* [
* 'sortOrder' => 12,
* 'actions' => $action
* ]
* ]
*/
private $crudCallbacks;
public function __construct(
$crudCallbacks = []
) {
$this->crudCallbacks = $this->sortActions($crudCallbacks);
}
private function sortActions(array $actionConfig): array
{
usort($actionConfig, function (array $configA, array $configB) {
$sortOrderA = $configA[self::SORT_ORDER] ?? 0;
$sortOrderB = $configB[self::SORT_ORDER] ?? 0;
return $sortOrderA <=> $sortOrderB;
});
return $actionConfig;
}
public function getIterator(): \Traversable
{
$actions = [];
foreach ($this->crudCallbacks as $callback) {
$action = $callback[self::ACTION] ?? null;
if ($action instanceof CRUDCallbackInterface) {
$actions[] = $action;
}
}
return new ArrayIterator($actions);
}
}
@@ -0,0 +1,84 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule;
use Amasty\Base\Model\Serializer;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Amasty\ElasticSearch\Model\RelevanceRule as RelevanceRuleResource;
use Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Psr\Log\LoggerInterface;
class Collection extends AbstractCollection
{
/**
* @var Serializer
*/
private $serializer;
public function __construct(
EntityFactoryInterface $entityFactory,
LoggerInterface $logger,
FetchStrategyInterface $fetchStrategy,
ManagerInterface $eventManager,
Serializer $serializer,
AdapterInterface $connection = null,
AbstractDb $resource = null
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->serializer = $serializer;
}
/**
* @inheritdoc
*/
protected function _construct()
{
parent::_construct();
$this->_idFieldName = RelevanceRuleInterface::RULE_ID;
$this->_init(
RelevanceRuleResource::class,
RelevanceRule::class
);
}
/**
* @return $this
*/
public function addActiveFilter(): Collection
{
$this->addStatusFilter(true);
return $this;
}
public function addStatusFilter(bool $active): void
{
$this->addFieldToFilter(RelevanceRuleInterface::IS_ENABLED, ['eq' => (int) $active]);
}
/**
* @param string $attributeCode
* @return $this
*/
public function addAttributeInConditionFilter($attributeCode): Collection
{
$match = sprintf(
'%%%s%%',
substr($this->serializer->serialize(['attribute' => $attributeCode]), 1, -1)
);
$this->addFieldToFilter(RelevanceRuleInterface::CONDITIONS, ['like' => $match]);
return $this;
}
}
@@ -0,0 +1,40 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Elastic Search Base for Magento 2
*/
namespace Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule;
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
use Amasty\ElasticSearch\Model\RelevanceRule;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Psr\Log\LoggerInterface as Logger;
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
class Grid extends SearchResult
{
/**
* @inheritdoc
*/
protected function _construct()
{
parent::_construct();
$this->document = RelevanceRule::class;
}
//phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
public function __construct(
EntityFactory $entityFactory,
Logger $logger,
FetchStrategy $fetchStrategy,
EventManager $eventManager,
$mainTable = RelevanceRuleInterface::TABLE_NAME,
$resourceModel = \Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule::class
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
}
}