Skip to content

Commit

Permalink
Merge 1.2.0 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Septdir authored Dec 22, 2022
1 parent d4d0c38 commit 83416fd
Show file tree
Hide file tree
Showing 11 changed files with 641 additions and 80 deletions.
146 changes: 112 additions & 34 deletions email.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function onRadicalMartPrepareConfigForm($form, $data)
public function onRadicalMartExpressPrepareConfigForm($form, $data)
{
Form::addFormPath(__DIR__ . '/forms');
$form->loadFile('express');
$form->loadFile('radicalmart_express');
}

/**
Expand All @@ -83,30 +83,105 @@ public function onRadicalMartExpressPrepareConfigForm($form, $data)
*/
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;
if (!in_array($type, ['radicalmart.user.create', 'radicalmart.order.create', 'radicalmart.order.change_status']))
{
return;
}

$helper = '\\Joomla\\Component\\RadicalMart\\Administrator\\Helper\\MessageHelper';
$params = \Joomla\Component\RadicalMart\Administrator\Helper\ParamsHelper::getComponentParams();
$layout = 'plugins.radicalmart_message.email.' . $type;

if (in_array($type, ['radicalmart.order.create', 'radicalmart.order.change_status']))
{
// Send order message
$config = Factory::getConfig();
$subject = ($type === 'radicalmart.order.create')
? 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));

// Send client email
if (!empty($data->contacts['email']))
{
$this->sendEmail($subject, $data->contacts['email'],
$helper::renderLayout($layout, [
'recipient' => 'client',
'order' => $data,
'params' => $params,
]));
}

// Send admin email
$adminEmails = [];
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,
$helper::renderLayout($layout, [
'recipient' => 'admin',
'order' => $data,
'params' => $params,
]));
}
elseif (($type === 'radicalmart.user.create') && !empty($data['result']))
{
// Send user email
$subject = Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_USER_CREATE', $data['user']->name,
Uri::getInstance()->getHost());

$constant = 'COM_RADICALMART';
$component = 'com_radicalmart';
if (in_array($type, array('express.user.create', 'express.order.create', 'express.order.change_status')))
$recipient = $data['user']->email;
$body = $helper::renderLayout($layout, ['user' => $data]);

// Send email
$this->sendEmail($subject, $recipient, $body);
}
}

/**
* Method to send message.
*
* @param string $type Message type.
* @param mixed $data Message data.
*
* @throws Exception
*
* @since __DEPLOY_VERSION__
*/
public function onRadicalMartExpressSendMessage($type = null, $data = null)
{
if (!in_array($type, ['radicalmart_express.user.create', 'radicalmart_express.order.create',
'radicalmart_express.order.change_status']))
{
$constant .= '_EXPRESS';
$component .= '_express';
return;
}
$params = ComponentHelper::getParams($component);

if ($type === 'order.create' || $type === 'order.change_status'
|| $type === 'express.order.create' || $type === 'express.order.change_status')
$helper = 'RadicalMartHelperMessage';
$params = ComponentHelper::getParams('com_radicalmart_express');
$layout = 'plugins.radicalmart_message.email.' . $type;

if (in_array($type, ['radicalmart_express.order.create', 'radicalmart_express.order.change_status']))
{
// Send order message
$config = Factory::getConfig();
$layout = ($type === 'order.create' || $type === 'express.order.create')
? 'create' : 'status';
$subject = ($type === 'order.create' || $type === 'express.order.create')
$subject = ($type === 'radicalmart_express.order.create')
? 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)
if ($data->status->id !== 2)
{
$links = false;
}
Expand All @@ -115,45 +190,48 @@ public function onRadicalMartSendMessage($type = null, $data = null)
if (!empty($data->contacts['email']))
{
$this->sendEmail($subject, $data->contacts['email'],
RadicalMartHelperMessage::renderLayout('email.order.' . $layout, array(
$helper::renderLayout($layout, [
'recipient' => 'client',
'order' => $data,
'constant' => $constant,
'component' => $component,
'params' => $params,
'links' => $links
)));
'links' => $links,
]));
}

// Send admin email
$adminEmails = array();
$adminEmails = [];
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($param->email))
{
$adminEmails[] = $param->email;
}
}
}
if (empty($adminEmails)) $adminEmails[] = $config->get('replyto', $config->get('mailfrom'));

