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,161 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Setup\Patch\Data;
use Amasty\HidePrice\Model\Source\Group;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class CreateAttributes implements DataPatchInterface
{
private const HIDE_PRICE_MODE_ATTR = 'am_hide_price_mode';
private const HIDE_PRICE_CUSTOMER_GROUP_ATTR = 'am_hide_price_customer_gr';
private const HIDE_PRICE_MODE_CAT_ATTR = 'am_hide_price_mode_cat';
private const HIDE_PRICE_CUSTOMER_GROUP_CAT_ATTR = 'am_hide_price_customer_gr_cat';
/**
* @var EavSetup
*/
private $eavSetup;
public function __construct(
EavSetupFactory $eavSetupFactory,
ModuleDataSetupInterface $setup
) {
$this->eavSetup = $eavSetupFactory->create(['setup' => $setup]);
}
public function apply(): self
{
$this->addHidePriceModeAttr();
$this->addHidePriceCustomerGroupAttr();
$this->addHidePriceModeCatAttribute();
$this->addHidePriceCustomerGrCatAttr();
return $this;
}
private function addHidePriceCustomerGrCatAttr(): void
{
$this->eavSetup->addAttribute(
Category::ENTITY,
self::HIDE_PRICE_CUSTOMER_GROUP_CAT_ATTR,
[
'type' => 'text',
'backend' => ArrayBackend::class,
'label' => __('Use Current Price Mode By Customer Group'),
'input' => 'multiselect',
'required' => false,
'sort_order' => 4,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'wysiwyg_enabled' => false,
'is_html_allowed_on_front' => false,
'group' => __('General Information')
]
);
}
private function addHidePriceModeCatAttribute(): void
{
$this->eavSetup->addAttribute(
Category::ENTITY,
self::HIDE_PRICE_MODE_CAT_ATTR,
[
'type' => 'int',
'label' => __('Display Price Mode'),
'input' => 'select',
'required' => false,
'sort_order' => 4,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'wysiwyg_enabled' => false,
'is_html_allowed_on_front' => false,
'group' => __('General Information')
]
);
}
private function addHidePriceModeAttr(): void
{
$this->eavSetup->addAttribute(
Product::ENTITY,
self::HIDE_PRICE_MODE_ATTR,
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => __('Display Price Mode'),
'input' => 'select',
'class' => '',
'source' => Boolean::class,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'used_in_product_listing' => true,
'apply_to' => '',
'is_configurable' => false
]
);
}
private function addHidePriceCustomerGroupAttr(): void
{
$this->eavSetup->addAttribute(
Product::ENTITY,
self::HIDE_PRICE_CUSTOMER_GROUP_ATTR,
[
'type' => 'text',
'backend' => ArrayBackend::class,
'frontend' => '',
'label' => __('Use Current Price Mode By Customer Group'),
'input' => 'multiselect',
'class' => '',
'source' => Group::class,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'used_in_product_listing' => true,
'apply_to' => '',
'is_configurable' => false
]
);
}
public function getAliases(): array
{
return [];
}
public static function getDependencies(): array
{
return [];
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Setup\Patch\Data;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
/**
* Transfer data after changing attribute types
*/
class TransferData implements DataPatchInterface
{
private const HIDE_PRICE_CUSTOMER_GROUP_ATTR = 'am_hide_price_customer_gr';
private const HIDE_PRICE_CUSTOMER_GROUP_CAT_ATTR = 'am_hide_price_customer_gr_cat';
private const PRODUCT_ENTITY_VARCHAR_TABLE = 'catalog_product_entity_varchar';
private const PRODUCT_ENTITY_TEXT_TABLE = 'catalog_product_entity_text';
private const CATEGORY_ENTITY_VARCHAR_TABLE = 'catalog_category_entity_varchar';
private const CATEGORY_ENTITY_TEXT_TABLE = 'catalog_category_entity_text';
/**
* @var ModuleDataSetupInterface
*/
private $schemaSetup;
/**
* @var AttributeRepositoryInterface
*/
private $attributeRepository;
public function __construct(
ModuleDataSetupInterface $schemaSetup,
AttributeRepositoryInterface $attributeRepository
) {
$this->schemaSetup = $schemaSetup;
$this->attributeRepository = $attributeRepository;
}
public static function getDependencies(): array
{
return [CreateAttributes::class];
}
public function getAliases(): array
{
return [];
}
public function apply(): self
{
$this->moveProductAttributeData();
$this->moveCategoryAttributeData();
return $this;
}
private function moveProductAttributeData(): void
{
$attribute = $this->attributeRepository->get(Product::ENTITY, self::HIDE_PRICE_CUSTOMER_GROUP_ATTR);
$this->transferData(
self::PRODUCT_ENTITY_VARCHAR_TABLE,
self::PRODUCT_ENTITY_TEXT_TABLE,
(int)$attribute->getAttributeId()
);
}
private function moveCategoryAttributeData(): void
{
$attribute = $this->attributeRepository->get(Category::ENTITY, self::HIDE_PRICE_CUSTOMER_GROUP_CAT_ATTR);
$this->transferData(
self::CATEGORY_ENTITY_VARCHAR_TABLE,
self::CATEGORY_ENTITY_TEXT_TABLE,
(int)$attribute->getAttributeId()
);
}
private function transferData(string $fromTableName, string $toTableName, int $attributeId): void
{
$fromTable = $this->schemaSetup->getTable($fromTableName);
$toTable = $this->schemaSetup->getTable($toTableName);
$connection = $this->schemaSetup->getConnection();
$select = $connection->select()
->from($fromTable)
->where('attribute_id = ?', $attributeId);
$attributeValues = $connection->fetchAll($select);
foreach ($attributeValues as $value) {
unset($value['value_id']);
$connection->insert($toTable, $value);
}
}
}
@@ -0,0 +1,127 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Setup\Patch\Data;
use Amasty\HidePrice\Model\Source\ReplaceButton;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class UpdateSettings implements DataPatchInterface
{
private const TABLE_CORE_CONFIG_DATA = 'core_config_data';
private const REPLACE_LINK_SETTING_PATH = 'amasty_hide_price/information/replace_link';
private const REPLACE_WITH_SETTING_PATH = 'amasty_hide_price/information/replace_with';
private const REDIRECT_LINK_SETTING_PATH = 'amasty_hide_price/information/redirect_link';
public const FORM_SELECTOR = 'form[data-role="tocart-form"],';
public const NEW_FORM_SELECTOR = 'form[data-role="tocart-form"] button,';
public const ADD_TO_CART_SETTING_PATH = 'amasty_hide_price/developer/addtocart';
/**
* @var ModuleDataSetupInterface
*/
private $setup;
public function __construct(
ModuleDataSetupInterface $setup
) {
$this->setup = $setup;
}
public function apply(): self
{
$this->updateReplaceLinkSetting();
$this->updateAddToCartSetting();
return $this;
}
private function updateAddToCartSetting(): void
{
$connection = $this->setup->getConnection();
$tableName = $this->setup->getTable(self::TABLE_CORE_CONFIG_DATA);
$select = $this->setup->getConnection()->select()
->from($tableName, ['path', 'value', 'scope', 'scope_id', 'config_id'])
->where('path = ?', self::ADD_TO_CART_SETTING_PATH);
$replaceLinks = $connection->fetchAll($select);
foreach ($replaceLinks as $replaceLink) {
if (isset($replaceLink['value'])) {
if (strpos($replaceLink['value'], self::FORM_SELECTOR) !== false) {
$value = str_replace(self::FORM_SELECTOR, self::NEW_FORM_SELECTOR, $replaceLink['value']);
$connection->update(
$tableName,
['value' => $value],
['config_id = ?' => $replaceLink['config_id']]
);
}
}
}
}
private function updateReplaceLinkSetting(): void
{
$connection = $this->setup->getConnection();
$tableName = $this->setup->getTable(self::TABLE_CORE_CONFIG_DATA);
$select = $this->setup->getConnection()->select()
->from($tableName, ['path', 'value', 'scope', 'scope_id'])
->where('path = ?', self::REPLACE_LINK_SETTING_PATH);
$replaceLinks = $connection->fetchAll($select);
foreach ($replaceLinks as $replaceLink) {
if (isset($replaceLink['value'])) {
if ($replaceLink['value'] === 'AmastyHidePricePopup') {
$updateData[] = [
'value' => ReplaceButton::HIDE_PRICE_POPUP,
'path' => self::REPLACE_WITH_SETTING_PATH,
'scope' => $replaceLink['scope'],
'scope_id' => $replaceLink['scope_id']
];
} else {
$updateData[] = [
'value' => ReplaceButton::REDIRECT_URL,
'path' => self::REPLACE_WITH_SETTING_PATH,
'scope' => $replaceLink['scope'],
'scope_id' => $replaceLink['scope_id']
];
$updateData[] = [
'value' => $replaceLink['value'],
'path' => self::REDIRECT_LINK_SETTING_PATH,
'scope' => $replaceLink['scope'],
'scope_id' => $replaceLink['scope_id']
];
}
}
}
if (!empty($updateData)) {
$connection->insertOnDuplicate(
$tableName,
$updateData
);
}
}
public function getAliases(): array
{
return [];
}
public static function getDependencies(): array
{
return [];
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\UninstallInterface;
class Uninstall implements UninstallInterface
{
private const HIDE_PRICE_REQUEST_TABLE = 'amasty_hideprice_request';
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context): void
{
$this->uninstallTables($setup);
$this->uninstallConfigData($setup);
}
private function uninstallTables(SchemaSetupInterface $setup): void
{
$tablesToDrop = [
self::HIDE_PRICE_REQUEST_TABLE
];
foreach ($tablesToDrop as $table) {
$setup->getConnection()->dropTable(
$setup->getTable($table)
);
}
}
private function uninstallConfigData(SchemaSetupInterface $setup): void
{
$configTable = $setup->getTable('core_config_data');
$setup->getConnection()->delete($configTable, "`path` LIKE 'amasty_hide_price%'");
}
}