ltsecurityinc安防产品在线商城代码
This commit is contained in:
+163
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer;
|
||||
|
||||
use Amasty\Sorting\Api\IndexedMethodInterface;
|
||||
use Amasty\Sorting\Model\ConfigProvider;
|
||||
use Amasty\Sorting\Model\Method\IsMethodEnabled;
|
||||
use Magento\Framework\Mview\ActionInterface as MviewActionInterface;
|
||||
use Magento\Framework\Indexer\ActionInterface as IndexerActionInterface;
|
||||
use Magento\Framework\App\Cache\TypeListInterface as CacheTypeListInterface;
|
||||
use Magento\Framework\Indexer\CacheContext;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
class AbstractIndexer implements IndexerActionInterface, MviewActionInterface
|
||||
{
|
||||
/**
|
||||
* @var IndexedMethodInterface
|
||||
*/
|
||||
private $indexBuilder;
|
||||
|
||||
/**
|
||||
* @var CacheTypeListInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var CacheContext
|
||||
*/
|
||||
private $cacheContext;
|
||||
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
private $eventManager;
|
||||
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
/**
|
||||
* @var IsMethodEnabled
|
||||
*/
|
||||
private $isMethodEnabled;
|
||||
|
||||
public function __construct(
|
||||
IndexedMethodInterface $indexBuilder,
|
||||
CacheTypeListInterface $cache,
|
||||
CacheContext $cacheContext,
|
||||
ManagerInterface $eventManager,
|
||||
Registry $registry,
|
||||
ConfigProvider $configProvider,
|
||||
IsMethodEnabled $isMethodEnabled
|
||||
) {
|
||||
$this->indexBuilder = $indexBuilder;
|
||||
$this->cache = $cache;
|
||||
$this->cacheContext = $cacheContext;
|
||||
$this->eventManager = $eventManager;
|
||||
$this->registry = $registry;
|
||||
$this->configProvider = $configProvider;
|
||||
$this->isMethodEnabled = $isMethodEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute materialization on ids entities
|
||||
*
|
||||
* @param int[] $ids
|
||||
* @return void
|
||||
*/
|
||||
public function execute($ids)
|
||||
{
|
||||
$this->executeList($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute full indexation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function executeFull()
|
||||
{
|
||||
// do full reindex if method is not disabled
|
||||
if ($this->isMethodEnabled->execute($this->indexBuilder->getMethodCode())
|
||||
&& !$this->registry->registry('reindex_' . $this->indexBuilder->getMethodCode())
|
||||
) {
|
||||
$this->indexBuilder->reindex();
|
||||
$this->cacheContext->registerTags(
|
||||
['sorted_by_' . $this->indexBuilder->getMethodCode()]
|
||||
);
|
||||
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
|
||||
$this->registry->register('reindex_' . $this->indexBuilder->getMethodCode(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute partial indexation by ID list
|
||||
*
|
||||
* @param int[] $ids
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
* @return void
|
||||
*/
|
||||
public function executeList(array $ids)
|
||||
{
|
||||
if (!$ids) {
|
||||
throw new \Magento\Framework\Exception\LocalizedException(
|
||||
__('Could not rebuild index for empty products array')
|
||||
);
|
||||
}
|
||||
$this->doExecuteList($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: implement partial reindex
|
||||
*
|
||||
* @param int[] $ids
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
//phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedFunction
|
||||
protected function doExecuteList($ids) : void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: implement partial reindex
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedFunction
|
||||
private function doExecuteRow($id): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute partial indexation by ID
|
||||
*
|
||||
* @param int $id
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
* @return void
|
||||
*/
|
||||
public function executeRow($id)
|
||||
{
|
||||
if (!$id) {
|
||||
throw new \Magento\Framework\Exception\LocalizedException(
|
||||
__('We can\'t rebuild the index for an undefined product.')
|
||||
);
|
||||
}
|
||||
$this->doExecuteRow($id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer;
|
||||
|
||||
use Magento\Framework\Indexer\AbstractProcessor;
|
||||
|
||||
abstract class AbstractSortingProcessor extends AbstractProcessor
|
||||
{
|
||||
public function markIndexerAsInvalid()
|
||||
{
|
||||
if ($this->isIndexerScheduled()) {
|
||||
parent::markIndexerAsInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer\Bestsellers;
|
||||
|
||||
use Amasty\Sorting\Model\Indexer\AbstractSortingProcessor;
|
||||
|
||||
class BestsellersProcessor extends AbstractSortingProcessor
|
||||
{
|
||||
/**
|
||||
* Indexer id
|
||||
*/
|
||||
public const INDEXER_ID = 'amasty_sorting_bestseller';
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer;
|
||||
|
||||
use Magento\Framework\Indexer\AbstractProcessor;
|
||||
|
||||
class ConfigInvalidateAbstract extends \Magento\Framework\App\Config\Value
|
||||
{
|
||||
/**
|
||||
* @var AbstractProcessor
|
||||
*/
|
||||
private $indexProcessor;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\Model\Context $context,
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface $config,
|
||||
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
|
||||
AbstractProcessor $indexProcessor,
|
||||
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
|
||||
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
|
||||
$this->indexProcessor = $indexProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function afterSave()
|
||||
{
|
||||
$this->_getResource()->addCommitCallback([$this, 'processValue']);
|
||||
return parent::afterSave();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate index if Status or Period changed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processValue()
|
||||
{
|
||||
if ($this->getValue() != $this->getOldValue()) {
|
||||
$this->indexProcessor->markIndexerAsInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer\MostViewed;
|
||||
|
||||
use Amasty\Sorting\Model\Indexer\AbstractSortingProcessor;
|
||||
|
||||
class MostViewedProcessor extends AbstractSortingProcessor
|
||||
{
|
||||
/**
|
||||
* Indexer id
|
||||
*/
|
||||
public const INDEXER_ID = 'amasty_sorting_most_viewed';
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer\Revenue;
|
||||
|
||||
use Amasty\Sorting\Model\Indexer\AbstractSortingProcessor;
|
||||
|
||||
class RevenueProcessor extends AbstractSortingProcessor
|
||||
{
|
||||
/**
|
||||
* Indexer id
|
||||
*/
|
||||
public const INDEXER_ID = 'amasty_sorting_revenue';
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer\Stock;
|
||||
|
||||
use Magento\ConfigurableProduct\Model\ResourceModel\Indexer\Stock\Configurable as NativeIndexer;
|
||||
use Zend_Db_Expr;
|
||||
use Magento\Framework\DB\Select;
|
||||
|
||||
class Configurable extends NativeIndexer
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
|
||||
{
|
||||
$select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable);
|
||||
$this->calculateDependOnSimples($select);
|
||||
|
||||
return $select;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Select $select
|
||||
*/
|
||||
private function calculateDependOnSimples($select)
|
||||
{
|
||||
$columns = $select->getPart(Select::COLUMNS);
|
||||
foreach ($columns as &$column) {
|
||||
if (isset($column[2]) && $column[2] == 'qty') {
|
||||
$column[1] = new Zend_Db_Expr('SUM(IF(i.stock_status > 0, i.qty, 0))');
|
||||
}
|
||||
// determine stock status based on simples
|
||||
// if (isset($column[2]) && $column[2] == 'status') {
|
||||
// $column[1] = new Zend_Db_Expr('MAX(i.stock_status = 1)');
|
||||
// }
|
||||
}
|
||||
$select->setPart(Select::COLUMNS, $columns);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer;
|
||||
|
||||
use Amasty\Sorting\Model\Indexer\Bestsellers\BestsellersProcessor;
|
||||
use Amasty\Sorting\Model\Indexer\MostViewed\MostViewedProcessor;
|
||||
use Amasty\Sorting\Model\Indexer\Revenue\RevenueProcessor;
|
||||
use Amasty\Sorting\Model\Indexer\Wished\WishedProcessor;
|
||||
use Magento\Framework\Indexer\IndexerRegistry;
|
||||
use Magento\Indexer\Model\IndexerFactory;
|
||||
|
||||
class Summary
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $indexerIds = [
|
||||
BestsellersProcessor::INDEXER_ID,
|
||||
RevenueProcessor::INDEXER_ID,
|
||||
MostViewedProcessor::INDEXER_ID,
|
||||
WishedProcessor::INDEXER_ID
|
||||
];
|
||||
|
||||
/**
|
||||
* @var IndexerRegistry
|
||||
*/
|
||||
private $indexerRegistry;
|
||||
|
||||
public function __construct(IndexerRegistry $indexerRegistry)
|
||||
{
|
||||
$this->indexerRegistry = $indexerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reindexAll(): void
|
||||
{
|
||||
foreach ($this->indexerIds as $indexerId) {
|
||||
$indexer = $this->indexerRegistry->get($indexerId);
|
||||
if ($indexer) {
|
||||
$indexer->reindexAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Indexer\Wished;
|
||||
|
||||
use Amasty\Sorting\Model\Indexer\AbstractSortingProcessor;
|
||||
|
||||
class WishedProcessor extends AbstractSortingProcessor
|
||||
{
|
||||
/**
|
||||
* Indexer id
|
||||
*/
|
||||
public const INDEXER_ID = 'amasty_sorting_wished';
|
||||
}
|
||||
Reference in New Issue
Block a user