if (empty($adminEmails))
{
$adminEmails[] = $config->get('replyto', $config->get('mailfrom'));
}

$this->sendEmail($subject, $adminEmails,
RadicalMartHelperMessage::renderLayout('email.order.' . $layout, array(
$helper::renderLayout($layout, [
'recipient' => 'admin',
'order' => $data,
'constant' => $constant,
'component' => $component,
'params' => $params,
'links' => $links
)));
'links' => true,
]));
}
elseif (($type === 'user.create' || $type === 'express.user.create') && !empty($data['result']))
elseif (($type === 'radicalmart_express.user.create') && !empty($data['result']))
{
// Prepare data
$subject = Text::sprintf('PLG_RADICALMART_MESSAGE_EMAIL_USER_CREATE', $data['user']->name,
// Send user email
$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',
array('user' => $data, 'constant' => $constant));
$body = $helper::renderLayout($layout, ['user' => $data]);

// Send email
$this->sendEmail($subject, $recipient, $body);
Expand Down Expand Up @@ -185,7 +263,7 @@ protected function sendEmail($subject, $recipient, $body)
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->addRecipient($recipient);
$mailer->addReplyTo($config->get('replyto'), $config->get('replytoname'));
//$mailer->addReplyTo($config->get('replyto'), $config->get('replytoname'));
$mailer->setBody($body);

return $mailer->Send();
Expand Down
8 changes: 4 additions & 4 deletions email.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<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 destination="plugins/radicalmart_message/email" folder="layouts">
<folder>radicalmart</folder>
<folder>radicalmart_express</folder>
</layouts>
<updateservers>
<server type="extension" priority="1" name="RadicalMart Message: Email">
https://radicalmart.ru/update?element=plg_radicalmart_message_email
https://sovmart.ru/update?element=plg_radicalmart_message_email
</server>
</updateservers>
</extension>
5 changes: 2 additions & 3 deletions forms/radicalmart.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?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"/>
<fieldset name="messages_email" 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">
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
*
*/


$root = Uri::getInstance()->toString(array('scheme', 'host', 'port'));
$link = $root;
$link .= ($recipient === 'admin') ? '/administrator/index.php?option=' . $component . '&task=order.edit&id='
$link .= ($recipient === 'admin') ? '/administrator/index.php?option=com_radicalmart&task=order.edit&id='
. $order->id : $order->link;
?>
<h1>
Expand All @@ -45,12 +44,12 @@
</h1>
<div style="margin-bottom: 20px;">
<div>
<strong><?php echo Text::_($constant . '_STATUS'); ?>: </strong>
<strong><?php echo Text::_('COM_RADICALMART_STATUS'); ?>: </strong>
<span><?php echo Text::_($order->status->title); ?></span>
</div>
<?php if (!empty($order->shipping)): ?>
<div>
<strong><?php echo Text::_($constant . '_SHIPPING'); ?>: </strong>
<strong><?php echo Text::_('COM_RADICALMART_SHIPPING'); ?>: </strong>
<span>
<?php echo (!empty($order->shipping->order->title)) ?
$order->shipping->order->title : $order->shipping->title; ?>
Expand All @@ -59,7 +58,7 @@
<?php endif; ?>
<?php if (!empty($order->payment)): ?>
<div>
<strong><?php echo Text::_($constant . '_PAYMENT'); ?>: </strong>
<strong><?php echo Text::_('COM_RADICALMART_PAYMENT'); ?>: </strong>
<span>
<?php echo (!empty($order->payment->order->title)) ?
$order->payment->order->title : $order->payment->title; ?>
Expand All @@ -71,9 +70,9 @@
if (empty(trim($value))) continue;

if ($label = $params->get('fields_' . $key . '_label')) $label = Text::_($label);
elseif (Factory::getLanguage()->hasKey($constant . '_' . $key))
elseif (Factory::getLanguage()->hasKey('COM_RADICALMART_' . $key))
{
$label = Text::_($constant . '_' . $key);
$label = Text::_('COM_RADICALMART_' . $key);
}
else $label = $key;
?>
Expand All @@ -88,16 +87,16 @@
<thead>
<tr>
<th style="text-align: left; vertical-align: bottom; font-weight: bold;padding: 8px;line-height: 18px; border-left:1px solid #ddd; ">
<?php echo Text::_($constant . '_PRODUCT'); ?>
<?php echo Text::_('COM_RADICALMART_PRODUCT'); ?>
</th>
<th style="vertical-align: bottom; font-weight: bold;padding: 8px;line-height: 18px; border-left:1px solid #ddd; text-align: right;">
<?php echo Text::_($constant . '_PRICE'); ?>
<?php echo Text::_('COM_RADICALMART_PRICE'); ?>
</th>
<th style="vertical-align: bottom; font-weight: bold;padding: 8px;line-height: 18px; border-left:1px solid #ddd; text-align: center;">
<?php echo Text::_($constant . '_QUANTITY'); ?>
<?php echo Text::_('COM_RADICALMART_QUANTITY'); ?>
</th>
<th style=" vertical-align: bottom; font-weight: bold;padding: 8px;line-height: 18px; border-left:1px solid #ddd; text-align: right;">
<?php echo Text::_($constant . '_SUM'); ?>
<?php echo Text::_('COM_RADICALMART_SUM'); ?>
</th>
</tr>
</thead>
Expand All @@ -106,12 +105,15 @@
$i = 0;
foreach ($order->products as $p => $product) :
$style = 'padding: 8px; line-height: 18px; text-align: left; vertical-align: top;border-top: 1px solid #ddd;';
if ($i % 2) $style .= 'background-color: #f9f9f9;';
if ($i % 2)
{
$style .= 'background-color: #f9f9f9;';
}
$i++;
?>
<tr>
<td style="<?php echo $style; ?>">
<?php if ($product->link && $links) : ?>
<?php if ($product->link) : ?>
<a href="<?php echo $root . $product->link; ?>" style="word-wrap:break-word;"
class="uk-link-reset"><?php echo $product->title; ?></a>
<?php else: ?>
Expand Down Expand Up @@ -188,29 +190,29 @@ class="uk-link-reset"><?php echo $product->title; ?></a>
<td colspan="3" style="border-top: 1px solid #ddd;"></td>
<td style="border-top: 1px solid #ddd; text-align: right;">
<div style="margin-bottom: 5px;">
<span><?php echo Text::_($constant . '_SUBTOTAL'); ?>: </span>
<span><?php echo Text::_('COM_RADICALMART_SUBTOTAL'); ?>: </span>
<span>
<?php echo str_replace(' ', '&nbsp;', $order->total['base_seo']); ?>
</span>
</div>
<?php if (!empty($order->total['discount'])): ?>
<div style="margin-bottom: 5px;">
<span><?php echo Text::_($constant . '_PRICE_DISCOUNT'); ?>: </span>
<span><?php echo Text::_('COM_RADICALMART_PRICE_DISCOUNT'); ?>: </span>
<span>
<?php echo str_replace(' ', '&nbsp;', $order->total['discount_seo']); ?>
</span>
</div>
<?php endif; ?>
<?php if ($order->payment && !empty($order->payment->order->price['fee_string'])): ?>
<div style="margin-bottom: 5px;">
<span><?php echo Text::_($constant . '_PRICE_FEE'); ?>: </span>
<span><?php echo Text::_('COM_RADICALMART_PRICE_FEE'); ?>: </span>
<span>
<?php echo str_replace(' ', '&nbsp;', $order->total['fee_seo']); ?>
</span>
</div>
<?php endif; ?>
<div style="font-size: 18px; padding: 20px">
<span><?php echo Text::_($constant . '_TOTAL'); ?>: </span>
<span><?php echo Text::_('COM_RADICALMART_TOTAL'); ?>: </span>
<strong>
<?php echo str_replace(' ', '&nbsp;', $order->total['final_seo']); ?>
</strong>
Expand All @@ -222,7 +224,7 @@ class="uk-link-reset"><?php echo $product->title; ?></a>
<?php if ($order->pay && $recipient == 'client'): ?>
<div style="text-align: center;margin-top:20px;">
<a href="<?php echo $order->pay; ?>" style="color: #006838;font-size: 22px;">
<?php echo Text::_($constant . '_PAY'); ?>
<?php echo Text::_('COM_RADICALMART_PAY'); ?>
</a>
</div>
<?php endif; ?>
Loading

0 comments on commit 83416fd

Please sign in to comment.