From 18e143fc528867c562d96b9735a43a25f63308a5 Mon Sep 17 00:00:00 2001 From: kestraly Date: Tue, 3 Nov 2020 10:08:51 +0000 Subject: [PATCH 1/4] New Feature - Extra Menu Position On Either Desktop, Mobile or Both --- Block/Adminhtml/Extra/Edit/Tab/Form.php | 19 ++++++++++++++++++- Block/Menu.php | 10 +++++++--- etc/module.xml | 4 ++-- view/frontend/templates/aio-topmenu.phtml | 4 +++- view/frontend/templates/topmenu.phtml | 3 ++- view/frontend/templates/vmenu.phtml | 4 +++- 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Block/Adminhtml/Extra/Edit/Tab/Form.php b/Block/Adminhtml/Extra/Edit/Tab/Form.php index b97c481..5c9304f 100644 --- a/Block/Adminhtml/Extra/Edit/Tab/Form.php +++ b/Block/Adminhtml/Extra/Edit/Tab/Form.php @@ -22,9 +22,14 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic implements \Magent /** * @var \Magento\Catalog\Model\Category\Attribute\Source\Page - */ + */ protected $_blocks; + /** + * @var \Magiccart\Magicmenu\Model\System\Config\Visibility + */ + protected $_visibility; + /** * @var \Magiccart\Magicmenu\Model\Magicmenu */ @@ -44,11 +49,13 @@ public function __construct( \Magento\Store\Model\System\Store $systemStore, \Magiccart\Magicmenu\Model\Magicmenu $magicmenu, \Magiccart\Magicmenu\Model\System\Config\Blocks $blocks, + \Magiccart\Magicmenu\Model\System\Config\Visibility $visibility, array $data = [] ) { $this->_objectFactory = $objectFactory; $this->_magicmenu = $magicmenu; $this->_blocks = $blocks; + $this->_visibility = $visibility; $this->_systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); } @@ -129,6 +136,16 @@ protected function _prepareForm() ] ); + $fieldset->addField('visibility', 'select', + [ + 'label' => __('Visibility Location'), + 'title' => __('Visibility Location'), + 'name' => 'visibility', + 'values' => $this->_visibility->toOptionArray(), + 'after_element_html' => '

Show Extra Menu Locations

', + ] + ); + $fieldset->addField('ext_content', 'select', [ 'label' => __('Extra Content'), diff --git a/Block/Menu.php b/Block/Menu.php index 212be5a..b4df291 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -333,10 +333,10 @@ public function getMegamenu($catTop, $blocks, $itemPositionClassPrefix) return array('desktop' => $desktopTmp, 'mobile' => $mobileTmp); } - public function drawExtraMenu() + public function drawExtraMenu($visibility = 1) { if($this->hasData('extraMenu')) return $this->getData('extraMenu'); - $extMenu = $this->getExtraMenu(); + $extMenu = $this->getExtraMenu($visibility); $count = count($extMenu); $drawExtraMenu = ''; if($count){ @@ -373,12 +373,16 @@ public function getChildExt($parentId) return $collection; } - public function getExtraMenu() + public function getExtraMenu($visibility) { $store = $this->_storeManager->getStore()->getStoreId(); + + if($visibility == 'mobile') $visibility = '2'; + $collection = $this->_magicmenuCollectionFactory->create() ->addFieldToSelect(array('link','name', 'cat_col', 'magic_label','ext_content','order')) ->addFieldToFilter('extra', 1) + ->addFieldToFilter('visibility', array('eq'=> $visibility, 'eq'=> 0)) ->addFieldToFilter('status', 1); $collection->getSelect()->where('find_in_set(0, stores) OR find_in_set(?, stores)', $store)->order('order'); return $collection; diff --git a/etc/module.xml b/etc/module.xml index 8e3f050..9062b2b 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -6,9 +6,9 @@ * @license http://www.magiccart.net/license-agreement.html * @Author: DOng NGuyen * @@Create Date: 2016-02-23 18:59:34 - * @@Modify Date: 2016-03-09 17:44:40 + * @@Modify Date: 2020-11-03 09:40:00 * @@Function: */ --> - + diff --git a/view/frontend/templates/aio-topmenu.phtml b/view/frontend/templates/aio-topmenu.phtml index 2061942..aea64ff 100644 --- a/view/frontend/templates/aio-topmenu.phtml +++ b/view/frontend/templates/aio-topmenu.phtml @@ -26,11 +26,13 @@ $mobileMenu = $menuHtml['mobile']; $drawHomeMenu = $menu['home'] ? $homeHtml : ''; $drawMainMenu = ''; $drawExtraMenu = $menu['extraCat'] ? $extraHtml : ''; +$drawExtraMobileMenu = $menu['extraCat'] ? $this->drawExtraMenu('mobile') : ''; + ?> diff --git a/view/frontend/templates/topmenu.phtml b/view/frontend/templates/topmenu.phtml index ccf9956..1bad347 100644 --- a/view/frontend/templates/topmenu.phtml +++ b/view/frontend/templates/topmenu.phtml @@ -28,11 +28,12 @@ $drawHomeMenu = $menu['home'] ? $this->drawHomeMenu() : ''; $drawMainMenu = $menu['mainCat'] ? implode("\n", $desktop) : ''; // drawExtMenu ExtraMenu $drawExtraMenu = $menu['extraCat'] ? $this->drawExtraMenu() : ''; +$drawExtraMobileMenu = $menu['extraCat'] ? $this->drawExtraMenu('mobile') : ''; ?> drawHomeMenu() : ''; $drawMainMenu = $vmenu['mainCat'] ? implode("\n", $desktop) : ''; // drawExtMenu ExtraMenu $drawExtraMenu = $vmenu['extraCat'] ? $this->drawExtraMenu() : ''; +$drawExtraMobileMenu = $menu['extraCat'] ? $this->drawExtraMenu('mobile') : ''; + ?>