init
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Homepage\Setup\Patch\Data;
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class AddHomepageProductAttributes implements DataPatchInterface
|
||||
{
|
||||
private const ATTRIBUTE_GROUP = 'Homepage';
|
||||
|
||||
public function __construct(
|
||||
private readonly ModuleDataSetupInterface $moduleDataSetup,
|
||||
private readonly CategorySetupFactory $categorySetupFactory
|
||||
) {
|
||||
}
|
||||
|
||||
public function apply(): self
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
$catalogSetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
|
||||
$attributes = [
|
||||
'homepage_feature_content' => [
|
||||
'label' => 'New Product Feature Content',
|
||||
'sort_order' => 10,
|
||||
'note' => 'Build the upper-right feature panel, including the four icon/text items.',
|
||||
],
|
||||
'homepage_gallery_content' => [
|
||||
'label' => 'New Product Gallery Content',
|
||||
'sort_order' => 20,
|
||||
'note' => 'Build the lower-right image area.',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($attributes as $attributeCode => $attributeData) {
|
||||
if (!$catalogSetup->getAttributeId(Product::ENTITY, $attributeCode)) {
|
||||
$catalogSetup->addAttribute(Product::ENTITY, $attributeCode, [
|
||||
'type' => 'text',
|
||||
'label' => $attributeData['label'],
|
||||
'input' => 'textarea',
|
||||
'required' => false,
|
||||
'sort_order' => $attributeData['sort_order'],
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
'searchable' => false,
|
||||
'filterable' => false,
|
||||
'comparable' => false,
|
||||
'visible_on_front' => false,
|
||||
'is_html_allowed_on_front' => true,
|
||||
'wysiwyg_enabled' => true,
|
||||
'is_pagebuilder_enabled' => true,
|
||||
'used_in_product_listing' => false,
|
||||
'unique' => false,
|
||||
'note' => $attributeData['note'],
|
||||
]);
|
||||
}
|
||||
|
||||
$catalogSetup->updateAttribute(Product::ENTITY, $attributeCode, [
|
||||
'is_wysiwyg_enabled' => 1,
|
||||
'is_pagebuilder_enabled' => 1,
|
||||
'is_html_allowed_on_front' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
$entityTypeId = $catalogSetup->getEntityTypeId(Product::ENTITY);
|
||||
foreach ($catalogSetup->getAllAttributeSetIds($entityTypeId) as $attributeSetId) {
|
||||
$catalogSetup->addAttributeGroup(
|
||||
$entityTypeId,
|
||||
(int) $attributeSetId,
|
||||
self::ATTRIBUTE_GROUP,
|
||||
95
|
||||
);
|
||||
|
||||
foreach ($attributes as $attributeCode => $attributeData) {
|
||||
$catalogSetup->addAttributeToSet(
|
||||
$entityTypeId,
|
||||
(int) $attributeSetId,
|
||||
self::ATTRIBUTE_GROUP,
|
||||
$attributeCode,
|
||||
$attributeData['sort_order']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Homepage\Setup\Patch\Data;
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class EnableHomepageProductPageBuilder implements DataPatchInterface
|
||||
{
|
||||
private const ATTRIBUTE_CODES = [
|
||||
'homepage_feature_content',
|
||||
'homepage_gallery_content',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly ModuleDataSetupInterface $moduleDataSetup,
|
||||
private readonly CategorySetupFactory $categorySetupFactory
|
||||
) {
|
||||
}
|
||||
|
||||
public function apply(): self
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
$catalogSetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
|
||||
foreach (self::ATTRIBUTE_CODES as $attributeCode) {
|
||||
$catalogSetup->updateAttribute(Product::ENTITY, $attributeCode, [
|
||||
'is_wysiwyg_enabled' => 1,
|
||||
'is_pagebuilder_enabled' => 1,
|
||||
'is_html_allowed_on_front' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
AddHomepageProductAttributes::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user