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/Model/System/Config/Visibility.php b/Model/System/Config/Visibility.php new file mode 100644 index 0000000..ebaaede --- /dev/null +++ b/Model/System/Config/Visibility.php @@ -0,0 +1,58 @@ + __('Show On Desktop / Mobile') + , self::DESKTOP_ONLY => __('Desktop Only') + , self::MOBILE_ONLY => __('Mobile Only') + ]; + } + + /** + * Options getter + * + * @return array + */ + public function toOptionArray() + { + return [ + ['value' => self::BOTH, 'label' => __('Show On Desktop / Mobile')], + ['value' => self::DESKTOP_ONLY, 'label' => __('Desktop Only')], + ['value' => self::MOBILE_ONLY, 'label' => __('Mobile Only')] + ]; + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toArray() + { + return self::getVisibility(); + } +} + diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php new file mode 100644 index 0000000..7dcb3f8 --- /dev/null +++ b/Setup/UpgradeSchema.php @@ -0,0 +1,56 @@ +connectionProvider = $connectionProvider; + } + + /** + * {@inheritdoc} + */ + public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) + { + $installer = $setup; + $installer->startSetup(); + + /** + * CURRENT VERSION LOWER THAN 2.1.0 + */ + if (version_compare($context->getVersion(), '2.1.0') == -1) { + $this->addExtraMenuVisibility($installer); + } + + + $installer->endSetup(); + } + + /** + * @param $installer + */ + private function addExtraMenuVisibility(SchemaSetupInterface $installer) + { + $installer + ->getConnection() + ->getTable($installer->getTable('magiccart_magicmenu')) + ->addColumn( + 'visibility', + Table::TYPE_INTEGER, null, + ['unsigned' => true, 'nullable' => false, 'default' => 0], 'Extra Menu Visibility'); + + $installer->endSetup(); + } +} 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') : ''; + ?>