init
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Esun\MegaMenu\Model\Config\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
|
||||
|
||||
class MegaMenuType extends AbstractSource
|
||||
{
|
||||
public const PRODUCT = 'product';
|
||||
public const ICON_CATEGORY = 'icon_category';
|
||||
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
['value' => self::PRODUCT, 'label' => __('Product Mega Menu')],
|
||||
['value' => self::ICON_CATEGORY, 'label' => __('Icon Category Mega Menu')]
|
||||
];
|
||||
}
|
||||
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
if ($this->_options === null) {
|
||||
$this->_options = $this->toOptionArray();
|
||||
}
|
||||
|
||||
return $this->_options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Force the catalog top navigation to use the Esun mega menu template.
|
||||
*/
|
||||
namespace Esun\MegaMenu\Plugin;
|
||||
|
||||
use Esun\MegaMenu\ViewModel\MegaMenuData;
|
||||
use Magento\Theme\Block\Html\Topmenu;
|
||||
|
||||
class TopmenuTemplatePlugin
|
||||
{
|
||||
private $megaMenuData;
|
||||
|
||||
public function __construct(MegaMenuData $megaMenuData)
|
||||
{
|
||||
$this->megaMenuData = $megaMenuData;
|
||||
}
|
||||
|
||||
public function beforeToHtml(Topmenu $subject): void
|
||||
{
|
||||
if ($subject->getNameInLayout() !== 'catalog.topnav') {
|
||||
return;
|
||||
}
|
||||
|
||||
$subject->setData('view_model', $this->megaMenuData);
|
||||
$subject->setTemplate('Esun_MegaMenu::html/topmenu.phtml');
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
<?php
|
||||
/**
|
||||
* MegaMenu Data ViewModel for Magento 2.4.9
|
||||
*/
|
||||
namespace Esun\MegaMenu\ViewModel;
|
||||
|
||||
use Esun\Catalog\Model\Product\CardPriceResolver;
|
||||
use Esun\MegaMenu\Model\Config\Source\MegaMenuType;
|
||||
use Magento\Catalog\Helper\Image as ImageHelper;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
|
||||
use Magento\Cms\Model\Template\FilterProvider;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Pricing\PriceCurrencyInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Framework\View\Element\Block\ArgumentInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
|
||||
class MegaMenuData implements ArgumentInterface
|
||||
{
|
||||
private const XML_PATH_ENABLED = 'esun_megamenu/general/enabled';
|
||||
private const XML_PATH_TITLE = 'esun_megamenu/general/title';
|
||||
private const XML_PATH_ROOT_CATEGORY_ID = 'esun_megamenu/general/root_category_id';
|
||||
private const XML_PATH_ROOT_CATEGORY_IDS = 'esun_megamenu/general/root_category_ids';
|
||||
private const XML_PATH_PRODUCTS_PER_SERIES = 'esun_megamenu/general/products_per_series';
|
||||
private const XML_PATH_SERIES_LIMIT = 'esun_megamenu/general/series_limit';
|
||||
|
||||
private $categoryCollectionFactory;
|
||||
private $productCollectionFactory;
|
||||
private $imageHelper;
|
||||
private $jsonSerializer;
|
||||
private $storeManager;
|
||||
private $scopeConfig;
|
||||
private $priceCurrency;
|
||||
private CardPriceResolver $cardPriceResolver;
|
||||
private $productRepository;
|
||||
private $filterProvider;
|
||||
private $categoryUrlCache = [];
|
||||
|
||||
public function __construct(
|
||||
CategoryCollectionFactory $categoryCollectionFactory,
|
||||
ProductCollectionFactory $productCollectionFactory,
|
||||
ImageHelper $imageHelper,
|
||||
JsonSerializer $jsonSerializer,
|
||||
StoreManagerInterface $storeManager,
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
PriceCurrencyInterface $priceCurrency,
|
||||
CardPriceResolver $cardPriceResolver,
|
||||
ProductRepositoryInterface $productRepository,
|
||||
FilterProvider $filterProvider
|
||||
) {
|
||||
$this->categoryCollectionFactory = $categoryCollectionFactory;
|
||||
$this->productCollectionFactory = $productCollectionFactory;
|
||||
$this->imageHelper = $imageHelper;
|
||||
$this->jsonSerializer = $jsonSerializer;
|
||||
$this->storeManager = $storeManager;
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
$this->priceCurrency = $priceCurrency;
|
||||
$this->cardPriceResolver = $cardPriceResolver;
|
||||
$this->productRepository = $productRepository;
|
||||
$this->filterProvider = $filterProvider;
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return trim((string)$this->scopeConfig->getValue(self::XML_PATH_TITLE, ScopeInterface::SCOPE_STORE)) ?: 'CLASSIFICATION';
|
||||
}
|
||||
|
||||
public function getRootCategoryId(): int
|
||||
{
|
||||
return (int)$this->scopeConfig->getValue(self::XML_PATH_ROOT_CATEGORY_ID, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
|
||||
public function getRootCategoryIds(): array
|
||||
{
|
||||
$configuredIds = (string)$this->scopeConfig->getValue(self::XML_PATH_ROOT_CATEGORY_IDS, ScopeInterface::SCOPE_STORE);
|
||||
$legacyId = $this->getRootCategoryId();
|
||||
$ids = [];
|
||||
|
||||
foreach (preg_split('/[\s,;]+/', $configuredIds) ?: [] as $value) {
|
||||
$id = (int)trim($value);
|
||||
|
||||
if ($id > 0) {
|
||||
$ids[$id] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($legacyId > 0) {
|
||||
$ids[$legacyId] = $legacyId;
|
||||
}
|
||||
|
||||
return array_values($ids);
|
||||
}
|
||||
|
||||
public function isMegaMenuRootCategory(int $categoryId): bool
|
||||
{
|
||||
return in_array($categoryId, $this->getRootCategoryIds(), true);
|
||||
}
|
||||
|
||||
public function getMegaMenuType(int $rootCategoryId): string
|
||||
{
|
||||
$category = $this->getCategoryById($rootCategoryId, ['esun_megamenu_type', 'is_active']);
|
||||
$type = $category ? trim((string)$category->getData('esun_megamenu_type')) : '';
|
||||
|
||||
return $type === MegaMenuType::ICON_CATEGORY ? $type : MegaMenuType::PRODUCT;
|
||||
}
|
||||
|
||||
public function isIconCategoryMenu(int $rootCategoryId): bool
|
||||
{
|
||||
return $this->getMegaMenuType($rootCategoryId) === MegaMenuType::ICON_CATEGORY;
|
||||
}
|
||||
|
||||
public function getIconCategoryMenuData(int $rootCategoryId): array
|
||||
{
|
||||
if (!$rootCategoryId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$storeId = (int)$this->storeManager->getStore()->getId();
|
||||
$columns = $this->categoryCollectionFactory->create()
|
||||
->setStoreId($storeId)
|
||||
->addAttributeToSelect([
|
||||
'name',
|
||||
'is_active',
|
||||
'include_in_menu',
|
||||
'url_key',
|
||||
'url_path',
|
||||
'esun_megamenu_icon',
|
||||
'esun_megamenu_redirect_url'
|
||||
])
|
||||
->addAttributeToFilter('parent_id', $rootCategoryId)
|
||||
->addAttributeToFilter('is_active', 1)
|
||||
->addAttributeToFilter('include_in_menu', 1)
|
||||
->setOrder('position', 'ASC');
|
||||
|
||||
$menuData = [];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$links = [];
|
||||
$children = $this->getChildCategories((int)$column->getId(), $storeId);
|
||||
|
||||
foreach ($children as $child) {
|
||||
$links[] = [
|
||||
'id' => (int)$child->getId(),
|
||||
'name' => (string)$child->getName(),
|
||||
'url' => $this->getConfiguredCategoryUrl($child)
|
||||
];
|
||||
}
|
||||
|
||||
$menuData[] = [
|
||||
'id' => (int)$column->getId(),
|
||||
'name' => (string)$column->getName(),
|
||||
'url' => $this->getConfiguredCategoryUrl($column),
|
||||
'icon_url' => $this->getCategoryImageUrl(
|
||||
trim((string)$column->getData('esun_megamenu_icon'))
|
||||
),
|
||||
'children' => $links
|
||||
];
|
||||
}
|
||||
|
||||
return $menuData;
|
||||
}
|
||||
|
||||
public function getFeaturedProductData(int $rootCategoryId): ?array
|
||||
{
|
||||
if (!$rootCategoryId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$storeId = (int)$this->storeManager->getStore()->getId();
|
||||
$category = $this->getCategoryById($rootCategoryId, [
|
||||
'esun_megamenu_featured_background',
|
||||
'esun_megamenu_featured_label',
|
||||
'esun_megamenu_featured_sku',
|
||||
'is_active'
|
||||
]);
|
||||
|
||||
if (!$category || !$category->getId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sku = trim((string)$category->getData('esun_megamenu_featured_sku'));
|
||||
|
||||
if ($sku === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$product = $this->productRepository->get($sku, false, $storeId);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((int)$product->getStatus() !== Status::STATUS_ENABLED) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$backgroundImage = trim((string)$category->getData('esun_megamenu_featured_background'));
|
||||
$label = trim((string)$category->getData('esun_megamenu_featured_label')) ?: 'New Arrival';
|
||||
|
||||
return [
|
||||
'label' => $label,
|
||||
'name' => (string)$product->getName(),
|
||||
'url' => $product->getProductUrl(),
|
||||
'category_background_url' => $this->getCategoryImageUrl($backgroundImage)
|
||||
];
|
||||
}
|
||||
|
||||
public function getTopLevelCategoryUrl(int $categoryId, string $fallbackUrl = '#'): string
|
||||
{
|
||||
if (!$categoryId || $this->isMegaMenuRootCategory($categoryId)) {
|
||||
return $fallbackUrl;
|
||||
}
|
||||
|
||||
if (isset($this->categoryUrlCache[$categoryId])) {
|
||||
return $this->categoryUrlCache[$categoryId];
|
||||
}
|
||||
|
||||
$category = $this->getCategoryById($categoryId, [
|
||||
'esun_megamenu_redirect_url',
|
||||
'url_key',
|
||||
'url_path',
|
||||
'is_active'
|
||||
]);
|
||||
|
||||
if (!$category || !$category->getId()) {
|
||||
return $fallbackUrl;
|
||||
}
|
||||
|
||||
$redirectUrl = trim((string)$category->getData('esun_megamenu_redirect_url'));
|
||||
$resolvedUrl = $redirectUrl !== ''
|
||||
? $this->resolveRedirectUrl($redirectUrl)
|
||||
: $category->getUrl();
|
||||
|
||||
$this->categoryUrlCache[$categoryId] = $resolvedUrl ?: $fallbackUrl;
|
||||
|
||||
return $this->categoryUrlCache[$categoryId];
|
||||
}
|
||||
|
||||
private function getConfiguredCategoryUrl(Category $category): string
|
||||
{
|
||||
$redirectUrl = trim((string)$category->getData('esun_megamenu_redirect_url'));
|
||||
|
||||
return $redirectUrl !== '' ? $this->resolveRedirectUrl($redirectUrl) : $category->getUrl();
|
||||
}
|
||||
|
||||
public function getRootCategoryUrl(?int $rootCategoryId = null): string
|
||||
{
|
||||
$rootCategoryId = $rootCategoryId ?: $this->getRootCategoryId();
|
||||
|
||||
if (!$rootCategoryId) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
$category = $this->getCategoryById($rootCategoryId, [
|
||||
'esun_megamenu_redirect_url',
|
||||
'is_active',
|
||||
'url_key',
|
||||
'url_path'
|
||||
]);
|
||||
|
||||
return $category && $category->getId() ? $this->getConfiguredCategoryUrl($category) : '#';
|
||||
}
|
||||
|
||||
public function getRootCategoryName(int $rootCategoryId): string
|
||||
{
|
||||
if (!$rootCategoryId) {
|
||||
return $this->getTitle();
|
||||
}
|
||||
|
||||
$category = $this->getCategoryById($rootCategoryId, ['name', 'is_active']);
|
||||
|
||||
return $category && $category->getId() ? (string)$category->getName() : $this->getTitle();
|
||||
}
|
||||
|
||||
public function getRootCategoryDescription(int $rootCategoryId): string
|
||||
{
|
||||
if (!$rootCategoryId) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$category = $this->getCategoryById($rootCategoryId, ['description', 'is_active']);
|
||||
|
||||
if (!$category || !$category->getId()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$description = trim((string)$category->getDescription());
|
||||
|
||||
return $description !== ''
|
||||
? (string)$this->filterProvider->getPageFilter()->filter($description)
|
||||
: '';
|
||||
}
|
||||
|
||||
public function getProductsPerSeries(): int
|
||||
{
|
||||
$limit = (int)$this->scopeConfig->getValue(self::XML_PATH_PRODUCTS_PER_SERIES, ScopeInterface::SCOPE_STORE);
|
||||
|
||||
return $limit > 0 ? $limit : 6;
|
||||
}
|
||||
|
||||
public function getSeriesLimit(): int
|
||||
{
|
||||
$limit = (int)$this->scopeConfig->getValue(self::XML_PATH_SERIES_LIMIT, ScopeInterface::SCOPE_STORE);
|
||||
|
||||
return $limit > 0 ? $limit : 8;
|
||||
}
|
||||
|
||||
public function getMegaMenuJson(?int $rootCategoryId = null): string
|
||||
{
|
||||
return $this->jsonSerializer->serialize($this->getMegaMenuData($rootCategoryId));
|
||||
}
|
||||
|
||||
public function getMegaMenuData(?int $rootCategoryId = null): array
|
||||
{
|
||||
$rootCategoryId = $rootCategoryId ?: $this->getRootCategoryId();
|
||||
|
||||
if (!$rootCategoryId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$storeId = $this->storeManager->getStore()->getId();
|
||||
|
||||
$filamentCategories = $this->categoryCollectionFactory->create()
|
||||
->setStoreId($storeId)
|
||||
->addAttributeToSelect([
|
||||
'name',
|
||||
'is_active',
|
||||
'include_in_menu',
|
||||
'url_key',
|
||||
'url_path',
|
||||
'esun_megamenu_redirect_url'
|
||||
])
|
||||
->addAttributeToFilter('parent_id', $rootCategoryId)
|
||||
->addAttributeToFilter('is_active', 1)
|
||||
->setOrder('position', 'ASC');
|
||||
|
||||
$menuData = [];
|
||||
|
||||
foreach ($filamentCategories as $filamentCategory) {
|
||||
$filamentData = [
|
||||
'id' => (int)$filamentCategory->getId(),
|
||||
'name' => (string)$filamentCategory->getName(),
|
||||
'url' => $filamentCategory->getUrl(),
|
||||
'seriesCategories' => []
|
||||
];
|
||||
|
||||
$seriesCategories = $this->getChildCategories((int)$filamentCategory->getId(), $storeId, $this->getSeriesLimit());
|
||||
|
||||
foreach ($seriesCategories as $seriesCategory) {
|
||||
$filamentData['seriesCategories'][] = $this->buildSeriesCategoryData($seriesCategory);
|
||||
}
|
||||
|
||||
// Some menu roots, such as Resins, assign products directly to their
|
||||
// first-level child categories instead of using a series level.
|
||||
if (!$filamentData['seriesCategories']) {
|
||||
$filamentData['seriesCategories'][] = $this->buildSeriesCategoryData($filamentCategory);
|
||||
}
|
||||
|
||||
$menuData[] = $filamentData;
|
||||
}
|
||||
|
||||
return $menuData;
|
||||
}
|
||||
|
||||
private function getChildCategories(int $parentId, int $storeId, int $pageSize = 0)
|
||||
{
|
||||
$collection = $this->categoryCollectionFactory->create()
|
||||
->setStoreId($storeId)
|
||||
->addAttributeToSelect([
|
||||
'name',
|
||||
'is_active',
|
||||
'include_in_menu',
|
||||
'url_key',
|
||||
'url_path',
|
||||
'esun_megamenu_redirect_url'
|
||||
])
|
||||
->addAttributeToFilter('parent_id', $parentId)
|
||||
->addAttributeToFilter('is_active', 1)
|
||||
->addAttributeToFilter('include_in_menu', 1)
|
||||
->setOrder('position', 'ASC');
|
||||
|
||||
if ($pageSize > 0) {
|
||||
$collection->setPageSize($pageSize)->setCurPage(1);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
private function buildSeriesCategoryData(Category $category): array
|
||||
{
|
||||
return [
|
||||
'id' => (int)$category->getId(),
|
||||
'name' => (string)$category->getName(),
|
||||
'url' => $category->getUrl(),
|
||||
'products' => $this->getProductsForCategory($category)
|
||||
];
|
||||
}
|
||||
|
||||
private function getProductsForCategory(Category $category): array
|
||||
{
|
||||
$storeId = $this->storeManager->getStore()->getId();
|
||||
$collection = $this->productCollectionFactory->create()
|
||||
->setStoreId($storeId)
|
||||
->addStoreFilter($storeId)
|
||||
->addAttributeToSelect(['name', 'price', 'small_image', 'thumbnail'])
|
||||
->addFinalPrice()
|
||||
->addCategoryFilter($category)
|
||||
->addAttributeToFilter('status', Status::STATUS_ENABLED)
|
||||
->setVisibility([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH])
|
||||
->addUrlRewrite()
|
||||
->setPageSize($this->getProductsPerSeries())
|
||||
->setCurPage(1);
|
||||
|
||||
$products = [];
|
||||
|
||||
foreach ($collection as $product) {
|
||||
$products[] = [
|
||||
'id' => (int)$product->getId(),
|
||||
'name' => (string)$product->getName(),
|
||||
'url' => $product->getProductUrl(),
|
||||
'price' => $this->priceCurrency->format(
|
||||
$this->cardPriceResolver->getFinalPrice($product),
|
||||
false
|
||||
),
|
||||
'image_url' => $this->imageHelper->init($product, 'category_page_grid')->getUrl()
|
||||
];
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
private function getCategoryById(int $categoryId, array $attributes): ?Category
|
||||
{
|
||||
$storeId = $this->storeManager->getStore()->getId();
|
||||
$collection = $this->categoryCollectionFactory->create()
|
||||
->setStoreId($storeId)
|
||||
->addAttributeToSelect($attributes)
|
||||
->addAttributeToFilter('entity_id', $categoryId)
|
||||
->addAttributeToFilter('is_active', 1)
|
||||
->setPageSize(1);
|
||||
|
||||
$category = $collection->getFirstItem();
|
||||
|
||||
return $category && $category->getId() ? $category : null;
|
||||
}
|
||||
|
||||
private function getCategoryImageUrl(string $image): string
|
||||
{
|
||||
if ($image === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('#^https?://#i', $image)) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
$image = ltrim($image, '/');
|
||||
if (strpos($image, 'media/') === 0) {
|
||||
$image = substr($image, strlen('media/'));
|
||||
}
|
||||
|
||||
$mediaPath = strpos($image, 'catalog/category/') === 0
|
||||
? $image
|
||||
: 'catalog/category/' . $image;
|
||||
|
||||
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . $mediaPath;
|
||||
}
|
||||
|
||||
private function resolveRedirectUrl(string $redirectUrl): string
|
||||
{
|
||||
if (preg_match('#^https?://#i', $redirectUrl)) {
|
||||
return $redirectUrl;
|
||||
}
|
||||
|
||||
$path = ltrim($redirectUrl, '/');
|
||||
|
||||
return rtrim(
|
||||
$this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK),
|
||||
'/'
|
||||
) . '/' . $path;
|
||||
}
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
|
||||
<acl>
|
||||
<resources>
|
||||
<resource id="Magento_Backend::admin">
|
||||
<resource id="Magento_Backend::stores">
|
||||
<resource id="Magento_Backend::stores_settings">
|
||||
<resource id="Magento_Config::config">
|
||||
<resource id="Esun_MegaMenu::config" title="Esun Mega Menu Configuration" sortOrder="90"/>
|
||||
</resource>
|
||||
</resource>
|
||||
</resource>
|
||||
</resource>
|
||||
</resources>
|
||||
</acl>
|
||||
</config>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<tab id="esun" translate="label" sortOrder="300">
|
||||
<label>Esun</label>
|
||||
</tab>
|
||||
<section id="esun_megamenu" translate="label" type="text" sortOrder="920" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Mega Menu</label>
|
||||
<tab>esun</tab>
|
||||
<resource>Esun_MegaMenu::config</resource>
|
||||
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>General Settings</label>
|
||||
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Enable Mega Menu</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
</field>
|
||||
<field id="title" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Fallback Menu Title</label>
|
||||
<comment>Used only when the configured category is not already present in the Magento top menu.</comment>
|
||||
</field>
|
||||
<field id="root_category_ids" translate="label comment" type="textarea" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Mega Menu Root Category IDs</label>
|
||||
<comment>Enter the top-level category IDs that should use the mega menu, separated by comma, space, semicolon, or new line. Example: 12, 38, 52.</comment>
|
||||
</field>
|
||||
<field id="root_category_id" translate="label comment" type="text" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Legacy Single Root Category ID</label>
|
||||
<comment>Backward compatible single category ID. The new multi-ID field above is preferred.</comment>
|
||||
<validate>validate-number validate-greater-than-zero</validate>
|
||||
</field>
|
||||
<field id="products_per_series" translate="label comment" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Products Per Series</label>
|
||||
<comment>Number of products displayed under each series category.</comment>
|
||||
<validate>validate-number validate-greater-than-zero</validate>
|
||||
</field>
|
||||
<field id="series_limit" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Series Category Limit</label>
|
||||
<comment>Maximum number of series categories displayed for the active Filament Category.</comment>
|
||||
<validate>validate-number validate-greater-than-zero</validate>
|
||||
</field>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
|
||||
<default>
|
||||
<esun_megamenu>
|
||||
<general>
|
||||
<enabled>1</enabled>
|
||||
<title>CLASSIFICATION</title>
|
||||
<root_category_ids>38</root_category_ids>
|
||||
<root_category_id>38</root_category_id>
|
||||
<products_per_series>6</products_per_series>
|
||||
<series_limit>8</series_limit>
|
||||
</general>
|
||||
</esun_megamenu>
|
||||
</default>
|
||||
</config>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
|
||||
<type name="Magento\Theme\Block\Html\Topmenu">
|
||||
<plugin name="esun_megamenu_topmenu_template" type="Esun\MegaMenu\Plugin\TopmenuTemplatePlugin"/>
|
||||
</type>
|
||||
</config>
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="Esun_MegaMenu" setup_version="1.0.0">
|
||||
<sequence>
|
||||
<module name="Magento_Theme"/>
|
||||
<module name="Magento_Catalog"/>
|
||||
<module name="Magento_Cms"/>
|
||||
<module name="Magento_Config"/>
|
||||
<module name="Esun_Catalog"/>
|
||||
</sequence>
|
||||
</module>
|
||||
</config>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Esun_MegaMenu Module Registration
|
||||
*
|
||||
* @category Esun
|
||||
* @package Esun_MegaMenu
|
||||
* @author Gemini Developer
|
||||
*/
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::MODULE,
|
||||
'Esun_MegaMenu',
|
||||
__DIR__
|
||||
);
|
||||
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
|
||||
<fieldset name="esun_megamenu_display" sortOrder="94">
|
||||
<settings>
|
||||
<collapsible>true</collapsible>
|
||||
<label translate="true">Mega Menu Display</label>
|
||||
</settings>
|
||||
<field name="esun_megamenu_type" sortOrder="10" formElement="select">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="source" xsi:type="string">category</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<dataType>text</dataType>
|
||||
<label translate="true">Mega Menu Type</label>
|
||||
<notice translate="true">Used when this category ID is configured as a Mega Menu root. Existing menus default to Product Mega Menu.</notice>
|
||||
<required>false</required>
|
||||
</settings>
|
||||
<formElements>
|
||||
<select>
|
||||
<settings>
|
||||
<options class="Esun\MegaMenu\Model\Config\Source\MegaMenuType"/>
|
||||
</settings>
|
||||
</select>
|
||||
</formElements>
|
||||
</field>
|
||||
<field name="esun_megamenu_icon" sortOrder="20" formElement="imageUploader">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="source" xsi:type="string">category</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<elementTmpl>ui/form/element/uploader/image</elementTmpl>
|
||||
<dataType>string</dataType>
|
||||
<label translate="true">Mega Menu Icon</label>
|
||||
<notice translate="true">Used on direct child categories in the Icon Category Mega Menu.</notice>
|
||||
<required>false</required>
|
||||
</settings>
|
||||
<formElements>
|
||||
<imageUploader>
|
||||
<settings>
|
||||
<required>false</required>
|
||||
<uploaderConfig>
|
||||
<param xsi:type="url" name="url" path="catalog/category_image/upload"/>
|
||||
</uploaderConfig>
|
||||
<previewTmpl>Magento_Catalog/image-preview</previewTmpl>
|
||||
<openDialogTitle>Media Gallery</openDialogTitle>
|
||||
<initialMediaGalleryOpenSubpath>catalog/category</initialMediaGalleryOpenSubpath>
|
||||
<allowedExtensions>jpg jpeg gif png webp</allowedExtensions>
|
||||
<maxFileSize>4194304</maxFileSize>
|
||||
</settings>
|
||||
</imageUploader>
|
||||
</formElements>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fieldset name="esun_megamenu_featured_product" sortOrder="95">
|
||||
<settings>
|
||||
<collapsible>true</collapsible>
|
||||
<label translate="true">Mega Menu Featured Product</label>
|
||||
</settings>
|
||||
<field name="esun_megamenu_featured_background" sortOrder="10" formElement="imageUploader">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="source" xsi:type="string">category</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<elementTmpl>ui/form/element/uploader/image</elementTmpl>
|
||||
<dataType>string</dataType>
|
||||
<label translate="true">Featured Background Image</label>
|
||||
<visible>true</visible>
|
||||
<required>false</required>
|
||||
</settings>
|
||||
<formElements>
|
||||
<imageUploader>
|
||||
<settings>
|
||||
<required>false</required>
|
||||
<uploaderConfig>
|
||||
<param xsi:type="url" name="url" path="catalog/category_image/upload"/>
|
||||
</uploaderConfig>
|
||||
<previewTmpl>Magento_Catalog/image-preview</previewTmpl>
|
||||
<openDialogTitle>Media Gallery</openDialogTitle>
|
||||
<initialMediaGalleryOpenSubpath>catalog/category</initialMediaGalleryOpenSubpath>
|
||||
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
|
||||
<maxFileSize>4194304</maxFileSize>
|
||||
</settings>
|
||||
</imageUploader>
|
||||
</formElements>
|
||||
</field>
|
||||
<field name="esun_megamenu_featured_label" sortOrder="20" formElement="input">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="source" xsi:type="string">category</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<dataType>text</dataType>
|
||||
<label translate="true">Featured Label</label>
|
||||
<notice translate="true">Example: New Arrival</notice>
|
||||
<visible>true</visible>
|
||||
<required>false</required>
|
||||
</settings>
|
||||
</field>
|
||||
<field name="esun_megamenu_featured_sku" sortOrder="30" formElement="input">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="source" xsi:type="string">category</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<dataType>text</dataType>
|
||||
<label translate="true">Featured Product SKU</label>
|
||||
<notice translate="true">If empty or invalid, the FEATURED PRODUCT card is hidden.</notice>
|
||||
<visible>true</visible>
|
||||
<required>false</required>
|
||||
</settings>
|
||||
</field>
|
||||
<field name="esun_megamenu_redirect_url" sortOrder="40" formElement="input">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="source" xsi:type="string">category</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<dataType>text</dataType>
|
||||
<label translate="true">Redirect URL</label>
|
||||
<notice translate="true">Used by normal top-level menu categories and Icon Category Mega Menu items. Enter a CMS page URL key/store path or a complete http/https URL. Mega Menu Root categories ignore this value.</notice>
|
||||
<visible>true</visible>
|
||||
<required>false</required>
|
||||
<validation>
|
||||
<rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
|
||||
</validation>
|
||||
</settings>
|
||||
</field>
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<move element="logo"
|
||||
destination="header-wrapper"
|
||||
before="-"/>
|
||||
<move element="navigation.sections"
|
||||
destination="header-wrapper"
|
||||
after="logo"/>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceBlock name="navigation.sections">
|
||||
<block class="Magento\Framework\View\Element\Template"
|
||||
name="store.menu"
|
||||
group="navigation-sections"
|
||||
template="Magento_Theme::html/container.phtml">
|
||||
<arguments>
|
||||
<argument name="title" translate="true" xsi:type="string">Menu</argument>
|
||||
</arguments>
|
||||
<block class="Magento\Theme\Block\Html\Topmenu"
|
||||
name="catalog.topnav"
|
||||
template="Esun_MegaMenu::html/topmenu.phtml"
|
||||
ttl="3600"
|
||||
before="-">
|
||||
<arguments>
|
||||
<argument name="view_model" xsi:type="object">Esun\MegaMenu\ViewModel\MegaMenuData</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
</block>
|
||||
</referenceBlock>
|
||||
<move element="logo"
|
||||
destination="header-wrapper"
|
||||
before="-"/>
|
||||
<move element="navigation.sections"
|
||||
destination="header-wrapper"
|
||||
after="logo"/>
|
||||
</body>
|
||||
</page>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceBlock name="catalog.topnav">
|
||||
<arguments>
|
||||
<argument name="view_model" xsi:type="object">Esun\MegaMenu\ViewModel\MegaMenuData</argument>
|
||||
</arguments>
|
||||
<action method="setTemplate">
|
||||
<argument name="template" xsi:type="string">Esun_MegaMenu::html/topmenu.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Icon category mega menu. Kept separate from the existing product mega menu.
|
||||
*
|
||||
* @var \Magento\Framework\View\Element\Template $block
|
||||
* @var \Magento\Framework\Escaper $escaper
|
||||
*/
|
||||
$rootCategoryId = (int)$block->getData('root_category_id');
|
||||
$label = (string)$block->getData('menu_label');
|
||||
$class = (string)$block->getData('menu_class');
|
||||
$menuUrl = (string)$block->getData('menu_url');
|
||||
$description = trim((string)$block->getData('menu_description'));
|
||||
$menuItems = (array)$block->getData('menu_items');
|
||||
$hasImages = false;
|
||||
$hasDescription = $description !== '';
|
||||
|
||||
foreach ($menuItems as $menuItem) {
|
||||
if (!empty($menuItem['icon_url'])) {
|
||||
$hasImages = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$layoutClass = $hasImages
|
||||
? 'esun-icon-megamenu--visual'
|
||||
: 'esun-icon-megamenu--text-only';
|
||||
$parentClass = $hasImages ? 'parent ' : '';
|
||||
$linkedMenuClass = !$hasImages ? 'esun-linked-megamenu-trigger' : '';
|
||||
$descriptionClass = $hasDescription ? 'has-description' : 'no-description';
|
||||
$textDividerIndex = !$hasImages && count($menuItems) > 1
|
||||
? (int)ceil(count($menuItems) / 2)
|
||||
: -1;
|
||||
?>
|
||||
<li class="<?= $escaper->escapeHtmlAttr(trim('level0 level-top ' . $parentClass . 'category-item esun-megamenu-trigger esun-icon-megamenu-trigger ' . $linkedMenuClass . ' ' . $class)) ?>"
|
||||
data-category="<?= $rootCategoryId ?>">
|
||||
<a href="<?= !$hasImages ? $escaper->escapeUrl($menuUrl) : 'javascript:void(0)' ?>"
|
||||
class="level-top"
|
||||
aria-haspopup="true">
|
||||
<span><?= $escaper->escapeHtml($label) ?></span>
|
||||
</a>
|
||||
<?php if (!$hasImages): ?>
|
||||
<button class="esun-megamenu-toggle"
|
||||
type="button"
|
||||
aria-label="<?= $escaper->escapeHtmlAttr(__('Toggle %1 submenu', $label)) ?>"
|
||||
aria-expanded="false">
|
||||
<span aria-hidden="true"></span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="esun-megamenu-wrapper esun-icon-megamenu-wrapper <?= $escaper->escapeHtmlAttr($layoutClass . ' ' . $descriptionClass) ?>">
|
||||
<div class="esun-icon-megamenu-inner">
|
||||
<?php if ($hasImages && $hasDescription): ?>
|
||||
<aside class="esun-icon-megamenu-intro">
|
||||
<div class="esun-icon-megamenu-intro-content">
|
||||
<?= /* @noEscape */ $description ?>
|
||||
</div>
|
||||
</aside>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="esun-icon-megamenu-items">
|
||||
<?php foreach ($menuItems as $itemIndex => $item): ?>
|
||||
<?php $hasItemImage = !empty($item['icon_url']); ?>
|
||||
<?php $hasChildren = !empty($item['children']); ?>
|
||||
<?php $dividerClass = (int)$itemIndex === $textDividerIndex ? 'is-second-half-start' : ''; ?>
|
||||
<section class="esun-icon-megamenu-column <?= $hasItemImage ? 'has-image' : 'no-image' ?> <?= $dividerClass ?>">
|
||||
<?php if ($hasItemImage): ?>
|
||||
<?php if (!$hasChildren): ?>
|
||||
<a class="esun-icon-megamenu-image-wrap"
|
||||
href="<?= $escaper->escapeUrl((string)$item['url']) ?>">
|
||||
<?php else: ?>
|
||||
<div class="esun-icon-megamenu-image-wrap">
|
||||
<?php endif; ?>
|
||||
<img class="esun-icon-megamenu-image"
|
||||
src="<?= $escaper->escapeUrl((string)$item['icon_url']) ?>"
|
||||
alt="<?= $escaper->escapeHtmlAttr((string)$item['name']) ?>"
|
||||
loading="lazy"/>
|
||||
<span class="esun-icon-megamenu-image-title">
|
||||
<?= $escaper->escapeHtml((string)$item['name']) ?>
|
||||
</span>
|
||||
<?php if (!$hasChildren): ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<div class="esun-icon-megamenu-content">
|
||||
<?php if (!$hasItemImage): ?>
|
||||
<?php if (!$hasChildren): ?>
|
||||
<a class="esun-icon-megamenu-title"
|
||||
href="<?= $escaper->escapeUrl((string)$item['url']) ?>">
|
||||
<?= $escaper->escapeHtml((string)$item['name']) ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<span class="esun-icon-megamenu-title">
|
||||
<?= $escaper->escapeHtml((string)$item['name']) ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php if ($hasChildren): ?>
|
||||
<ul class="esun-icon-megamenu-links">
|
||||
<?php foreach ((array)$item['children'] as $child): ?>
|
||||
<li>
|
||||
<a href="<?= $escaper->escapeUrl((string)$child['url']) ?>">
|
||||
<?= $escaper->escapeHtml((string)$child['name']) ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/**
|
||||
* Magento top menu with an Esun classification mega menu attached to one level-0 node.
|
||||
*
|
||||
* @var \Magento\Theme\Block\Html\Topmenu $block
|
||||
* @var \Magento\Framework\Escaper $escaper
|
||||
* @var \Esun\MegaMenu\ViewModel\MegaMenuData|null $viewModel
|
||||
*/
|
||||
$viewModel = $block->getData('view_model');
|
||||
|
||||
if (!$viewModel || !$viewModel->isEnabled()) {
|
||||
$columnsLimit = $block->getColumnsLimit() ?: 0;
|
||||
$_menuHtml = $block->getHtml('level-top', 'submenu', $columnsLimit);
|
||||
?>
|
||||
<nav class="navigation" data-action="navigation">
|
||||
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
|
||||
<?= /* @noEscape */ $_menuHtml ?>
|
||||
<?= $block->getChildHtml() ?>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
|
||||
$columnsLimit = $block->getColumnsLimit() ?: 0;
|
||||
$block->getHtml('level-top', 'submenu', $columnsLimit);
|
||||
$rootCategoryIds = $viewModel->getRootCategoryIds();
|
||||
$legacyRootCategoryId = $viewModel->getRootCategoryId();
|
||||
$targetTitle = strtoupper(trim($viewModel->getTitle()));
|
||||
$baseScopeName = 'esunMegaMenu_' . preg_replace('/[^A-Za-z0-9_]/', '_', (string)$block->getNameInLayout());
|
||||
$renderedRootCategoryIds = [];
|
||||
$componentConfigs = [];
|
||||
|
||||
$getNodeCategoryId = function ($node): int {
|
||||
if (preg_match('/^category-node-(\d+)$/', (string)$node->getId(), $matches)) {
|
||||
return (int)$matches[1];
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
$renderDefaultNode = function ($node) use (
|
||||
$escaper,
|
||||
$getNodeCategoryId,
|
||||
$viewModel
|
||||
): string {
|
||||
$categoryId = $getNodeCategoryId($node);
|
||||
$nodeUrl = $categoryId
|
||||
? $viewModel->getTopLevelCategoryUrl($categoryId, (string)$node->getUrl())
|
||||
: (string)$node->getUrl();
|
||||
$classes = array_filter([
|
||||
'level0',
|
||||
(string)$node->getPositionClass(),
|
||||
(string)$node->getClass(),
|
||||
'level-top',
|
||||
$node->getIsActive() ? 'active' : ''
|
||||
]);
|
||||
|
||||
$html = '<li class="' . $escaper->escapeHtmlAttr(implode(' ', $classes)) . '">';
|
||||
$html .= '<a href="' . $escaper->escapeUrl($nodeUrl) . '" class="level-top">';
|
||||
$html .= '<span>' . $escaper->escapeHtml($node->getName()) . '</span></a>';
|
||||
$html .= '</li>';
|
||||
|
||||
return $html;
|
||||
};
|
||||
|
||||
$getMegaNodeRootCategoryId = function ($node) use (
|
||||
$viewModel,
|
||||
$getNodeCategoryId,
|
||||
$legacyRootCategoryId,
|
||||
$targetTitle
|
||||
): int {
|
||||
$categoryId = $getNodeCategoryId($node);
|
||||
|
||||
if ($categoryId && $viewModel->isMegaMenuRootCategory($categoryId)) {
|
||||
return $categoryId;
|
||||
}
|
||||
|
||||
if ($legacyRootCategoryId && strtoupper(trim((string)$node->getName())) === $targetTitle) {
|
||||
return $legacyRootCategoryId;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
$renderMegaNode = function (int $rootCategoryId, string $label, string $class = '') use (
|
||||
$block,
|
||||
$escaper,
|
||||
$viewModel,
|
||||
$baseScopeName,
|
||||
&$componentConfigs
|
||||
): string {
|
||||
if ($viewModel->isIconCategoryMenu($rootCategoryId)) {
|
||||
return $block->getLayout()
|
||||
->createBlock(\Magento\Framework\View\Element\Template::class)
|
||||
->setTemplate('Esun_MegaMenu::html/icon-category-menu.phtml')
|
||||
->setData('root_category_id', $rootCategoryId)
|
||||
->setData('menu_label', $label)
|
||||
->setData('menu_class', $class)
|
||||
->setData('menu_url', $viewModel->getRootCategoryUrl($rootCategoryId))
|
||||
->setData('menu_description', $viewModel->getRootCategoryDescription($rootCategoryId))
|
||||
->setData('menu_items', $viewModel->getIconCategoryMenuData($rootCategoryId))
|
||||
->toHtml();
|
||||
}
|
||||
|
||||
$scopeName = $baseScopeName . '_' . $rootCategoryId;
|
||||
$featuredProduct = $viewModel->getFeaturedProductData($rootCategoryId);
|
||||
$componentConfigs[$scopeName] = [
|
||||
'component' => 'Esun_MegaMenu/js/mega-menu',
|
||||
'config' => [
|
||||
'rawMenuData' => $viewModel->getMegaMenuData($rootCategoryId)
|
||||
]
|
||||
];
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<li class="<?= $escaper->escapeHtmlAttr(trim('level0 level-top parent category-item esun-megamenu-trigger ' . $class)) ?>" data-category="<?= $rootCategoryId ?>"
|
||||
data-bind="scope: '<?= $escaper->escapeHtmlAttr($scopeName) ?>'">
|
||||
<a href="javascript:void(0)" class="level-top" aria-haspopup="true">
|
||||
<span><?= $escaper->escapeHtml($label) ?></span>
|
||||
</a>
|
||||
|
||||
<div class="esun-megamenu-wrapper">
|
||||
<div class="esun-megamenu-inner">
|
||||
<div class="esun-megamenu-sidebar">
|
||||
<div class="esun-filament-categories" data-bind="foreach: menuData">
|
||||
<div class="esun-filament-category" data-bind="
|
||||
css: { active: $parent.currentSecondaryId() === id },
|
||||
event: { click: $parent.switchSecondaryCategory.bind($parent), mouseenter: $parent.switchSecondaryCategory.bind($parent), focusin: $parent.switchSecondaryCategory.bind($parent) }
|
||||
">
|
||||
<span class="esun-filament-category-label">
|
||||
<span data-bind="text: name"></span>
|
||||
<span class="esun-megamenu-arrow" aria-hidden="true"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($featuredProduct): ?>
|
||||
<div class="esun-featured-product-block">
|
||||
<div class="esun-featured-title"><?= $escaper->escapeHtml(__('FEATURED PRODUCT')) ?></div>
|
||||
<?php $backgroundUrl = (string)$featuredProduct['category_background_url']; ?>
|
||||
<div class="esun-megamenu-featured-card"
|
||||
<?php if ($backgroundUrl): ?>
|
||||
style="background-image: linear-gradient(90deg, rgba(20, 33, 44, 0.48), rgba(20, 33, 44, 0.06)), url('<?= $escaper->escapeUrl($backgroundUrl) ?>');"
|
||||
<?php endif; ?>>
|
||||
<span class="esun-megamenu-featured-kicker">
|
||||
<?= $escaper->escapeHtml($featuredProduct['label']) ?>
|
||||
</span>
|
||||
<span class="esun-megamenu-featured-name">
|
||||
<?= $escaper->escapeHtml($featuredProduct['name']) ?>
|
||||
</span>
|
||||
<a class="esun-megamenu-featured-link"
|
||||
href="<?= $escaper->escapeUrl($featuredProduct['url']) ?>">
|
||||
<?= $escaper->escapeHtml(__('Explore Product')) ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="esun-megamenu-content" data-bind="with: activeSecondaryCategory">
|
||||
<!-- ko if: seriesCategories && seriesCategories.length -->
|
||||
<div class="esun-series-container" data-bind="foreach: seriesCategories">
|
||||
<section class="esun-series-group">
|
||||
<header class="esun-series-header">
|
||||
<h4 data-bind="text: name"></h4>
|
||||
<a data-bind="attr: { href: url }" class="esun-view-all">
|
||||
<?= $escaper->escapeHtml(__('View All')) ?> >
|
||||
</a>
|
||||
</header>
|
||||
|
||||
<!-- ko if: products && products.length -->
|
||||
<div class="esun-products-grid" data-bind="foreach: products">
|
||||
<article class="esun-product-card">
|
||||
<a data-bind="attr: { href: url, title: name }" class="esun-product-link">
|
||||
<span class="esun-product-image-frame">
|
||||
<img data-bind="attr: { src: image_url, alt: name }" class="esun-product-image" loading="lazy"/>
|
||||
</span>
|
||||
<span class="esun-product-name" data-bind="text: name"></span>
|
||||
<span class="esun-product-price" data-bind="text: price"></span>
|
||||
</a>
|
||||
</article>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
</section>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
};
|
||||
|
||||
?>
|
||||
|
||||
<nav class="navigation esun-main-navigation"
|
||||
data-action="navigation"
|
||||
data-mage-init='{"Esun_MegaMenu/js/mobile-menu":{}}'>
|
||||
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
|
||||
<?php foreach ($block->getMenu()->getChildren() as $node): ?>
|
||||
<?php $megaRootCategoryId = $getMegaNodeRootCategoryId($node); ?>
|
||||
<?php if ($megaRootCategoryId): ?>
|
||||
<?php $renderedRootCategoryIds[$megaRootCategoryId] = $megaRootCategoryId; ?>
|
||||
<?= /* @noEscape */ $renderMegaNode(
|
||||
$megaRootCategoryId,
|
||||
(string)$node->getName(),
|
||||
trim((string)$node->getPositionClass() . ' ' . (string)$node->getClass())
|
||||
) ?>
|
||||
<?php else: ?>
|
||||
<?= /* @noEscape */ $renderDefaultNode($node) ?>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php foreach ($rootCategoryIds as $rootCategoryId): ?>
|
||||
<?php if (isset($renderedRootCategoryIds[$rootCategoryId])): ?>
|
||||
<?php continue; ?>
|
||||
<?php endif; ?>
|
||||
<?= /* @noEscape */ $renderMegaNode(
|
||||
(int)$rootCategoryId,
|
||||
$rootCategoryId === $legacyRootCategoryId ? $viewModel->getTitle() : $viewModel->getRootCategoryName((int)$rootCategoryId)
|
||||
) ?>
|
||||
<?php endforeach; ?>
|
||||
<?= $block->getChildHtml() ?>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<?php if ($componentConfigs): ?>
|
||||
<script type="text/x-magento-init">
|
||||
{
|
||||
"*": {
|
||||
"Magento_Ui/js/core/app": {
|
||||
"components": <?= /* @noEscape */ json_encode($componentConfigs, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) ?>
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,288 @@
|
||||
.esun-icon-megamenu-wrapper {
|
||||
border-radius: 0 0 36px 36px;
|
||||
box-shadow: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-inner {
|
||||
box-sizing: border-box;
|
||||
margin: 0 auto;
|
||||
padding: 20px 7.5% 30px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-items {
|
||||
display: grid;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column {
|
||||
box-sizing: border-box;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-content {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-title {
|
||||
color: #111111;
|
||||
display: block;
|
||||
font-size: 24px;
|
||||
font-weight: 500;
|
||||
line-height: 1.25;
|
||||
margin: 0 0 18px;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: @esun-megamenu-green;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-links {
|
||||
background: transparent !important;
|
||||
border: 0 !important;
|
||||
box-shadow: none !important;
|
||||
display: block !important;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
min-width: 0 !important;
|
||||
opacity: 1 !important;
|
||||
padding: 0;
|
||||
position: static !important;
|
||||
transform: none !important;
|
||||
visibility: visible !important;
|
||||
width: auto !important;
|
||||
|
||||
li {
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #171717;
|
||||
display: inline-block;
|
||||
font-size: 19px;
|
||||
font-weight: 400;
|
||||
line-height: 1.35;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: @esun-megamenu-green;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Image mode: four equal cards by default; Description reserves the first quarter.
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--visual {
|
||||
.esun-icon-megamenu-inner {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-intro-content {
|
||||
color: #171717;
|
||||
font-size: 19px;
|
||||
line-height: 1.5;
|
||||
max-width: 410px;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
[data-content-type] {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-items {
|
||||
display: grid !important;
|
||||
gap: 42px 30px !important;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
|
||||
min-width: 0 !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column {
|
||||
display: block !important;
|
||||
float: none !important;
|
||||
margin: 0 !important;
|
||||
max-width: none !important;
|
||||
min-width: 0 !important;
|
||||
padding: 0 !important;
|
||||
width: auto !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-image-wrap {
|
||||
aspect-ratio: 2.35 / 1 !important;
|
||||
border-radius: 20px !important;
|
||||
display: block !important;
|
||||
flex: none !important;
|
||||
height: auto !important;
|
||||
overflow: hidden !important;
|
||||
position: relative !important;
|
||||
width: 100% !important;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-image {
|
||||
display: block !important;
|
||||
height: 100% !important;
|
||||
max-width: none !important;
|
||||
object-fit: cover !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-image-wrap::after {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgba(0, 0, 0, 0.42),
|
||||
rgba(0, 0, 0, 0.03) 72%
|
||||
);
|
||||
content: "";
|
||||
inset: 0;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-image-title {
|
||||
color: #ffffff;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
left: 24px;
|
||||
line-height: 1.25;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-content {
|
||||
display: block !important;
|
||||
padding: 24px 24px 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column.no-image {
|
||||
padding-top: 16px !important;
|
||||
}
|
||||
|
||||
&.has-description {
|
||||
.esun-icon-megamenu-inner {
|
||||
display: grid !important;
|
||||
gap: 64px !important;
|
||||
grid-template-columns: minmax(260px, 1fr) minmax(0, 3fr) !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-items {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No-image mode: every second-level category receives an equal share.
|
||||
.esun-icon-megamenu--text-only {
|
||||
.esun-icon-megamenu-inner {
|
||||
padding-bottom: 82px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-items {
|
||||
display: flex;
|
||||
gap: 40px 0;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column {
|
||||
flex: 1 1 0;
|
||||
padding: 0 38px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column:first-child {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1399px) {
|
||||
.esun-icon-megamenu-inner {
|
||||
padding-left: 48px;
|
||||
padding-right: 48px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--visual.has-description
|
||||
.esun-icon-megamenu-inner {
|
||||
gap: 40px !important;
|
||||
grid-template-columns: minmax(220px, 1fr) minmax(0, 3fr) !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 991px) {
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--visual {
|
||||
.esun-icon-megamenu-inner {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-intro {
|
||||
margin-bottom: 34px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-items {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--visual.has-description
|
||||
.esun-icon-megamenu-inner {
|
||||
display: block !important;
|
||||
}
|
||||
.esun-icon-megamenu-wrapper {
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-inner {
|
||||
display: block !important;
|
||||
padding: 18px 20px !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-intro {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-items {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column,
|
||||
.esun-icon-megamenu--text-only .esun-icon-megamenu-column {
|
||||
border: 0 !important;
|
||||
margin: 0 0 22px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--visual {
|
||||
.esun-icon-megamenu-image-wrap {
|
||||
border-radius: 12px !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-content {
|
||||
padding: 14px 8px 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column {
|
||||
margin-bottom: 22px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-title {
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-links a {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,637 @@
|
||||
@esun-megamenu-green: #30a957;
|
||||
@esun-megamenu-text: #333333;
|
||||
@esun-megamenu-muted: #999;
|
||||
@esun-megamenu-border: #edf0f2;
|
||||
|
||||
@import "_icon-category-menu.less";
|
||||
|
||||
.page-header {
|
||||
position: relative;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.esun-main-navigation {
|
||||
position: static;
|
||||
|
||||
> ul {
|
||||
position: static;
|
||||
}
|
||||
|
||||
.level0.esun-megamenu-trigger {
|
||||
cursor: pointer;
|
||||
position: static !important;
|
||||
|
||||
> .level-top {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:focus-within {
|
||||
> .esun-megamenu-wrapper {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.esun-megamenu-wrapper {
|
||||
background: #ffffff;
|
||||
box-sizing: border-box;
|
||||
display: none;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
top: 99%;
|
||||
width: 100%;
|
||||
z-index: 999;
|
||||
box-shadow: 0 0 36px rgba(26, 137, 82, 0.38);
|
||||
}
|
||||
|
||||
.esun-main-navigation .esun-megamenu-toggle,
|
||||
.esun-main-navigation .esun-megamenu-toggle:hover,
|
||||
.esun-main-navigation .esun-megamenu-toggle:focus,
|
||||
.esun-main-navigation .esun-megamenu-toggle:active {
|
||||
appearance: none;
|
||||
background: transparent !important;
|
||||
background-image: none !important;
|
||||
border: 0 !important;
|
||||
border-radius: 0;
|
||||
box-shadow: none !important;
|
||||
display: none;
|
||||
min-width: 0;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.esun-megamenu-inner {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
margin: 0 auto;
|
||||
max-width: 1360px;
|
||||
min-height: 520px;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.esun-megamenu-sidebar {
|
||||
width: 26%;
|
||||
}
|
||||
|
||||
.esun-filament-categories {
|
||||
display: block;
|
||||
margin: 0 0 34px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.esun-filament-category {
|
||||
background: #f3f3f3;
|
||||
border-radius: 12px;
|
||||
box-sizing: border-box;
|
||||
color: @esun-megamenu-text;
|
||||
cursor: pointer;
|
||||
margin: 0 0 10px;
|
||||
min-height: 50px;
|
||||
transition:
|
||||
background-color 160ms ease,
|
||||
color 160ms ease;
|
||||
width: 100%;
|
||||
|
||||
> .esun-filament-category-label {
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
color: inherit;
|
||||
display: flex;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
justify-content: space-between;
|
||||
line-height: 1.25;
|
||||
min-height: 50px;
|
||||
padding: 10px 20px;
|
||||
text-decoration: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&.active,
|
||||
&:hover {
|
||||
background: @esun-megamenu-green;
|
||||
color: #ffffff;
|
||||
.esun-megamenu-arrow {
|
||||
border-bottom: 2px solid #fff;
|
||||
border-right: 2px solid #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.esun-megamenu-arrow {
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-bottom: 2px solid #939393;
|
||||
border-right: 2px solid #939393;
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.esun-featured-product-block {
|
||||
.esun-featured-title {
|
||||
color: @esun-megamenu-green;
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
letter-spacing: 1px;
|
||||
line-height: 1.2;
|
||||
margin: 0 0 18px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-megamenu-featured-card {
|
||||
background: linear-gradient(135deg, #dfeee8 0%, #f4f4f4 52%, #d6d7ff 100%);
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
border-radius: 8px;
|
||||
box-sizing: border-box;
|
||||
color: #ffffff;
|
||||
display: block;
|
||||
min-height: 174px;
|
||||
overflow: hidden;
|
||||
padding: 42px 30px 26px;
|
||||
text-decoration: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.esun-megamenu-featured-kicker {
|
||||
color: #ffffff;
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
letter-spacing: 4px;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 10px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.esun-megamenu-featured-name {
|
||||
color: #ffffff;
|
||||
display: block;
|
||||
font-size: 23px;
|
||||
font-weight: 800;
|
||||
line-height: 1.1;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.esun-megamenu-featured-link {
|
||||
background: @esun-megamenu-green;
|
||||
border-radius: 18px;
|
||||
color: #ffffff;
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
padding: 11px 16px;
|
||||
text-decoration: none;
|
||||
width: fit-content;
|
||||
|
||||
&:hover {
|
||||
background: #258e49;
|
||||
color: #ffffff;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-megamenu-content {
|
||||
width: 70%;
|
||||
}
|
||||
.ui-state-active .esun-megamenu-content {
|
||||
overflow-y: scroll;
|
||||
max-height: calc(100dvh - 104px);
|
||||
}
|
||||
.esun-series-group {
|
||||
margin: 0 0 42px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-series-header {
|
||||
align-items: baseline;
|
||||
border-bottom: 1px solid @esun-megamenu-border;
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
justify-content: space-between;
|
||||
margin: 0 0 22px;
|
||||
padding: 0 0 18px;
|
||||
|
||||
h4 {
|
||||
color: @esun-megamenu-green;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-view-all {
|
||||
color: @esun-megamenu-text;
|
||||
flex: 0 0 auto;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: @esun-megamenu-green;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-products-grid {
|
||||
display: grid;
|
||||
gap: 26px 24px;
|
||||
grid-template-columns: repeat(6, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.esun-product-card {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.esun-product-link {
|
||||
color: @esun-megamenu-text;
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: @esun-megamenu-green;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-product-image-frame {
|
||||
align-items: center;
|
||||
aspect-ratio: 1 / 1;
|
||||
background: #fbfbfb;
|
||||
border: 1px solid @esun-megamenu-border;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 0 0 10px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.esun-product-image {
|
||||
display: block;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
max-width: 100%;
|
||||
object-fit: cover;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.esun-product-name,
|
||||
.esun-product-price {
|
||||
display: block;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.esun-product-name {
|
||||
color: @esun-megamenu-text;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.esun-product-price {
|
||||
color: @esun-megamenu-muted;
|
||||
font-size: 15px;
|
||||
margin-top: 2px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@media (max-width: 1199px) {
|
||||
.esun-megamenu-inner {
|
||||
gap: 30px;
|
||||
grid-template-columns: 280px minmax(0, 1fr);
|
||||
padding-left: 24px;
|
||||
padding-right: 24px;
|
||||
}
|
||||
|
||||
.esun-products-grid {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
.esun-main-navigation .level0.esun-megamenu-trigger {
|
||||
> .level-top:after,
|
||||
> .level-top.ui-state-active:after {
|
||||
content: "\e622";
|
||||
}
|
||||
}
|
||||
|
||||
.esun-main-navigation .level0.esun-linked-megamenu-trigger {
|
||||
position: relative !important;
|
||||
|
||||
> .level-top {
|
||||
padding-right: 64px;
|
||||
}
|
||||
|
||||
> .level-top:after,
|
||||
> .level-top.ui-state-active:after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
> .esun-megamenu-toggle {
|
||||
align-items: center;
|
||||
color: #ffffff !important;
|
||||
display: flex;
|
||||
font-size: 0;
|
||||
height: 64px;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
width: 64px;
|
||||
z-index: 2;
|
||||
|
||||
> span {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
> .esun-megamenu-toggle:after {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
color: inherit;
|
||||
content: "\e622";
|
||||
display: inline-block;
|
||||
font-family: "icons-blank-theme";
|
||||
font-size: 42px;
|
||||
font-weight: normal;
|
||||
line-height: inherit;
|
||||
overflow: hidden;
|
||||
speak: none;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
&.is-open > .esun-megamenu-toggle:after {
|
||||
content: "\e621";
|
||||
}
|
||||
}
|
||||
.page-header .navigation li.level0:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
.esun-megamenu-wrapper {
|
||||
box-shadow: none;
|
||||
left: auto;
|
||||
position: static;
|
||||
transform: none;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.esun-main-navigation
|
||||
.level0.esun-megamenu-trigger:hover
|
||||
> .esun-megamenu-wrapper,
|
||||
.esun-main-navigation
|
||||
.level0.esun-megamenu-trigger:focus-within
|
||||
> .esun-megamenu-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.esun-main-navigation .level0.esun-megamenu-trigger.is-open {
|
||||
> .level-top:after,
|
||||
> .level-top.ui-state-active:after {
|
||||
content: "\e621";
|
||||
}
|
||||
|
||||
> .esun-megamenu-wrapper {
|
||||
display: block !important;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-main-navigation {
|
||||
.esun-megamenu-wrapper {
|
||||
background: #f7f8f7;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
|
||||
.esun-megamenu-inner,
|
||||
.esun-icon-megamenu-inner {
|
||||
display: block !important;
|
||||
max-height: calc(100vh - 170px);
|
||||
max-height: calc(100dvh - 170px);
|
||||
min-height: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
padding: 16px !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.esun-megamenu-sidebar,
|
||||
.esun-megamenu-content {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.esun-filament-categories {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin: 0 -16px 4px;
|
||||
overflow-x: auto;
|
||||
padding: 0 16px 4px;
|
||||
scrollbar-width: none;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-filament-category {
|
||||
border: 1px solid #e2e7e3;
|
||||
border-radius: 999px;
|
||||
flex: 0 0 auto;
|
||||
margin: 0;
|
||||
min-height: 40px;
|
||||
width: auto;
|
||||
|
||||
> .esun-filament-category-label {
|
||||
font-size: 14px;
|
||||
min-height: 38px;
|
||||
padding: 8px 15px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.esun-megamenu-arrow {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-featured-product-block {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.esun-megamenu-content,
|
||||
.ui-state-active .esun-megamenu-content {
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.esun-series-group {
|
||||
margin-bottom: 26px;
|
||||
}
|
||||
|
||||
.esun-series-header {
|
||||
gap: 12px;
|
||||
margin-bottom: 0px;
|
||||
padding-bottom: 10px;
|
||||
|
||||
h4 {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-view-all {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.esun-products-grid {
|
||||
gap: 12px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.esun-product-image-frame {
|
||||
border-radius: 7px;
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.esun-product-name {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.esun-product-price {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-wrapper {
|
||||
border-radius: 0;
|
||||
|
||||
.esun-icon-megamenu-intro {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&.esun-icon-megamenu--visual .esun-icon-megamenu-inner {
|
||||
display: block !important;
|
||||
gap: 0 !important;
|
||||
grid-template-columns: none !important;
|
||||
}
|
||||
|
||||
&.esun-icon-megamenu--visual .esun-icon-megamenu-items {
|
||||
align-items: start;
|
||||
display: grid !important;
|
||||
gap: 18px 12px !important;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
|
||||
}
|
||||
|
||||
&.esun-icon-megamenu--visual .esun-icon-megamenu-column {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column,
|
||||
.esun-icon-megamenu--text-only .esun-icon-megamenu-column {
|
||||
border: 0 !important;
|
||||
margin: 0 !important;
|
||||
min-width: 0;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-image-wrap {
|
||||
aspect-ratio: 1.65 / 1 !important;
|
||||
border-radius: 10px !important;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-image-title {
|
||||
font-size: 15px;
|
||||
left: 12px;
|
||||
right: 10px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-content {
|
||||
padding: 10px 4px 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-title {
|
||||
font-size: 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-links li {
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-links a {
|
||||
font-size: 14px;
|
||||
line-height: 1.3;
|
||||
padding: 5px 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-trigger[data-category="7"]
|
||||
.esun-icon-megamenu-image-wrap::after {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-trigger[data-category="7"]
|
||||
.esun-icon-megamenu-column,
|
||||
.esun-icon-megamenu-trigger[data-category="7"]
|
||||
.esun-icon-megamenu-image-wrap {
|
||||
border-radius: 14px !important;
|
||||
overflow: hidden !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-trigger[data-category="7"]
|
||||
.esun-icon-megamenu-image-title {
|
||||
left: 16px;
|
||||
line-height: 1.25;
|
||||
right: 16px;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--text-only {
|
||||
.esun-icon-megamenu-items {
|
||||
display: grid !important;
|
||||
gap: 0 !important;
|
||||
grid-template-columns: 1fr !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column {
|
||||
border-bottom: 1px solid #e2e7e3 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-column:last-child {
|
||||
border-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-content {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.esun-icon-megamenu-title {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 14px 4px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 420px) {
|
||||
.esun-main-navigation
|
||||
.esun-icon-megamenu-wrapper.esun-icon-megamenu--text-only {
|
||||
.esun-icon-megamenu-items {
|
||||
grid-template-columns: 1fr !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
define([
|
||||
'uiComponent',
|
||||
'ko'
|
||||
], function (Component, ko) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
rawMenuData: []
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
this._super();
|
||||
|
||||
this.rawMenuData = this.rawMenuData || [];
|
||||
this.menuData = ko.observableArray(this.rawMenuData);
|
||||
|
||||
var firstId = this.rawMenuData.length ? this.rawMenuData[0].id : null;
|
||||
this.currentSecondaryId = ko.observable(firstId);
|
||||
|
||||
this.activeSecondaryCategory = ko.computed(function () {
|
||||
var currentId = this.currentSecondaryId(),
|
||||
items = this.menuData(),
|
||||
index;
|
||||
|
||||
for (index = 0; index < items.length; index++) {
|
||||
if (items[index].id === currentId) {
|
||||
return items[index];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}, this);
|
||||
},
|
||||
|
||||
switchSecondaryCategory: function (category, event) {
|
||||
var menuContainer,
|
||||
menuScrollTop,
|
||||
navigationContainer,
|
||||
navigationScrollTop,
|
||||
pageScrollTop,
|
||||
shouldRestoreScroll = event && event.type === 'click' &&
|
||||
window.matchMedia('(max-width: 992px)').matches;
|
||||
|
||||
if (shouldRestoreScroll) {
|
||||
menuContainer = event.currentTarget.closest('.esun-megamenu-inner');
|
||||
menuScrollTop = menuContainer ? menuContainer.scrollTop : 0;
|
||||
navigationContainer = event.currentTarget.closest('.nav-sections');
|
||||
navigationScrollTop = navigationContainer ? navigationContainer.scrollTop : 0;
|
||||
pageScrollTop = window.pageYOffset;
|
||||
}
|
||||
|
||||
if (category && typeof category.id !== 'undefined') {
|
||||
this.currentSecondaryId(category.id);
|
||||
}
|
||||
|
||||
if (shouldRestoreScroll) {
|
||||
window.requestAnimationFrame(function restoreScroll() {
|
||||
if (menuContainer) {
|
||||
menuContainer.scrollTop = menuScrollTop;
|
||||
}
|
||||
|
||||
if (navigationContainer) {
|
||||
navigationContainer.scrollTop = navigationScrollTop;
|
||||
}
|
||||
|
||||
window.scrollTo(0, pageScrollTop);
|
||||
|
||||
window.requestAnimationFrame(function () {
|
||||
if (menuContainer) {
|
||||
menuContainer.scrollTop = menuScrollTop;
|
||||
}
|
||||
|
||||
if (navigationContainer) {
|
||||
navigationContainer.scrollTop = navigationScrollTop;
|
||||
}
|
||||
|
||||
window.scrollTo(0, pageScrollTop);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
define([
|
||||
'jquery'
|
||||
], function ($) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $navigation = $(element),
|
||||
mobileQuery = window.matchMedia(config.mediaBreakpoint || '(max-width: 992px)'),
|
||||
triggerSelector = '.esun-megamenu-trigger > .level-top';
|
||||
|
||||
function resetMenus() {
|
||||
$navigation
|
||||
.find('.esun-megamenu-trigger')
|
||||
.removeClass('is-open')
|
||||
.find('> .esun-megamenu-wrapper')
|
||||
.css('display', '')
|
||||
.end()
|
||||
.find('> .level-top')
|
||||
.removeClass('ui-state-active')
|
||||
.attr('aria-expanded', 'false')
|
||||
.end()
|
||||
.find('> .esun-megamenu-toggle')
|
||||
.attr('aria-expanded', 'false');
|
||||
}
|
||||
|
||||
function handleNavigationClick(event) {
|
||||
var $target = $(event.target),
|
||||
$item = $target.closest('.esun-megamenu-trigger'),
|
||||
$contentLink = $target.closest('a.esun-product-link, a.esun-view-all'),
|
||||
$trigger,
|
||||
$linkedToggle,
|
||||
willOpen;
|
||||
|
||||
if (mobileQuery.matches && $contentLink.length) {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
window.location.assign($contentLink.get(0).href);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mobileQuery.matches || !$item.length ||
|
||||
$target.closest('.esun-megamenu-wrapper').length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$linkedToggle = $target.closest('.esun-megamenu-toggle');
|
||||
|
||||
if ($item.hasClass('esun-linked-megamenu-trigger') && !$linkedToggle.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$trigger = $linkedToggle.length
|
||||
? $linkedToggle
|
||||
: $item.find('> .level-top');
|
||||
|
||||
if (!$trigger.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
willOpen = !$item.hasClass('is-open');
|
||||
resetMenus();
|
||||
|
||||
if (willOpen) {
|
||||
$item.addClass('is-open');
|
||||
$trigger.attr('aria-expanded', 'true');
|
||||
}
|
||||
}
|
||||
|
||||
$navigation
|
||||
.find(triggerSelector)
|
||||
.attr({
|
||||
'aria-expanded': 'false'
|
||||
});
|
||||
|
||||
$navigation
|
||||
.find('.esun-megamenu-toggle')
|
||||
.attr({
|
||||
'aria-expanded': 'false'
|
||||
});
|
||||
|
||||
$navigation
|
||||
.find('.esun-megamenu-wrapper')
|
||||
.on('click.esunMobileMegaMenu', function (event) {
|
||||
if (mobileQuery.matches) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
});
|
||||
|
||||
$(document)
|
||||
.off('click.esunMobileMegaMenuReset', '[data-action="toggle-nav"]')
|
||||
.on('click.esunMobileMegaMenuReset', '[data-action="toggle-nav"]', resetMenus);
|
||||
|
||||
if (typeof mobileQuery.addEventListener === 'function') {
|
||||
mobileQuery.addEventListener('change', function (event) {
|
||||
if (!event.matches) {
|
||||
resetMenus();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mobileQuery.addListener(function (event) {
|
||||
if (!event.matches) {
|
||||
resetMenus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
element.addEventListener('click', handleNavigationClick, true);
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user