Home / Shopware / Tips and Tricks for Shopware 6

How to programmatically send emails from Shopware 6

I recently had to send email notifications from one Shopware 6 store when something went wrong with one of the background scripts. Of course, I could have just used the regular PHP mail function, but I figured Shopware must have its own functionality. Yes, it has! The “send” method is available in the ShopwareCoreContentMailServiceAbstractMailService class, which we may utilize to send emails.

So now you know how to use Shopware 6 to send emails. You’re welcome, and this concludes the article. Of course not, I’m only joking. As is customary, we’ll look at various samples and discuss the code. 

Finally, we’ll construct a standalone email service that you can copy to your plugin, register in your services.xml file, and then inject into any class where you need it to send emails for you. This assumes you already have a plugin with a class into which our new email service might be injected. 

If you don’t have a plugin yet, you can download and utilize the “skeleton plugin” sample, which is available in my Shopware 6 plugin programming tutorial.

I’ll use the name “TestPlugin” in the following examples, so make sure to replace it with the name of your plugin if you want to copy and paste my code.

How to add basic page data to a custom page in Shopware 6

I detailed how to use our own custom storefront controller to create a custom page with custom content in the Shopware 6 plugin tutorial. 

In this article, I’d like to broaden the scope of this discussion by including the normal Shopware 6-page data on our custom page. We will be able to display the regular navigation as well as access certain useful system data in this manner.

In another article I will elaborate on tips and tricks for the Shopify platform, as well as App developing platforms.  

How to set up default values for Shopware 6 plugin config

This article will guide you, on how to set up default values, that you want the user to see in your plugin’s configuration, after he installs and activates it. If you are new to the Shopware 6 plugin configuration, then I suggest you read my article How to create a config for your Shopware 6 plugin first, to get some basic information with examples. This article expands the knowledge from the previous one and also builds on some information from the article accessing your plugin’s classes during its installation and activation.

However, there are certain limits to this, at least in Shopware version 6.4, which is the most recent version at the time of the writing of this text. Internally, Shopware 6 uses a JSON field, named ‘configuration_value’ in the‘system_config’ table for storing the plugin config values. 

That is a good option because it provides a lot of freedom and allows you to save almost anything. However, the method ‘phpize’ from the XmlUtils package, which is utilized by Shopware for this reason, limits how the default value from the config.xml file is preserved.

If you need developer of Shopware for your business, solution25 dedicated outsourcing team can assist you on the matter. 

Arrange a free consultation now!