ltsecurityinc安防产品在线商城代码
This commit is contained in:
+47
@@ -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\Model\ResourceModel\Advanced;
|
||||
|
||||
use Amasty\Base\Model\MagentoVersion as MagentoVersion;
|
||||
use Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection;
|
||||
|
||||
class CollectionFactory
|
||||
{
|
||||
/**
|
||||
* @var MagentoVersion
|
||||
*/
|
||||
private $magentoVersion;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
public function __construct(
|
||||
MagentoVersion $magentoVersion,
|
||||
\Magento\Framework\ObjectManagerInterface $objectManager
|
||||
) {
|
||||
$this->magentoVersion = $magentoVersion;
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if (version_compare($this->magentoVersion->get(), '2.3.2', '<')) {
|
||||
return $this->objectManager->create(Collection::class);
|
||||
} else {
|
||||
return $this->objectManager->create('elasticsearchAdvancedCollection');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
|
||||
use Magento\Framework\Model\ResourceModel\Db\Context;
|
||||
|
||||
class ConfigurableResolver extends AbstractDb
|
||||
{
|
||||
public const TABLE = 'catalog_product_relation';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $linkedField;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
ProductResource $productResource,
|
||||
$connectionName = null
|
||||
) {
|
||||
parent::__construct($context, $connectionName);
|
||||
$this->linkedField = $productResource->getLinkField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resource initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(self::TABLE, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parentIds
|
||||
* @return array
|
||||
*/
|
||||
public function getRelationSkuValues(array $parentIds)
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
|
||||
$select = $connection->select()->from(
|
||||
['product_relation' => $this->getTable(self::TABLE)],
|
||||
[]
|
||||
)->joinInner(
|
||||
['parent_product_entity' => $this->getTable('catalog_product_entity')],
|
||||
'product_relation.parent_id = parent_product_entity.' . $this->linkedField,
|
||||
['parent_product_entity.entity_id']
|
||||
)->joinRight(
|
||||
['product_entity' => $this->getTable('catalog_product_entity')],
|
||||
'product_entity.entity_id = product_relation.child_id',
|
||||
['GROUP_CONCAT(product_entity.sku)']
|
||||
)->where(
|
||||
'parent_product_entity.entity_id IN (?)',
|
||||
$parentIds
|
||||
)->group('product_relation.parent_id');
|
||||
|
||||
return $connection->fetchPairs($select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel;
|
||||
|
||||
use Magento\CatalogInventory\Api\StockConfigurationInterface;
|
||||
use Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
|
||||
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
|
||||
use Magento\Catalog\Model\Product\Visibility as ProductVisibility;
|
||||
|
||||
class Engine implements EngineInterface
|
||||
{
|
||||
/**
|
||||
* @var ProductVisibility
|
||||
*/
|
||||
private $productVisibility;
|
||||
|
||||
/**
|
||||
* @var IndexScopeResolver
|
||||
*/
|
||||
private $indexScopeResolver;
|
||||
|
||||
/**
|
||||
* @var StockConfigurationInterface
|
||||
*/
|
||||
private $stockConfiguration;
|
||||
|
||||
public function __construct(
|
||||
ProductVisibility $productVisibility,
|
||||
IndexScopeResolver $indexScopeResolver,
|
||||
StockConfigurationInterface $stockConfiguration
|
||||
) {
|
||||
$this->productVisibility = $productVisibility;
|
||||
$this->indexScopeResolver = $indexScopeResolver;
|
||||
$this->stockConfiguration = $stockConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedVisibility()
|
||||
{
|
||||
return $this->productVisibility->getVisibleInSiteIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function allowAdvancedIndex()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processAttributeValue($attribute, $value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareEntityIndex($index, $separator = ' ')
|
||||
{
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IndexScopeResolver
|
||||
*/
|
||||
public function isAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel\Fulltext;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
class SearchCollectionFactory
|
||||
{
|
||||
/**
|
||||
* Object Manager instance
|
||||
*
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager = null;
|
||||
|
||||
/**
|
||||
* Instance name to create
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_instanceName = null;
|
||||
|
||||
/**
|
||||
* Factory constructor
|
||||
*
|
||||
* @param ObjectManagerInterface $objectManager
|
||||
* @param string $instanceName
|
||||
*/
|
||||
public function __construct(ObjectManagerInterface $objectManager, $instanceName)
|
||||
{
|
||||
$this->_objectManager = $objectManager;
|
||||
$this->_instanceName = $instanceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create class instance with specified parameters
|
||||
*
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $data = [])
|
||||
{
|
||||
return $this->_objectManager->create($this->_instanceName, $data);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?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\Product;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
|
||||
class ConvertProductIdToSku
|
||||
{
|
||||
/**
|
||||
* @var ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
public function __construct(ResourceConnection $resourceConnection)
|
||||
{
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
public function execute(int $productId): string
|
||||
{
|
||||
$select = $this->resourceConnection->getConnection()->select()->from(
|
||||
$this->resourceConnection->getTableName('catalog_product_entity'),
|
||||
['sku']
|
||||
)->where('entity_id = ?', $productId);
|
||||
|
||||
return (string)$this->resourceConnection->getConnection()->fetchOne($select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
|
||||
use Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule\AdditionalSaveActions\CRUDCallbackInterface;
|
||||
use Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule\CRUDCallbackPull as OnDeleteCallbackPull;
|
||||
use Amasty\ElasticSearch\Model\ResourceModel\RelevanceRule\CRUDCallbackPull as OnSaveCallbackPull;
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
use Magento\Framework\Model\ResourceModel\Db\Context;
|
||||
|
||||
class RelevanceRule extends AbstractDb
|
||||
{
|
||||
/**
|
||||
* @var OnSaveCallbackPull
|
||||
*/
|
||||
private $onDeleteCallbackPull;
|
||||
/**
|
||||
* @var OnSaveCallbackPull
|
||||
*/
|
||||
private $onSaveCallbackPull;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
OnDeleteCallbackPull $onDeleteCallbackPull,
|
||||
OnSaveCallbackPull $onSaveCallbackPull,
|
||||
$connectionName = null
|
||||
) {
|
||||
$this->onDeleteCallbackPull = $onDeleteCallbackPull;
|
||||
$this->onSaveCallbackPull = $onSaveCallbackPull;
|
||||
|
||||
parent::__construct($context, $connectionName);
|
||||
}
|
||||
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(RelevanceRuleInterface::TABLE_NAME, RelevanceRuleInterface::RULE_ID);
|
||||
}
|
||||
|
||||
protected function _afterDelete(AbstractModel $object): RelevanceRule
|
||||
{
|
||||
/**
|
||||
* @var RelevanceRuleInterface $object
|
||||
* @var CRUDCallbackInterface $callback
|
||||
*/
|
||||
foreach ($this->onDeleteCallbackPull as $callback) {
|
||||
$callback->execute($object);
|
||||
}
|
||||
|
||||
return parent::_afterDelete($object);
|
||||
}
|
||||
|
||||
protected function _afterSave(AbstractModel $object): RelevanceRule
|
||||
{
|
||||
/**
|
||||
* @var RelevanceRuleInterface $object
|
||||
* @var CRUDCallbackInterface $callback
|
||||
*/
|
||||
foreach ($this->onSaveCallbackPull as $callback) {
|
||||
$callback->execute($object);
|
||||
}
|
||||
|
||||
return parent::_afterSave($object);
|
||||
}
|
||||
}
|
||||
+18
@@ -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;
|
||||
}
|
||||
+33
@@ -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();
|
||||
}
|
||||
}
|
||||
+35
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+63
@@ -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);
|
||||
}
|
||||
}
|
||||
+66
@@ -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);
|
||||
}
|
||||
}
|
||||
+84
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel;
|
||||
|
||||
class StopWord extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
|
||||
{
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('amasty_elastic_stop_word', 'stop_word_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel\StopWord;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_idFieldName = 'stop_word_id';
|
||||
|
||||
/**
|
||||
* Define resource model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Amasty\ElasticSearch\Model\StopWord::class,
|
||||
\Amasty\ElasticSearch\Model\ResourceModel\StopWord::class
|
||||
);
|
||||
}
|
||||
|
||||
public function deleteByIds($ids)
|
||||
{
|
||||
$this->getConnection()->delete(
|
||||
$this->getMainTable(),
|
||||
['stop_word_id IN(?)' => implode(',', $ids)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add filter by store
|
||||
*
|
||||
* @param null $store
|
||||
* @return $this
|
||||
*/
|
||||
public function addStoreFilter($store = null)
|
||||
{
|
||||
$storeId = $store;
|
||||
if ($store instanceof Store) {
|
||||
$storeId = $store->getId();
|
||||
}
|
||||
$this->getSelect()->where('store_id = ?', $storeId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $terms
|
||||
* @return $this
|
||||
*/
|
||||
public function addTermsFilter(array $terms = [])
|
||||
{
|
||||
$this->addFieldToFilter(StopWordInterface::TERM, ['in' => $terms]);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel\StopWord;
|
||||
|
||||
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 Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
use Amasty\ElasticSearch\Model\StopWord;
|
||||
use Psr\Log\LoggerInterface as Logger;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
|
||||
|
||||
class Grid extends SearchResult
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $document = Stopword::class;
|
||||
|
||||
//phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
|
||||
public function __construct(
|
||||
EntityFactory $entityFactory,
|
||||
Logger $logger,
|
||||
FetchStrategy $fetchStrategy,
|
||||
EventManager $eventManager,
|
||||
$mainTable = StopWordInterface::TABLE_NAME,
|
||||
$resourceModel = \Amasty\ElasticSearch\Model\ResourceModel\StopWord::class
|
||||
) {
|
||||
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel;
|
||||
|
||||
class Synonym extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
|
||||
{
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('amasty_elastic_synonym', 'synonym_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel\Synonym;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\SynonymInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_idFieldName = 'synonym_id';
|
||||
|
||||
/**
|
||||
* Define resource model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Amasty\ElasticSearch\Model\Synonym::class,
|
||||
\Amasty\ElasticSearch\Model\ResourceModel\Synonym::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*/
|
||||
public function deleteByIds(array $ids)
|
||||
{
|
||||
$this->getConnection()->delete(
|
||||
$this->getMainTable(),
|
||||
['synonym_id IN(?)' => implode(',', $ids)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $searchString
|
||||
* @return $this
|
||||
*/
|
||||
public function addSearchStringFilter($searchString)
|
||||
{
|
||||
// phpcs:ignore
|
||||
$searchString = addslashes($searchString);
|
||||
$this->getSelect()
|
||||
->where(
|
||||
SynonymInterface::TERM . ' ?',
|
||||
new \Zend_Db_Expr('REGEXP \'' . $searchString . '\'')
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add filter by store
|
||||
*
|
||||
* @param null $store
|
||||
* @return $this
|
||||
*/
|
||||
public function addStoreFilter($store = null)
|
||||
{
|
||||
$storeId = $store;
|
||||
|
||||
if ($store instanceof Store) {
|
||||
$storeId = $store->getId();
|
||||
}
|
||||
|
||||
$this->getSelect()->where('store_id = ?', $storeId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Model\ResourceModel\Synonym;
|
||||
|
||||
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 Amasty\ElasticSearch\Api\Data\SynonymInterface;
|
||||
use Amasty\ElasticSearch\Model\Synonym;
|
||||
use Psr\Log\LoggerInterface as Logger;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
|
||||
|
||||
class Grid extends SearchResult
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $document = Synonym::class;
|
||||
|
||||
//phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
|
||||
public function __construct(
|
||||
EntityFactory $entityFactory,
|
||||
Logger $logger,
|
||||
FetchStrategy $fetchStrategy,
|
||||
EventManager $eventManager,
|
||||
$mainTable = SynonymInterface::TABLE_NAME,
|
||||
$resourceModel = \Amasty\ElasticSearch\Model\ResourceModel\Synonym::class
|
||||
) {
|
||||
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user