This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,109 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Eav\Model\Entity\Attribute\Backend\Datetime;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Stemcell\Catalog\Enum\CategoryOption;
/**
* 给搜索结果增加一个包含产品、资源、文档的filter
*/
class AddCategoryOptionAttribute implements SchemaPatchInterface
{
const ATTRIBUTE_CATEGORY_OPTION = 'category_option';
/**
* Constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private EavSetupFactory $eavSetupFactory
) {
}
/**
* {@inheritdoc}
*/
public function apply(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
self::ATTRIBUTE_CATEGORY_OPTION,
[
'type' => 'int',
'label' => 'Category',
'input' => 'select',
'source' => '',
'frontend' => '',
'required' => false,
'sort_order' => '30',
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'default' => null,
'visible' => true,
'user_defined' => true,
'searchable' => true,
'search_weight' => 4,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => '',
'group' => 'General',
'used_in_product_listing' => false,
'is_used_in_grid' => false,
'filterable_in_search' => true,
'is_visible_in_grid' => false,
'used_for_sort_by' => false,
'is_filterable_in_grid' => false,
'option' => [
'values' => array_column(CategoryOption::cases(), 'value')
],
]
);
$this->moduleDataSetup->getConnection()->endSetup();
}
public function revert(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'category_option');
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies(): array
{
return [];
}
}
@@ -0,0 +1,158 @@
<?php
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Catalog\Model\Product;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
/**
* 目前只有技术资料和文献可能有关联的sku, 可以通过调用系统的数据动态输出。
* 但是目前的状况是技术资料、常见问题、文献都以html的形式放在resources_publications里。因此需要将这三者摘出来,单独存放
*/
class AddEducationalMaterialSkusAttribute implements SchemaPatchInterface
{
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private EavSetupFactory $eavSetupFactory
) {}
/**
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Validator\ValidateException
*/
public function apply()
{
$attributes = [
'technical_resource_skus' => [
'label' => 'Technical Resource Skus',
'attributes' => []
],
'publication_skus' => [
'label' => 'Publication Skus',
'attributes' => []
],
'technical_resource' => [
'label' => 'Technical Resource',
'attributes' => [
'group' => 'Content',
'wysiwyg_enabled' => 1,
'is_html_allowed_on_front' => 1,
'visible_on_front' => 0,
'is_pagebuilder_enabled' => 1,
]
],
'faq' => [
'label' => 'FAQ',
'attributes' => [
'group' => 'Content',
'wysiwyg_enabled' => 1,
'is_html_allowed_on_front' => 1,
'visible_on_front' => 0,
'is_pagebuilder_enabled' => 1,
]
],
'publication' => [
'label' => 'Publication',
'attributes' => [
'group' => 'Content',
'wysiwyg_enabled' => 1,
'is_html_allowed_on_front' => 1,
'visible_on_front' => 0,
'is_pagebuilder_enabled' => 1,
]
]
];
foreach ($attributes as $code => $item) {
$this->create($code, $item['label'], $item['attributes']);
}
}
/**
* @param string $attributeCode
* @param string $attributeLabel
* @param string $attributeSetName
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Validator\ValidateException
*/
protected function create(string $attributeCode, string $attributeLabel, array $attributes, string $attributeSetName='Pendants and charms')
{
$this->moduleDataSetup->getConnection()->startSetup();
$eavSetup = $this->eavSetupFactory->create([
'setup' => $this->moduleDataSetup
]);
$attr = [
'type' => 'text',
'label' => $attributeLabel,
'input' => 'textarea',
'required' => false,
'user_defined' => true,
'visible' => true,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General',
];
$attr = array_merge($attr, $attributes);
// 1. Add product attribute
$eavSetup->addAttribute(
Product::ENTITY,
$attributeCode,
$attr
);
if (!empty($attr['is_pagebuilder_enabled'])) {
$eavSetup->updateAttribute(
Product::ENTITY,
$attributeCode,
[
'is_wysiwyg_enabled' => 1,
'is_pagebuilder_enabled' => 1,
]
);
}
// 2. Assign to specific attribute set
$entityTypeId = $eavSetup->getEntityTypeId(Product::ENTITY);
$attributeSetId = $eavSetup->getAttributeSetId(
$entityTypeId,
$attributeSetName// attribute set name
);
$attributeGroupId = $eavSetup->getAttributeGroupId(
$entityTypeId,
$attributeSetId,
$attr['group']
);
$attributeId = $eavSetup->getAttributeId(
Product::ENTITY,
$attributeCode
);
$eavSetup->addAttributeToSet(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
$attributeId
);
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
public static function getDependencies()
{
return [];
}
public function getAliases()
{
return [];
}
}
@@ -0,0 +1,54 @@
<?php
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
class AddFulltextParserToProductManualSearch implements SchemaPatchInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
}
public static function getDependencies()
{
return [];
}
public function getAliases()
{
return [];
}
public function apply()
{
$connection = $this->moduleDataSetup->getConnection();
$tableName = $this->moduleDataSetup->getTable('product_manual_search');
$connection->startSetup();
// Drop existing fulltext index if exists
$indexName = $connection->getIndexName($tableName, ['name'], \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT);
if ($connection->isTableExists($tableName)) {
$connection->dropIndex($tableName, $indexName);
}
// Add fulltext index with ngram parser
$sql = sprintf(
'ALTER TABLE `%s` ADD FULLTEXT INDEX `%s` (`name`) WITH PARSER ngram;',
$tableName,
$indexName
);
$connection->query($sql);
$connection->endSetup();
return $this;
}
}
@@ -0,0 +1,101 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Eav\Model\Entity\Attribute\Backend\Datetime;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
class AddNewPublishDateAttribute implements SchemaPatchInterface
{
/**
* Constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private EavSetupFactory $eavSetupFactory
) {
}
/**
* {@inheritdoc}
*/
public function apply(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'new_publish_date',
[
'type' => 'datetime',
'label' => 'Publish Date',
'input' => 'date',
'source' => '',
'frontend' => '',
'required' => false,
'backend' => Datetime::class,
'sort_order' => '30',
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'default' => null,
'visible' => true,
'user_defined' => true,
'searchable' => false,
'search_weight' => 4,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => '',
'group' => 'General',
'used_in_product_listing' => false,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'used_for_sort_by' => true,
'is_filterable_in_grid' => false,
'note' => 'Replace publish_date for product list sort'
]
);
$this->moduleDataSetup->getConnection()->endSetup();
}
public function revert(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'new_publish_date');
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies(): array
{
return [];
}
}
@@ -0,0 +1,106 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Eav\Model\Entity\Attribute\Backend\Datetime;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Stemcell\Catalog\Enum\CategoryOption;
/**
* 此属性主要用于产品说明书、安全数据表等分类页面里的搜索,和parent_sku的数据对应
*/
class AddParentNamesAttribute implements SchemaPatchInterface
{
const ATTRIBUTE_PARENT_NAMES = 'parent_names';
/**
* Constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(
private readonly ModuleDataSetupInterface $moduleDataSetup,
private readonly EavSetupFactory $eavSetupFactory
) {
}
/**
* {@inheritdoc}
*/
public function apply(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
self::ATTRIBUTE_PARENT_NAMES,
[
'type' => 'varchar',
'label' => 'Parent Names',
'input' => 'text',
'source' => '',
'frontend' => '',
'required' => false,
'sort_order' => '30',
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'default' => null,
'visible' => true,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => '',
'group' => 'General',
'used_in_product_listing' => false,
'is_used_in_grid' => false,
'filterable_in_search' => true,
'is_visible_in_grid' => false,
'used_for_sort_by' => false,
'is_filterable_in_grid' => false,
'note' => '此属性主要用于产品说明书、安全数据表等分类页面里的搜索,和parent_sku的数据对应',
]
);
$this->moduleDataSetup->getConnection()->endSetup();
}
public function revert(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, self::ATTRIBUTE_PARENT_NAMES);
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies(): array
{
return [];
}
}
@@ -0,0 +1,98 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
class AddSearchTermsProductAttribute implements SchemaPatchInterface
{
/**
* Constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private EavSetupFactory $eavSetupFactory
) {
}
/**
* {@inheritdoc}
*/
public function apply(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'search_terms',
[
'type' => 'text',
'label' => 'Search Terms',
'input' => 'textarea',
'source' => '',
'frontend' => '',
'required' => false,
'backend' => '',
'sort_order' => '30',
'global' => ScopedAttributeInterface::SCOPE_STORE,
'default' => null,
'visible' => true,
'user_defined' => true,
'searchable' => true,
'search_weight' => 4,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => '',
'group' => 'General',
'used_in_product_listing' => false,
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false
]
);
$this->moduleDataSetup->getConnection()->endSetup();
}
public function revert(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'search_tags');
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies(): array
{
return [];
}
}
@@ -0,0 +1,51 @@
<?php
namespace Stemcell\Catalog\Setup\Patch\Schema;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use \Magento\Catalog\Controller\Adminhtml\Product\Attribute\Validate;
use Magento\Catalog\Model\Product;
/**
* 1. 系统不允许使用product_type, type_id这两个属性code作为product code, 因此将原来加的product_type改成product_family
*/
class RenameProductTypeAttribute implements SchemaPatchInterface
{
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private CustomerSetupFactory $customerSetupFactory,
) {
}
public static function getDependencies()
{
return [];
}
public function getAliases()
{
return [];
}
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->updateAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'product_type',
'attribute_code',
'product_family'
);
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
}