/   /   /  OroCommerce for developers: frontend add link to customer menu and load custom grid

Note:

For more extensions and themes visit our store

OroCommerce for developers: frontend add link to customer menu and load custom grid


The oro_customer_menu defines the menu items that would populate the Account section of the user menu.


So to create new customer menu you need to :

    1. Create action and route for the menu item.
    2. Add the menu item to see it on Account section.

And if you want to show a datagrid for your menu, it’s simple :

    3. Create datagrid
    4. Add the datagrid to your layout

Let’s Started!!

1. Create action and route

• Create Frontend Controller:
#src/Ibnab/Bundle/CustomerMenuBundle/Controller/Frontend/CustomerMenuController.php

  1.  
  2. <?php
  3. namespace Ibnab\Bundle\CustomerMenuBundle\Controller\Frontend;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Oro\Bundle\LayoutBundle\Annotation\Layout;
  7. class CustomerMenuController extends AbstractController {  
  8.     /**
  9.      * @Route("/", name="ibnab_menu_frontend_index")
  10.      * @Layout(vars={"entity_class"})
  11.      *
  12.      * @return array
  13.      */
  14.     public function indexAction()
  15.     {
  16.         return ['entity_class' => YourEntity::class];
  17.     }
  18. }
  19.  

• Create routing.yml file:
#src/Ibnab/Bundle/CustomerMenuBundle/Resources/config/oro/routing.yml

  1.  
  2. ibnab_menu_frontend:
  3.     resource:     "@IbnabCustomerMenuBundle/Controller/Frontend/CustomerMenuController.php"
  4.     type:         annotation
  5.     prefix:       /customer/new-menu
  6.     options:
  7.         frontend: true
  8.  

       

2. Add the menu item on navigation.yml

• Create navigation.yml file:
#src/Ibnab/Bundle/CustomerMenuBundle/Resources/config/oro/navigation.yml

  1.  
  2. navigation:
  3.     menu_config:
  4.         items:   
  5.             ibnab_customer_frontend_customer_user_menu_index:
  6.                 label: 'ibnab.menu.frontend.new-menu.label'
  7.                 route: 'ibnab_menu_frontend_index'
  8.                 position: 80
  9.         tree:
  10.             oro_customer_menu:
  11.                 scope_type: menu_frontend_visibility
  12.                 children:
  13.                     ibnab_customer_frontend_customer_user_menu_index: ~                    
  14.     titles:
  15.         ibnab_menu_frontend_index: 'ibnab.menu.frontend.frontend_index_title'
  16.  

3. Create the datagrid

• Create datagrids.yml file:
# src/Ibnab/Bundle/CustomerMenuBundle/Resources/config/oro/datagrids.yml

  1.  
  2. datagrids:
  3.     ibnab-new-menu-frontend-grid:
  4.         source:
  5.             type:         orm
  6.             query:
  7.                 select:
  8.                     ….
  9.                 from:
  10.                     - { table: … , alias: i }
  11.         columns:
  12.             ….
  13.         sorters:
  14.             columns:
  15.                 ….
  16.         options:
  17.             frontend: true
  18.  


4. Add the datagrid into layout.yml

# src/Ibnab/CustomerMenuBundle/Resources/views/layouts/default/imports/ibnab_menu_frontend_index_grid/layout.yml
  1.  
  2. layout:
  3.     imports:
  4.         -
  5.             id: datagrid
  6.             root: __root
  7.     actions:
  8.         - '@setOption':
  9.             id: __datagrid
  10.             optionName: grid_name
  11.             optionValue: ibnab-new-menu-frontend-grid
  12.  


• Import the datagrid
# src/Ibnab/CustomerMenuBundle/Resources/views/layouts/default/ibnab_menu_frontend_index/layout.yml
  1.  
  2. layout:
  3.     imports:
  4.         -
  5.             id: ibnab_menu_frontend_index_grid
  6.             root: page_content
  7.     actions:
  8.         - '@setOption':
  9.             id: page_title
  10.             optionName: defaultValue
  11.             optionValue: 'ibnab.menu.frontend.entity_plural_label'
  12.  


• Import the Account Section
# src/Ibnab/Bundle/CustomerMenuBundle/Resources/views/layouts/blank/ibnab_menu_frontend_index/layout.yml

  1.  
  2. layout:
  3.     imports:
  4.         -
  5.             id: oro_customer_page
  6.     actions: []
  7.  

Done!

Comments

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.