ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class AddRevenueToDescSorting implements DataPatchInterface
|
||||
{
|
||||
private const DEFAULT_DESC_SORTING_PATH = 'amsorting/general/desc_attributes';
|
||||
private const REVENUE_SORTING_CODE = 'revenue';
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $setup;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $setup
|
||||
) {
|
||||
$this->setup = $setup;
|
||||
}
|
||||
|
||||
public function apply(): self
|
||||
{
|
||||
$connection = $this->setup->getConnection();
|
||||
$tableName = $this->setup->getTable('core_config_data');
|
||||
|
||||
$select = $connection->select()
|
||||
->from($tableName, ['config_id', 'value'])
|
||||
->where('path = ?', self::DEFAULT_DESC_SORTING_PATH);
|
||||
|
||||
$settings = $connection->fetchAll($select);
|
||||
|
||||
foreach ($settings as $row) {
|
||||
$value = $row['value'] ? $row['value'] . ',' . self::REVENUE_SORTING_CODE : self::REVENUE_SORTING_CODE;
|
||||
$connection->update(
|
||||
$tableName,
|
||||
['value' => $value],
|
||||
['config_id = ?' => $row['config_id']]
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\Sorting\Model\Indexer\Bestsellers\BestsellersProcessor;
|
||||
use Amasty\Sorting\Model\Indexer\MostViewed\MostViewedProcessor;
|
||||
use Amasty\Sorting\Model\Indexer\Wished\WishedProcessor;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\State;
|
||||
use Magento\Framework\Indexer\IndexerRegistry;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\NonTransactionableInterface;
|
||||
|
||||
class ReindexData implements DataPatchInterface, NonTransactionableInterface
|
||||
{
|
||||
private $indexerIds = [
|
||||
BestsellersProcessor::INDEXER_ID,
|
||||
MostViewedProcessor::INDEXER_ID,
|
||||
WishedProcessor::INDEXER_ID
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var IndexerRegistry
|
||||
*/
|
||||
private $indexerRegistry;
|
||||
|
||||
/**
|
||||
* @var State
|
||||
*/
|
||||
private $appState;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
IndexerRegistry $indexerRegistry,
|
||||
State $state
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->indexerRegistry = $indexerRegistry;
|
||||
$this->appState = $state;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
\Amasty\Sorting\Setup\Patch\Data\RenameLabelsField::class,
|
||||
\Amasty\Sorting\Setup\Patch\Data\UpdateDefaultSearch::class
|
||||
];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): ReindexData
|
||||
{
|
||||
foreach ($this->indexerIds as $indexerId) {
|
||||
$this->appState->emulateAreaCode(
|
||||
Area::AREA_ADMINHTML,
|
||||
[$this, 'reindexData'],
|
||||
[$indexerId]
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function reindexData(string $indexerId): void
|
||||
{
|
||||
$indexer = $this->indexerRegistry->get($indexerId);
|
||||
$indexer->invalidate();
|
||||
$indexer->reindexAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Magento\Framework\DB\Select;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class RenameLabelsField implements DataPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): RenameLabelsField
|
||||
{
|
||||
if ($this->isCanProceed()) {
|
||||
$updateData = [];
|
||||
$connection = $this->moduleDataSetup->getConnection();
|
||||
$tableName = $this->moduleDataSetup->getTable('core_config_data');
|
||||
$select = $this->prepareSelect('amsorting/biggest_saving/label');
|
||||
$rows = $connection->fetchAll($select);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$updateData[] = [
|
||||
'value' => $row['value'],
|
||||
'path' => 'amsorting/saving/label',
|
||||
'scope' => $row['scope'],
|
||||
'scope_id' => $row['scope_id']
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$connection->insertOnDuplicate($tableName, $updateData);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function prepareSelect(string $path): Select
|
||||
{
|
||||
$tableName = $this->moduleDataSetup->getTable('core_config_data');
|
||||
$connection = $this->moduleDataSetup->getConnection();
|
||||
|
||||
return $connection
|
||||
->select()
|
||||
->from($tableName, ['path', 'value', 'scope', 'scope_id'])
|
||||
->where('path = ?', $path);
|
||||
}
|
||||
|
||||
private function isCanProceed(): bool
|
||||
{
|
||||
$select = $this->prepareSelect('amsorting/saving/label');
|
||||
$rows = $this->moduleDataSetup->getConnection()->fetchAll($select);
|
||||
|
||||
return empty($rows);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Magento\Catalog\Model\Config;
|
||||
use Magento\Framework\DB\Select;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class UpdateDefaultSearch implements DataPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
\Amasty\Sorting\Setup\Patch\Data\RenameLabelsField::class
|
||||
];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): UpdateDefaultSearch
|
||||
{
|
||||
if ($this->isCanProceed()) {
|
||||
$select = $this->prepareSelect(Config::XML_PATH_LIST_DEFAULT_SORT_BY);
|
||||
$tableName = $this->moduleDataSetup->getTable('core_config_data');
|
||||
$connection = $this->moduleDataSetup->getConnection();
|
||||
$rows = $connection->fetchAll($select);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$updateData[] = [
|
||||
'value' => $row['value'],
|
||||
'path' => 'amsorting/default_sorting/category_1',
|
||||
'scope' => $row['scope'],
|
||||
'scope_id' => $row['scope_id']
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$connection->insertOnDuplicate($tableName, $updateData);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function prepareSelect(string $path): Select
|
||||
{
|
||||
$tableName = $this->moduleDataSetup->getTable('core_config_data');
|
||||
$connection = $this->moduleDataSetup->getConnection();
|
||||
|
||||
return $connection
|
||||
->select()
|
||||
->from($tableName, ['path', 'value', 'scope', 'scope_id'])
|
||||
->where('path = ?', $path);
|
||||
}
|
||||
|
||||
private function isCanProceed(): bool
|
||||
{
|
||||
$select = $this->prepareSelect('amsorting/default_sorting/category_1');
|
||||
$rows = $this->moduleDataSetup->getConnection()->fetchAll($select);
|
||||
|
||||
return empty($rows);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?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\Setup\Patch\DeclarativeSchemaApplyBefore;
|
||||
|
||||
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
|
||||
class DropOldTables implements SchemaPatchInterface
|
||||
{
|
||||
public const TABLES = [
|
||||
'amasty_sorting_yotpo',
|
||||
'amsorting_bestsellers',
|
||||
'amsorting_most_viewed',
|
||||
'amsorting_wished',
|
||||
'amasty_sorting_bestsellers',
|
||||
'amasty_sorting_most_viewed',
|
||||
'amasty_sorting_wished'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var SchemaSetupInterface
|
||||
*/
|
||||
private $schemaSetup;
|
||||
|
||||
public function __construct(
|
||||
SchemaSetupInterface $schemaSetup
|
||||
) {
|
||||
$this->schemaSetup = $schemaSetup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): DropOldTables
|
||||
{
|
||||
$connection = $this->schemaSetup->getConnection();
|
||||
|
||||
foreach (self::TABLES as $table) {
|
||||
$tableName = $this->schemaSetup->getTable($table);
|
||||
|
||||
if ($connection->isTableExists($tableName)) {
|
||||
$connection->dropTable($tableName);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user