Skip to content

New Feature - Extra Menu Position On Either Desktop, Mobile or Both #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Block/Adminhtml/Extra/Edit/Tab/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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);
}
Expand Down Expand Up @@ -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' => '<p class="nm"><small>Show Extra Menu Locations</small></p>',
]
);

$fieldset->addField('ext_content', 'select',
[
'label' => __('Extra Content'),
Expand Down
10 changes: 7 additions & 3 deletions Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions Model/System/Config/Visibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* @Author: nguyen
* @Date: 2020-08-28 10:53:10
* @Last Modified by: nguyen
* @Last Modified time: 2020-11-03 09:52:12
*/

namespace Magiccart\Magicmenu\Model\System\Config;


class Visibility implements \Magento\Framework\Option\ArrayInterface
{

const BOTH = 0;
const DESKTOP_ONLY = 1;
const MOBILE_ONLY = 2;

/**
* get available statuses.
*
* @return []
*/
public static function getVisibility()
{
return [
self::BOTH => __('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();
}
}

56 changes: 56 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Magiccart\Magicmenu\Setup;

use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{
/** @var SplitDatabaseConnectionProvider */
private $connectionProvider;

public function __construct(SplitDatabaseConnectionProvider $connectionProvider)
{
$this->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();
}
}
4 changes: 2 additions & 2 deletions etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* @license http://www.magiccart.net/license-agreement.html
* @Author: DOng NGuyen<nguyen@dvn.com>
* @@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:
*/ -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magiccart_Magicmenu" setup_version="2.0"/>
<module name="Magiccart_Magicmenu" setup_version="2.1"/>
</config>
4 changes: 3 additions & 1 deletion view/frontend/templates/aio-topmenu.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ $mobileMenu = $menuHtml['mobile'];
$drawHomeMenu = $menu['home'] ? $homeHtml : '';
$drawMainMenu = '';
$drawExtraMenu = $menu['extraCat'] ? $extraHtml : '';
$drawExtraMobileMenu = $menu['extraCat'] ? $this->drawExtraMenu('mobile') : '';

?>
<nav class="navigation mean-nav navigation-mobile" role="navigation" data-action="navigation">
<ul class="nav-mobile" data-alo-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<?php echo $mobileMenu ?>
<?php echo $drawExtraMenu ?>
<?php echo $drawExtraMobileMenu ?>
</ul>
</nav>
<?php if($vmenu['enabled']) : ?>
Expand Down
3 changes: 2 additions & 1 deletion view/frontend/templates/topmenu.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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') : '';
?>
<nav class="navigation mean-nav navigation-mobile" role="navigation" data-action="navigation">
<ul class="nav-mobile" data-alo-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<?php echo $mobileMenu ?>
<?php echo $drawExtraMenu ?>
<?php echo $drawExtraMobileMenu ?>
</ul>
</nav>
<?php
Expand Down
4 changes: 3 additions & 1 deletion view/frontend/templates/vmenu.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ $drawHomeMenu = $vmenu['home'] ? $this->drawHomeMenu() : '';
$drawMainMenu = $vmenu['mainCat'] ? implode("\n", $desktop) : '';
// drawExtMenu ExtraMenu
$drawExtraMenu = $vmenu['extraCat'] ? $this->drawExtraMenu() : '';
$drawExtraMobileMenu = $menu['extraCat'] ? $this->drawExtraMenu('mobile') : '';

?>
<div class="vmagicmenu clearfix">
<ul class="nav-desktop">
Expand All @@ -38,7 +40,7 @@ $drawExtraMenu = $vmenu['extraCat'] ? $this->drawExtraMenu() : '';
<nav class="navigation" role="navigation">
<ul class="nav-mobile" data-alo-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<?php echo $mobileMenu ?>
<?php echo $drawExtraMenu ?>
<?php echo $drawExtraMobileMenu ?>
</ul>
</nav>
<?php endif; ?>
Expand Down