All Projects → SnowdogApps → Magento2 Menu

SnowdogApps / Magento2 Menu

Licence: mit
Provides powerful menu editor to replace category based menus in Magento 2

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Magento2 Menu

Magento2 Frontools
Set of front-end tools for Magento 2 based on Gulp.js
Stars: ✭ 416 (+126.09%)
Mutual labels:  hacktoberfest, magento2
Magento2 Phpstorm Plugin
PHPStorm Plugin for Magento 2
Stars: ✭ 294 (+59.78%)
Mutual labels:  hacktoberfest, magento2
Menu
A JavaScript free menu library for Blazor and Razor Components applications.
Stars: ✭ 118 (-35.87%)
Mutual labels:  hacktoberfest, menus
Magento2 Theme Blank Sass
SASS based version of Magento 2 Blank theme
Stars: ✭ 373 (+102.72%)
Mutual labels:  hacktoberfest, magento2
Vue Storefront
The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Ne…
Stars: ✭ 9,111 (+4851.63%)
Mutual labels:  hacktoberfest, magento2
Magento2
All Submissions you make to Magento Inc. ("Magento") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual, worldwide, non-exclusive, no charge, royalty free, irrevocable license under your applicable copyrights and patents to reproduce, prepare derivative works of, display, publically perform, subli…
Stars: ✭ 9,816 (+5234.78%)
Mutual labels:  hacktoberfest, magento2
Magento2 Alpaca Theme
Magento 2 theme built on top of Alpaca design system crafted for ecommerce
Stars: ✭ 129 (-29.89%)
Mutual labels:  hacktoberfest, magento2
Wpstarter
Easily bootstrap whole site Composer packages for WordPress.
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Comunica
📬 A knowledge graph querying framework for JavaScript
Stars: ✭ 183 (-0.54%)
Mutual labels:  hacktoberfest
Github Csv Tools
Import and export GitHub issues via CSV
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Thunder
An open-source game engine is written in C++ with a flexible architecture
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Vue Dock Menu
⚓Dockable Menu bar for Vue
Stars: ✭ 183 (-0.54%)
Mutual labels:  menus
Discord Bot Dashboard
📊 A tool for Discord.js Bot Developers to get detailed analytics of their bots and to manage them.
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Git S3 Push
Deploy your git repo to an S3 bucket
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Docker
🐳
Stars: ✭ 183 (-0.54%)
Mutual labels:  hacktoberfest
Hacktoberfest Data Structure And Algorithms
A repo to contains data structure s and algorithms, regardless of language.
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Chef Client
Development repository for Chef Client cookbook
Stars: ✭ 183 (-0.54%)
Mutual labels:  hacktoberfest
Px4 Sitl gazebo
Set of plugins, models and worlds to use with OSRF Gazebo Simulator in SITL and HITL.
Stars: ✭ 182 (-1.09%)
Mutual labels:  hacktoberfest
Bastion
Highly-available Distributed Fault-tolerant Runtime
Stars: ✭ 2,333 (+1167.93%)
Mutual labels:  hacktoberfest
Front End Performance Checklist
🎮 더 빠르게 작동하는 프론트엔드 성능 체크리스트
Stars: ✭ 183 (-0.54%)
Mutual labels:  hacktoberfest

Packagist Packagist Packagist

Magento 2 Menu

Provides powerful menu editor to replace category based menus in Magento 2.

Use

List of menus is located in Admin Panel under Content > Elements > Menus.

Following example shows how to replace default Magento 2 menu, by the user-defined menu with identifier main.

<referenceBlock name="catalog.topnav" remove="true"/>
<referenceBlock name="store.menu">
  <block name="main.menu" class="Snowdog\Menu\Block\Menu">
     <arguments>
        <argument name="menu" xsi:type="string">main</argument>
     </arguments>
  </block>
</referenceBlock>

Overwriting templates per menu ID

You have to add new folder with menu ID and add same structure like in default folder. For example, to overwrite templates of menu with ID menu_main the folders structure should looks like this:

Snowdog_Menu
  └─ templates
    └─ menu_main
      │- menu
      │  │- node_type
      │  │  │- category.phtml
      │  │  └─ ...
      │  └─ sub_menu.phtml
      └─ menu.phtml

Adding new types of nodes

To add new type node you have to add:

  • new backend block that also implements \Snowdog\Menu\Api\NodeTypeInterface and is defined in di.xml
  • create new vue component for new type node and define it in di.xml

Backend block will be directly injected into menu editor.

New node type in admin panel

Menu UI in admin panel is build with Vue.js.

Every node type has its own vue component located inside view/adminhtml/web/vue/menu-type directory. (See view/adminhtml/web/vue/menu-type/category.vue or view/adminhtml/web/vue/menu-type/cms-block.vue examples for a reference)

