Email theme in PrestaShop using the module

In this blog we will learn how to add an email subject to PrestaShop using a module.

In PrestaShop, you can add a new theme folder directly to mail/themes, but it cannot be quickly installed/uninstalled as a module.

Email theme in PrestaShop using the module

First you need to create your own email templates as mentioned emails/subject/ and keep it in your module.
Follow the same folder structure as given below

├── modules
    ├── yourmodule
        ├── mails
        │     └── themes
        |           └──wk_modern
        |                 ├assets---contains all assets going to use
        |                 ├components---contains header, footer, layout
        |                 |             twig files
        |                 ├core---contains all the mail templates available
        |                 |       in PS as twig files
        |                 └modules --- contains all the modules related
        |                              mails available in PS modules
        |
        |
        └── yourmodule.php

Here we will use a hook actionListMailTheme which lists new mail topics directly from the module. Follow the code below for the main module file.

<?php
use PrestaShop\PrestaShop\Core\MailTemplate\Layout\Layout;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCatalogInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCollectionInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\ThemeInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeScanner;

class WkModern extends Module

    public function __construct()
    
        $this->name = 'WkModern';
        $this->tab = 'theme';
        $this->version = '1.0.0';
        $this->author = 'Author';
        $this->need_instance = 0;
        parent::__construct();
        $this->displayName = $this->l('Modern Email Theme');
        $this->description = $this->l('Email theme module to modifiy emails.');
        $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);        
    

    public function install()
    
        return parent::install()
            && $this->registerHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    

    public function uninstall()
    
        return parent::uninstall()
            && $this->unregisterHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    

    public function enable($force_all = false)
    
        return parent::enable($force_all)
            && $this->registerHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    

    public function disable($force_all = false)
    
        return parent::disable($force_all)
            && $this->unregisterHook(ThemeCatalogInterface::LIST_MAIL_THEMES_HOOK);
    
   
    public function hookActionListMailThemes(array $hookParams)
    
        if (!isset($hookParams['mailThemes'])) 
            return;
        
        /** @var ThemeCollectionInterface $themes */
        $themes = $hookParams['mailThemes'];
        $scanner = new FolderThemeScanner(__DIR__);
        $wk_modern = $scanner->scan(__DIR__.'/mails/themes/wk_modern');
        if (null !== $wk_modern && $wk_modern->getLayouts()->count() > 0) 
            $themes->add($wk_modern);
        
    

Your theme is listed on the “Design > Email Theme” page and browse to the wk_modern theme, as shown in the default PrestaShop email theme. You can click on the view button and see all available email templates in that theme.

In this example, we created an email subject with the name wk_modern as shown in the attached image below.

Email theme in PrestaShop using the module

That’s all about the email theme in PrestaShop using the module. I hope it helps you.

In closing this blog, I hope you find it helpful. If you face any problems or have any doubts regarding the above procedure, don’t hesitate to contact us through the comments section.

You can also explore our PrestaShop development services and a large selection of quality PrestaShop modules.

For any doubts, contact us at [email protected]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *