init
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Add the redirect used by non-mega-menu top-level categories.
|
||||
*/
|
||||
namespace Esun\MegaMenu\Setup\Patch\Data;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class AddCategoryRedirectUrlAttribute implements DataPatchInterface
|
||||
{
|
||||
private const ATTRIBUTE_CODE = 'esun_megamenu_redirect_url';
|
||||
private const GROUP_NAME = 'Mega Menu Featured Product';
|
||||
|
||||
private $moduleDataSetup;
|
||||
private $categorySetupFactory;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CategorySetupFactory $categorySetupFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->categorySetupFactory = $categorySetupFactory;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
|
||||
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$entityTypeId = $categorySetup->getEntityTypeId(Category::ENTITY);
|
||||
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
|
||||
|
||||
$categorySetup->addAttribute($entityTypeId, self::ATTRIBUTE_CODE, [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Mega Menu Redirect URL',
|
||||
'input' => 'text',
|
||||
'required' => false,
|
||||
'sort_order' => 40,
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'group' => self::GROUP_NAME,
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
'note' => 'Used by normal top-level categories and Icon Category Mega Menu items. Accepts a CMS page URL key/store path or a complete URL. Ignored for Mega Menu Root categories.',
|
||||
]);
|
||||
|
||||
$categorySetup->addAttributeGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
self::GROUP_NAME,
|
||||
90
|
||||
);
|
||||
$attributeGroupId = $categorySetup->getAttributeGroupId(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
self::GROUP_NAME
|
||||
);
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
self::ATTRIBUTE_CODE,
|
||||
40
|
||||
);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
AddFeaturedProductCategoryAttributes::class
|
||||
];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Add category-level controls for the mega menu featured product card.
|
||||
*/
|
||||
namespace Esun\MegaMenu\Setup\Patch\Data;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Model\Category\Attribute\Backend\Image;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class AddFeaturedProductCategoryAttributes implements DataPatchInterface
|
||||
{
|
||||
private $moduleDataSetup;
|
||||
private $categorySetupFactory;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CategorySetupFactory $categorySetupFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->categorySetupFactory = $categorySetupFactory;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
|
||||
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$entityTypeId = $categorySetup->getEntityTypeId(Category::ENTITY);
|
||||
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
|
||||
$groupName = 'Mega Menu Featured Product';
|
||||
|
||||
$categorySetup->addAttributeGroup($entityTypeId, $attributeSetId, $groupName, 90);
|
||||
$attributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, $groupName);
|
||||
|
||||
$categorySetup->addAttribute($entityTypeId, 'esun_megamenu_featured_background', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Mega Menu Featured Background Image',
|
||||
'input' => 'image',
|
||||
'backend' => Image::class,
|
||||
'required' => false,
|
||||
'sort_order' => 10,
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'group' => 'Mega Menu Featured Product',
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
]);
|
||||
|
||||
$categorySetup->addAttribute($entityTypeId, 'esun_megamenu_featured_label', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Mega Menu Featured Label',
|
||||
'input' => 'text',
|
||||
'required' => false,
|
||||
'sort_order' => 20,
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'group' => 'Mega Menu Featured Product',
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
'default' => 'New Arrival',
|
||||
]);
|
||||
|
||||
$categorySetup->addAttribute($entityTypeId, 'esun_megamenu_featured_sku', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Mega Menu Featured Product SKU',
|
||||
'input' => 'text',
|
||||
'required' => false,
|
||||
'sort_order' => 30,
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'group' => 'Mega Menu Featured Product',
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
'note' => 'If empty or invalid, the FEATURED PRODUCT card is hidden.',
|
||||
]);
|
||||
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
'esun_megamenu_featured_background',
|
||||
10
|
||||
);
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
'esun_megamenu_featured_label',
|
||||
20
|
||||
);
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
'esun_megamenu_featured_sku',
|
||||
30
|
||||
);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace Esun\MegaMenu\Setup\Patch\Data;
|
||||
|
||||
use Esun\MegaMenu\Model\Config\Source\MegaMenuType;
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Model\Category\Attribute\Backend\Image;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class AddIconMenuCategoryAttributes implements DataPatchInterface
|
||||
{
|
||||
private $moduleDataSetup;
|
||||
private $categorySetupFactory;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CategorySetupFactory $categorySetupFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->categorySetupFactory = $categorySetupFactory;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
|
||||
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$entityTypeId = $categorySetup->getEntityTypeId(Category::ENTITY);
|
||||
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
|
||||
$groupName = 'Mega Menu Display';
|
||||
|
||||
$categorySetup->addAttributeGroup($entityTypeId, $attributeSetId, $groupName, 89);
|
||||
$attributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, $groupName);
|
||||
|
||||
$categorySetup->addAttribute($entityTypeId, 'esun_megamenu_type', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Mega Menu Type',
|
||||
'input' => 'select',
|
||||
'source' => MegaMenuType::class,
|
||||
'required' => false,
|
||||
'sort_order' => 10,
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'group' => $groupName,
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
'default' => MegaMenuType::PRODUCT,
|
||||
'note' => 'Used when this category ID is configured as a Mega Menu root.'
|
||||
]);
|
||||
|
||||
$categorySetup->addAttribute($entityTypeId, 'esun_megamenu_icon', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Mega Menu Icon',
|
||||
'input' => 'image',
|
||||
'backend' => Image::class,
|
||||
'required' => false,
|
||||
'sort_order' => 20,
|
||||
'global' => ScopedAttributeInterface::SCOPE_STORE,
|
||||
'group' => $groupName,
|
||||
'visible' => true,
|
||||
'user_defined' => true,
|
||||
'note' => 'Displayed for direct children of an Icon Category Mega Menu root.'
|
||||
]);
|
||||
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
'esun_megamenu_type',
|
||||
10
|
||||
);
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
'esun_megamenu_icon',
|
||||
20
|
||||
);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Ensure the mega menu category attributes are assigned to the category form group.
|
||||
*/
|
||||
namespace Esun\MegaMenu\Setup\Patch\Data;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class AssignFeaturedProductCategoryAttributes implements DataPatchInterface
|
||||
{
|
||||
private const GROUP_NAME = 'Mega Menu Featured Product';
|
||||
|
||||
private $moduleDataSetup;
|
||||
private $categorySetupFactory;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CategorySetupFactory $categorySetupFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->categorySetupFactory = $categorySetupFactory;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
|
||||
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$entityTypeId = $categorySetup->getEntityTypeId(Category::ENTITY);
|
||||
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
|
||||
|
||||
$categorySetup->addAttributeGroup($entityTypeId, $attributeSetId, self::GROUP_NAME, 90);
|
||||
$attributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, self::GROUP_NAME);
|
||||
|
||||
foreach ($this->getAttributes() as $attributeCode => $sortOrder) {
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSetId,
|
||||
$attributeGroupId,
|
||||
$attributeCode,
|
||||
$sortOrder
|
||||
);
|
||||
}
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
AddFeaturedProductCategoryAttributes::class
|
||||
];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getAttributes(): array
|
||||
{
|
||||
return [
|
||||
'esun_megamenu_featured_background' => 10,
|
||||
'esun_megamenu_featured_label' => 20,
|
||||
'esun_megamenu_featured_sku' => 30,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Create default CMS block used by the mega menu featured product area.
|
||||
*/
|
||||
namespace Esun\MegaMenu\Setup\Patch\Data;
|
||||
|
||||
use Magento\Cms\Model\BlockFactory;
|
||||
use Magento\Cms\Model\ResourceModel\Block as BlockResource;
|
||||
use Magento\Cms\Model\ResourceModel\Block\CollectionFactory as BlockCollectionFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class CreateFeaturedProductBlock implements DataPatchInterface
|
||||
{
|
||||
private const BLOCK_IDENTIFIER = 'megamenu_featured_product';
|
||||
|
||||
private $moduleDataSetup;
|
||||
private $blockFactory;
|
||||
private $blockResource;
|
||||
private $blockCollectionFactory;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
BlockFactory $blockFactory,
|
||||
BlockResource $blockResource,
|
||||
BlockCollectionFactory $blockCollectionFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->blockFactory = $blockFactory;
|
||||
$this->blockResource = $blockResource;
|
||||
$this->blockCollectionFactory = $blockCollectionFactory;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
|
||||
if (!$this->blockExists()) {
|
||||
$block = $this->blockFactory->create();
|
||||
$block->setTitle('Mega Menu Featured Product');
|
||||
$block->setIdentifier(self::BLOCK_IDENTIFIER);
|
||||
$block->setStores([Store::DEFAULT_STORE_ID]);
|
||||
$block->setIsActive(1);
|
||||
$block->setContent(
|
||||
'<div class="esun-megamenu-featured-card">' .
|
||||
'<div class="esun-megamenu-featured-kicker">New Arrival</div>' .
|
||||
'<div class="esun-megamenu-featured-name">PLA-Chameleon</div>' .
|
||||
'<a class="esun-megamenu-featured-link" href="{{store url=\'\'}}">Explore Product</a>' .
|
||||
'</div>'
|
||||
);
|
||||
$this->blockResource->save($block);
|
||||
}
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function blockExists(): bool
|
||||
{
|
||||
$collection = $this->blockCollectionFactory->create()
|
||||
->addFieldToFilter('identifier', self::BLOCK_IDENTIFIER)
|
||||
->setPageSize(1);
|
||||
|
||||
return (bool)$collection->getSize();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user