Thursday , August 17 2017
Home / Shopware / Shopware Tutorial – Add menu item under Marketing in backend and display data from a table

Shopware Tutorial – Add menu item under Marketing in backend and display data from a table

You should add the plugin in engine/Shopware/Plugins/Backend. The plugin adds additional menu item under Marketing in the backend. Once clicked opens a window with a list of data from a table, manually created and filled in the database. The plugins enables adding data too, so the only thing you need to do is create the table. The name of my table is s_user_comments. In case you create a different name go to the Bootstrap.php file and change the name of the table you want to display data from. The table looks something like this. This window is shown after the button Listing Comments under Marketing is clicked.

Shopware Tutorial - Add menu item under Marketing in backend and display data from a table

From the right side of the window, there’s an additional panel which displays some info once a row from the table is clicked. You can edit this code in ‘info.js’.

Shopware Tutorial - Add menu item under Marketing in backend and display data from a table

//INSERT AND SELECT FROM DATABASE
//This is the function that adds and pulls data. It is added in Bootstrap.php
protected function addDemoData()
{
$sql = ” INSERT IGNORE INTO s_user_comments (id, name, email, comment) SELECT com.id, com.name, com.email, com.comment FROM s_user_comments com “;
Shopware()->Db()->query($sql);
}

//CREATE MENU UNDER MARKETING
// This is added in install function.
$this->createMenuItem(array(
‘label’ => ‘Listing Comments’,
‘controller’ => ‘ListingComments’,
‘class’ => ‘sprite-application-block’,
‘action’ => ‘Index’,
‘active’ => 1,
‘parent’ => $this->Menu()->findOneBy([‘label’ => ‘Marketing’])
));

//main.js file under Views/backend/listing_comments/controller/main/js
//here you can add additional option like, instead the standard edit and delete options
//you can add additional view opion next to delete.
Ext.define(‘Shopware.apps.ListingComments.controller.Main‘, {
extend: ‘Enlight.app.Controller‘,

init: function() {
var curr = this;
curr.mainWindow = me.getView(‘list.Window‘).create({ }).show();
}
});

The plugin can be downloaded here. Give us a feedback and let us know if this helped you.