CommercePeer Brand Logo


Programmatically: Magento 2 Product Entity

Programmatically: How to create custom Magento dashboard widgets

Step 1: Create a new module

Create a new module in your Magento installation. For example, let's create a module called "MyModule". Create a new folder named "MyModule" in the app/code/local directory and create the following files: etc/config.xml etc/module.xml Model/Widget.php

Step 2: Define the widget in the config.xml file

In the config.xml file, add the following code:


		
	
    
        
            1.0.0
        
    
    
        
            
                
                    MyModule_Block_Adminhtml_Widget_MyWidget
                
            
        
    
	
	

Step 3: Create the widget block class

In the Model/Widget.php file, add the following code:


		

class MyModule_Block_Adminhtml_Widget_MyWidget extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('mywidget/mywidget.phtml');
    }

    public function getHeaderText()
    {
        return 'My Custom Widget';
    }

    public function getWidgetHtml()
    {
        // Add your custom widget HTML code here
        return '

This is my custom dashboard widget.

'; } }

Step 4: Create the widget template

Create a new file named mywidget.phtml in the app/design/adminhtml/default/default/template/mywidget directory. Add the following code:


		

	

echo $this->getHeaderText();

echo $this->getWidgetHtml();

Step 5: Enable and configure the widget

To enable and configure the widget, go to System > Configuration > Advanced > Admin > Dashboard > Widgets and add a new widget with the following settings: Widget Type: My Custom Widget Title: My Custom Widget Description: This is my custom dashboard widget.

LET’S WORK TOGETHER

We love working with Small Businesses, Retailers, Manufacturers. Our team is here to Help.

→ Schedule Free Consultant Now
Copyright © 2024 CommercePeer. All Rights Reserved.