UI initialization starts in view/adminhtml/templates/menu/nodes.phtml where we initialize menu.js and we pass list of paths of Vue components that are assigned to each node type using "vueComponents" property (see two fragments of code from nodes.phtml below).

$vueComponents = $block->getVueComponents();
<script type="text/x-magento-init">
    {
        "*": {
            "menuNodes": {
                "vueComponents": <?= json_encode($vueComponents) ?>,
                // ...
            }
        }
    }
</script>

To show new node in UI we need to add new Vue component via di.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Snowdog\Menu\Model\VueProvider">
        <arguments>
            <argument name="components" xsi:type="array">
                <item name="component_name" xsi:type="string">component-file-name</item>
            </argument>
        </arguments>
    </type>
</config>

Where we need to define

  • component_name - example: cms_block
  • component-file-name - example: cms-block

Then in view/adminhtml/web/vue/menu-type/ we add component-file-name.vue ex. cms-block.vue

In new vue file we register our component (component_name ex. cms_block) and we add our logic we need.

<template>
    ...
</template>
<script>
    define(['Vue'], function(Vue) {
        Vue.component('component_name', {
        // example: Vue.component('cms_block', {
            ...
        }
    })
</script>

Newly created block with additional method should be added via di.xml defining block instance and node type code (code will be stored in database).

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Snowdog\Menu\Model\NodeTypeProvider">
        <arguments>
            <argument name="providers" xsi:type="array">
                <item name="my_node_type" xsi:type="object">Foo\Bar\Block\NodeType\MyNode</item>
            </argument>
        </arguments>
    </type>
</config>

my_node_type - example: cms_block (the same as component_name) Foo\Bar\Block\NodeType\MyNode - example: Snowdog\Menu\Block\NodeType\CmsBlock

In our cms_block example it would be:

<item name="cms_block" xsi:type="object">Snowdog\Menu\Block\NodeType\CmsBlock</item>

How to save data from vue components when saving menu changes?

When saving menu changes we send form post request that contains several fields like: form_key, id, title, identifier, css_class, stores[], serialized_notes.

serialized_notes stores data from our vue components using computed property jsonList.

App.vue:

<input
    type="hidden"
    name="serialized_nodes"
    :value="jsonList"
>
computed: {
    jsonList: function() {
        return JSON.stringify(this.list);
    }
}

The list and item objects are passed from App.vue to child components. As they are objects, they are passed by reference and editing them in child components, updates the value of serialized_nodes in App.vue.

This is not an ideal way of mutating data, and we plan to refactor it.

For now look at menu-type.vue. You can find:

<component
    :is="item['type']"
    :item="item"
    :config="config"
/>

This loads dynamically a component of a chosen type of node. For example for a node type: cms_block -> cms-block.vue

Cms block node type component uses autocomplete.vue input type component with prop item :item="item". Once user makes some changes, the data is propagated up to the root App.vue component, stringified and saved in a hidden input.

Nodes Custom Templates

This feature allows you to add custom templates to each menu node type and node submenu.
And it allows to select the custom templates in menu admin edit page.

The custom templates override the default ones that are provided by the module.

Adding Nodes Custom Templates

  • Create a directory inside your theme files that will contain the custom templates with the following structure:
Snowdog_Menu  
  └─ templates
    └─ {menu_identifier}
      └─ menu
        └─ custom
          └─ {custom_templates_directories}
  • {menu_identifier} is the identifier that you enter when you create a menu on menu admin page.
  • {custom_templates_directories} is a list of container directories for the custom templates.
  • The name of the custom templates container directory can be either a node type (Check Available Node Types) or sub_menu.
  • Once the custom templates container directories are ready, you have to add the custom templates PHTML files to them. (Template file name must not be a node type.)
  • After that, you can proceed to your menu admin edit page to select the custom templates that you want to use for your nodes. (Check Configuring Nodes Custom Templates.)

Configuring Nodes Custom Templates

After adding your custom templates, you can select the templates that you want to use for your menu nodes in menu admin edit page.

In menu admin edit page, the Node template field will contain a list of available node type custom templates.
And the Submenu template field will contain a list of available submenu templates. (Submenu template applies to the child nodes of a node.)

Available Node Types

  • category
  • product
  • cms_page
  • cms_block
  • custom_url
  • category_child
  • wrapper

Available endpoints:

  • /rest/V1/menus: retrieves available menus
  • /rest/V1/nodes: retrieves nodes by menuId

Frontend

We are not providing any CSS or JS, only basic HTML, which means this module is not out of box supported by any theme, you always need to write some custom code to get expected results or pick some ready to use theme / extension, built on top of this module.

Themes:

Extensions:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].