shopware 6 plugin
2Hats . 3 minutes
September 5, 2023

How to create custom components in Shopware 6 Plugin Configuration

Shopware does not permit the display of every component on the plugin configuration page due to its complexities. Instead, Shopware recommends creating custom modules to effectively showcase these components within plugins. While creating our custom modules is an option, it’s essential to note that this approach can be time-consuming. As an alternative, we can opt to utilize custom components within the plugin configuration to meet our plugin’s specific requirements more efficiently. In this blog post, we will dive deep into a detailed guide on how to elegantly display messages and implement API calling buttons in the plugin configuration by utilizing custom components.

 

Good looking messages

In our plugins, we frequently utilize snippets to incorporate translations into text elements. To present these snippets in an appealing and informative manner within the plugin, we can use custom components. First, we need to add a custom component to the plugin’s config page, like below.

The Next step is to import the component into the administration. Import the component in the main.js file in the src/Resources/app/administration/src/ folder.

In the snippet-info/index.js file add the below mentioned code.

We can add snippets and styles to the custom components, and we need to import them to use in the plugin. We can add our messages to the twig file, import it as a template, and register it with the component. The styles we added in the SCSS file will be used in this template so we can show good-looking messages in plugin configurations. A template twig file is given below.

Now you need to build the administration using the administration build command to see the changes. The plugin configuration will look like the below screenshot . When clicked on the Go to snippet it will redirect to the edit page of the snippet “general.message” we added in the component snippets.

API test buttons

Using the custom components, we can add API test buttons in the plugin config. For that, in the config.xml file, add the below code.

In the main.js file under /src/Resources/app/administration/src import our components folder.
import ‘.component/api-test’;

Inside side the component/api-test/api-test-button.html.twig add the template file like below

We can use snippets here like the previous example. 

Add below code to the index.js file under src/Resources/app/administration/src/component/api-test

Here, the SendGetRequest function will send the API requests and return the response. By checking the responses, we can show notifications using the functions createNotificationSuccess or createNotificationError. We need to build the administration using the administration build command to see the changes.

blog
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
Aneesh ceo
Aneesh Sreedharan
Founder & CEO, 2Hats Logic Solutions
Subscribe to our Newsletter
Arsha Content writer

    Stay In The Loop!

    Subscribe to our newsletter and learn about the latest digital trends.