Skip to content

Commit

Permalink
RadicalMart Message: Email v1.1.0
Browse files Browse the repository at this point in the history
* Fix Languages
* Add admin emails
* Small fixes
* Fix Uri [close #7]
* Change update server name [close #6]
  • Loading branch information
Septdir authored Mar 1, 2022
1 parent 3429b53 commit 25aa2e8
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 55 deletions.
81 changes: 70 additions & 11 deletions email.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @package RadicalMart Package
* @subpackage plg_radicalmart_message_email
* @version 1.0.0
* @version 1.1.0
* @author Delo Design - delo-design.ru
* @copyright Copyright (c) 2021 Delo Design. All rights reserved.
* @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand All @@ -12,7 +12,9 @@
defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Uri\Uri;
Expand All @@ -37,6 +39,38 @@ class plgRadicalMart_MessageEmail extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Add email config form to RadicalMart.
*
* @param Form $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @throws Exception
*
* @since 1.1.0
*/
public function onRadicalMartPrepareConfigForm($form, $data)
{
Form::addFormPath(__DIR__ . '/forms');
$form->loadFile('radicalmart');
}

/**
* Add email config form to RadicalMart Express.
*
* @param Form $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @throws Exception
*
* @since 1.1.0
*/
public function onRadicalMartExpressPrepareConfigForm($form, $data)
{
Form::addFormPath(__DIR__ . '/forms');
$form->loadFile('radicalmart');
}

/**
* Method to send message.
*
Expand All @@ -52,11 +86,14 @@ public function onRadicalMartSendMessage($type = null, $data = null)
if (!in_array($type, array('user.create', 'order.create', 'order.change_status',
'express.user.create', 'express.order.create', 'express.order.change_status'))) return;

$constant = 'COM_RADICALMART';
$constant = 'COM_RADICALMART';
$component = 'com_radicalmart';
if (in_array($type, array('express.user.create', 'express.order.create', 'express.order.change_status')))
{
$constant .= '_EXPRESS';
$constant .= '_EXPRESS';
$component .= '_express';
}
$params = ComponentHelper::getParams($component);

if ($type === 'order.create' || $type === 'order.change_status'
|| $type === 'express.order.create' || $type === 'express.order.change_status')
Expand All @@ -65,8 +102,8 @@ public function onRadicalMartSendMessage($type = null, $data = null)
$layout = ($type === 'order.create' || $type === 'express.order.create')
? 'create' : 'status';
$subject = ($type === 'order.create' || $type === 'express.order.create')
? Text::sprintf('PLG_RADICALMART_MESSAGE_ORDER_CREATE', $data->number)
: Text::sprintf('PLG_RADICALMART_MESSAGE_ORDER_CHANGE_STATUS', $data->number, Text::_($data->status->title));
? Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_ORDER_CREATE', $data->number)
: Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_ORDER_CHANGE_STATUS', $data->number, Text::_($data->status->title));

$links = true;
if (($type === 'express.order.create' || $type === 'express.order.change_status') && $data->status->id !== 2)
Expand All @@ -78,19 +115,41 @@ public function onRadicalMartSendMessage($type = null, $data = null)
if (!empty($data->contacts['email']))
{
$this->sendEmail($subject, $data->contacts['email'],
RadicalMartHelperMessage::renderLayout('email.order.' . $layout,
array('recipient' => 'client', 'order' => $data, 'constant' => $constant, 'links' => $links)));
RadicalMartHelperMessage::renderLayout('email.order.' . $layout, array(
'recipient' => 'client',
'order' => $data,
'constant' => $constant,
'component' => $component,
'params' => $params,
'links' => $links
)));
}

// Send admin email
$this->sendEmail($subject, $config->get('replyto', $config->get('mailfrom')),
RadicalMartHelperMessage::renderLayout('email.order.' . $layout,
array('recipient' => 'admin', 'order' => $data, 'constant' => $constant, 'links' => $links)));
$adminEmails = array();
if (!empty($params->get('messages_email_admin')))
{
foreach ((array) $params->get('messages_email_admin') as $param)
{
if (!empty($param->email)) $adminEmails[] = $param->email;
}
}
if (empty($adminEmails)) $adminEmails[] = $config->get('replyto', $config->get('mailfrom'));

$this->sendEmail($subject, $adminEmails,
RadicalMartHelperMessage::renderLayout('email.order.' . $layout, array(
'recipient' => 'admin',
'order' => $data,
'constant' => $constant,
'component' => $component,
'params' => $params,
'links' => $links
)));
}
elseif (($type === 'user.create' || $type === 'express.user.create') && !empty($data['result']))
{
// Prepare data
$subject = Text::sprintf('PLG_RADICALMART_MESSAGE_USER_CREATE', $data['user']->name,
$subject = Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_USER_CREATE', $data['user']->name,
Uri::getInstance()->getHost());
$recipient = $data['user']->email;
$body = RadicalMartHelperMessage::renderLayout('email.user.create',
Expand Down
7 changes: 4 additions & 3 deletions email.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<extension version="3.9" type="plugin" group="radicalmart_message" method="upgrade">
<name>PLG_RADICALMART_MESSAGE_EMAIL</name>
<author>Delo Design</author>
<creationDate>August 2021</creationDate>
<creationDate>March 2022</creationDate>
<copyright>Copyright © 2021 Delo Design. All rights reserved.</copyright>
<license>https://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://delo-design.ru</authorUrl>
<version>1.0.0</version>
<version>1.1.0</version>
<description>PLG_RADICALMART_MESSAGE_EMAIL_DESCRIPTION</description>
<scriptfile>script.php</scriptfile>
<languages folder="language">
Expand All @@ -18,13 +18,14 @@
</languages>
<files>
<filename plugin="email">email.php</filename>
<folder>forms</folder>
</files>
<layouts destination="components/radicalmart/message/email" folder="layouts">
<folder>user</folder>
<folder>order</folder>
</layouts>
<updateservers>
<server type="extension" priority="1" name="RadicalMart - Email">
<server type="extension" priority="1" name="RadicalMart Message: Email">
https://radicalmart.ru/update?element=plg_radicalmart_message_email
</server>
</updateservers>
Expand Down
14 changes: 14 additions & 0 deletions forms/express.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="messages" label="COM_RADICALMART_EXPRESS_PARAMS_MESSAGES">
<field type="note" label="PLG_RADICALMART_MESSAGE_EMAIL"
description="PLG_RADICALMART_MESSAGE_EMAIL_DESCRIPTION"/>
<field name="messages_email_admin" type="subform"
label="PLG_RADICALMART_MESSAGE_EMAIL_PARAMS_ADMIN"
multiple="true">
<form>
<field name="email" type="email" label="COM_RADICALMART_EXPRESS_EMAIL" required="true"/>
</form>
</field>
</fieldset>
</form>
14 changes: 14 additions & 0 deletions forms/radicalmart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="messages" label="COM_RADICALMART_PARAMS_MESSAGES">
<field type="note" label="PLG_RADICALMART_MESSAGE_EMAIL"
description="PLG_RADICALMART_MESSAGE_EMAIL_DESCRIPTION"/>
<field name="messages_email_admin" type="subform"
label="PLG_RADICALMART_MESSAGE_EMAIL_PARAMS_ADMIN"
multiple="true">
<form>
<field name="email" type="email" label="COM_RADICALMART_EMAIL" required="true"/>
</form>
</field>
</fieldset>
</form>
2 changes: 1 addition & 1 deletion language/en-GB/en-GB.plg_radicalmart_message_email.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; @package RadicalMart Package
; @subpackage plg_radicalmart_message_email
; @version 1.0.0
; @version 1.1.0
; @author Delo Design - delo-design.ru
; @copyright Copyright (c) 2021 Delo Design. All rights reserved.
; @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand Down
2 changes: 1 addition & 1 deletion language/en-GB/en-GB.plg_radicalmart_message_email.sys.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; @package RadicalMart Package
; @subpackage plg_radicalmart_message_email
; @version 1.0.0
; @version 1.1.0
; @author Delo Design - delo-design.ru
; @copyright Copyright (c) 2021 Delo Design. All rights reserved.
; @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand Down
20 changes: 11 additions & 9 deletions language/ru-RU/ru-RU.plg_radicalmart_message_email.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; @package RadicalMart Package
; @subpackage plg_radicalmart_message_email
; @version 1.0.0
; @version 1.1.0
; @author Delo Design - delo-design.ru
; @copyright Copyright (c) 2021 Delo Design. All rights reserved.
; @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand All @@ -10,11 +10,13 @@
PLG_RADICALMART_MESSAGE_EMAIL = "RadicalMart Message: Email"
PLG_RADICALMART_MESSAGE_EMAIL_DESCRIPTION = "Плагин отправки email сообщений"

PLG_RADICALMART_MESSAGE_ORDER_CREATE = "Новый заказ №%s"
PLG_RADICALMART_MESSAGE_ORDER_CHANGE_STATUS = "Статус заказа №%s изменился на %s"
PLG_RADICALMART_MESSAGE_ORDER_INFORMATION = "Информация о заказе №%s"
PLG_RADICALMART_MESSAGE_USER_CREATE = "%s, ваш доступ к сайту %s"
PLG_RADICALMART_MESSAGE_USER_CREATE_TITLE = "%s, для вас на сайте %s автоматически создана учетная запись."
PLG_RADICALMART_MESSAGE_USER_CREATE_DESC = "Вы можете в любой момент времени авторизоваться на сайте %ы используя"
PLG_RADICALMART_MESSAGE_USER_LOGIN = "Логин"
PLG_RADICALMART_MESSAGE_USER_PASSWORD = "Пароль"
PLG_RADICALMART_MESSAGE_EMAIL_PARAMS_ADMIN = "Почта администраторов"

PLG_RADICALMART_MESSAGE_EMAIL_ORDER_CREATE = "Новый заказ №%s"
PLG_RADICALMART_MESSAGE_EMAIL_ORDER_CHANGE_STATUS = "Статус заказа №%s изменился на %s"
PLG_RADICALMART_MESSAGE_EMAIL_ORDER_INFORMATION = "Информация о заказе №%s"
PLG_RADICALMART_MESSAGE_EMAIL_USER_CREATE = "%s, ваш доступ к сайту %s"
PLG_RADICALMART_MESSAGE_EMAIL_USER_CREATE_TITLE = "%s, для вас на сайте %s автоматически создана учетная запись."
PLG_RADICALMART_MESSAGE_EMAIL_USER_CREATE_DESC = "Вы можете в любой момент времени авторизоваться на сайте %s используя"
PLG_RADICALMART_MESSAGE_EMAIL_USER_LOGIN = "Логин"
PLG_RADICALMART_MESSAGE_EMAIL_USER_PASSWORD = "Пароль"
2 changes: 1 addition & 1 deletion language/ru-RU/ru-RU.plg_radicalmart_message_email.sys.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; @package RadicalMart Package
; @subpackage plg_radicalmart_message_email
; @version 1.0.0
; @version 1.1.0
; @author Delo Design - delo-design.ru
; @copyright Copyright (c) 2021 Delo Design. All rights reserved.
; @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand Down
26 changes: 14 additions & 12 deletions layouts/order/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @package RadicalMart Package
* @subpackage plg_radicalmart_message_email
* @version 1.0.0
* @version 1.1.0
* @author Delo Design - delo-design.ru
* @copyright Copyright (c) 2021 Delo Design. All rights reserved.
* @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand All @@ -15,37 +15,39 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\Registry\Registry;

extract($displayData);

/**
* Layout variables
* -----------------
*
* @var object $order The order id.
* @var string $recipient Mail recipient.
* @var string $constant Language constant.
* @var boolean $links Products links.
* @var object $order The order id.
* @var string $recipient Mail recipient.
* @var string $constant Language constant.
* @var string $component Component name constant.
* @var boolean $links Products links.
* @var Registry $params Component params.
*
*/

$component = strtolower($constant);
$link = Uri::getInstance('site')->toString(array('scheme', 'host', 'port'));
$link .= ($recipient === 'admin') ? '/administrator/index.php?option=' . $component . '&task=order.edit&id='

$link = Uri::getInstance()->toString(array('scheme', 'host', 'port'));
$link .= ($recipient === 'admin') ? '/administrator/index.php?option=' . $component . '&task=order.edit&id='
. $order->id : $order->link;
$params = ComponentHelper::getParams($component);
?>
<h1>
<a href="<?php echo $link; ?>">
<?php echo Text::sprintf('PLG_RADICALMART_MESSAGE_ORDER_INFORMATION', $order->number); ?>
<?php echo Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_ORDER_INFORMATION', $order->number); ?>
</a>
</h1>
<div style="margin-bottom: 20px;">
<div>
<strong><?php echo Text::_($constant . '_STATUS'); ?>: </strong>
<span><?php echo Text::_($order->status->title); ?></span>
</div>
<?php if ($order->shipping): ?>
<?php if (!empty($order->shipping)): ?>
<div>
<strong><?php echo Text::_($constant . '_SHIPPING'); ?>: </strong>
<span>
Expand All @@ -54,7 +56,7 @@
</span>
</div>
<?php endif; ?>
<?php if ($order->payment): ?>
<?php if (!empty($order->payment)): ?>
<div>
<strong><?php echo Text::_($constant . '_PAYMENT'); ?>: </strong>
<span>
Expand Down
23 changes: 12 additions & 11 deletions layouts/order/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @package RadicalMart Package
* @subpackage plg_radicalmart_message_email
* @version 1.0.0
* @version 1.1.0
* @author Delo Design - delo-design.ru
* @copyright Copyright (c) 2021 Delo Design. All rights reserved.
* @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
Expand All @@ -15,37 +15,38 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\Registry\Registry;

extract($displayData);

/**
* Layout variables
* -----------------
*
* @var object $order The order id.
* @var string $recipient Mail recipient.
* @var string $constant Language constant.
* @var boolean $links Products links.
* @var object $order The order id.
* @var string $recipient Mail recipient.
* @var string $constant Language constant.
* @var string $component Component name constant.
* @var boolean $links Products links.
* @var Registry $params Component params.
*
*/

$component = strtolower($constant);
$link = Uri::getInstance('site')->toString(array('scheme', 'host', 'port'));
$link = Uri::getInstance()->toString(array('scheme', 'host', 'port'));
$link .= ($recipient === 'admin') ? '/administrator/index.php?option=' . $component . '&task=order.edit&id='
. $order->id : $order->link;
$params = ComponentHelper::getParams($component);
?>
<h1>
<a href="<?php echo $link; ?>">
<?php echo Text::sprintf('PLG_RADICALMART_MESSAGE_ORDER_INFORMATION', $order->number); ?>
<?php echo Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_ORDER_INFORMATION', $order->number); ?>
</a>
</h1>
<div style="margin-bottom: 20px;">
<div>
<strong><?php echo Text::_($constant . '_STATUS'); ?>: </strong>
<span><?php echo Text::_($order->status->title); ?></span>
</div>
<?php if ($order->shipping): ?>
<?php if (!empty($order->shipping)): ?>
<div>
<strong><?php echo Text::_($constant . '_SHIPPING'); ?>: </strong>
<span>
Expand All @@ -54,7 +55,7 @@
</span>
</div>
<?php endif; ?>
<?php if ($order->payment): ?>
<?php if (!empty($order->payment)): ?>
<div>
<strong><?php echo Text::_($constant . '_PAYMENT'); ?>: </strong>
<span>
Expand Down
Loading

0 comments on commit 25aa2e8

Please sign in to comment.