Skip to content

Commit d2a955a

Browse files
author
zanardi
committed
Refs #10620
1 parent 72faebf commit d2a955a

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

component/backend/config.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
<option value="1">JYes</option>
1111
</field>
1212
<field name="email_address" type="text" default="" label="PIZZABOX_CONFIG_FIELD_EMAIL_ADDRESS_LABEL" description="PIZZABOX_CONFIG_FIELD_EMAIL_ADDRESS_DESC" />
13-
<field name="user:email_notification" type="radio" default="0" label="PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_LABEL" description="PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_DESC">
13+
<field name="user_email_notification" type="radio" default="0" label="PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_LABEL" description="PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_DESC">
14+
<option value="0">JNo</option>
15+
<option value="1">JYes</option>
16+
</field>
17+
<field name="email_includes_order" type="radio" default="0" label="PIZZABOX_CONFIG_FIELD_EMAIL_INCLUDES_ORDER_LABEL" description="PIZZABOX_CONFIG_FIELD_EMAIL_INCLUDES_ORDER_DESC">
1418
<option value="0">JNo</option>
1519
<option value="1">JYes</option>
1620
</field>

component/backend/language/en-GB/en-GB.com_pizzabox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ PIZZABOX_CONFIG_FIELD_EMAIL_ADDRESS_LABEL="E-mail address"
4343
PIZZABOX_CONFIG_FIELD_EMAIL_ADDRESS_DESC="What e-mail address should receive the notification.<br/>If not set, the notification will be sent to all Joomla users that are set to receive system e-mails"
4444
PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_LABEL="User notification"
4545
PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_DESC="Enable e-mail notification to the customer as well"
46+
PIZZABOX_CONFIG_FIELD_EMAIL_INCLUDES_ORDER_LABEL="Include order in email"
47+
PIZZABOX_CONFIG_FIELD_EMAIL_INCLUDES_ORDER_DESC="If enabled, the mail message includes full order details instead of just a link to see the order online"
4648

4749
PIZZABOX_CONFIG_FIELDSET_DELIVERY_TITLE="Delivery options"
4850
PIZZABOX_CONFIG_FIELD_TIME_ENABLED_LABEL="Time enabled"

component/backend/language/it-IT/it-IT.com_pizzabox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ PIZZABOX_CONFIG_FIELD_EMAIL_ADDRESS_LABEL="Indirzzi e-mail"
4343
PIZZABOX_CONFIG_FIELD_EMAIL_ADDRESS_DESC="L'indirizzo e-mail a cui mandare la notifica.<br/>Se non è impostato, la notifica verrà inviata a tutti gli utenti Joomla impostati per ricevere le e-mail di sistema"
4444
PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_LABEL="Notifica utente"
4545
PIZZABOX_CONFIG_FIELD_USER_EMAIL_NOTIFICATION_DESC="Abilita la notifica via e-mail anche all'acquirente"
46+
PIZZABOX_CONFIG_FIELD_EMAIL_INCLUDES_ORDER_LABEL="Includi ordine in email"
47+
PIZZABOX_CONFIG_FIELD_EMAIL_INCLUDES_ORDER_DESC="Se abilitato, la mail conterrà il dettaglio completo dell'ordine anzichè semplicemente un link per visualizzare l'ordine sul sito"
4648

4749
PIZZABOX_CONFIG_FIELDSET_DELIVERY_TITLE="Opzioni di consegna"
4850
PIZZABOX_CONFIG_FIELD_TIME_ENABLED_LABEL="Orario abilitato"

component/frontend/helpers/pizzabox.php

+64-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
* @copyright Copyright (C) 2011-2013 GiBiLogic. All rights reserved.
99
* @license GNU/GPL v2 or later
1010
*/
11-
1211
defined('_JEXEC') or die();
12+
require_once(JPATH_COMPONENT_ADMINISTRATOR . '/models/orders.php');
1313

1414
/**
1515
* PizzaboxHelper
1616
*/
1717
class PizzaboxHelper
1818
{
19+
1920
public function __construct()
2021
{
2122
$this->params = & JComponentHelper::getParams('com_pizzabox');
@@ -62,21 +63,57 @@ public function emailNotification($order_id)
6263
$mailer->addRecipient($user->email, $user->name);
6364

6465
// Subject and body
65-
$link = JURI::root() . JRoute::_("index.php?option=com_pizzabox&controller=orders&task=edit&id=$order_id");
6666
$mailer->setSubject(JText::_('PIZZABOX_EMAIL_NOTIFICATION_SUBJECT'));
67-
$mailer->setBody('<html><body><p>' . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY') . " <a href=\"$link\">" . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY_ORDER_DETAIL') . "</a></p></body></html>");
67+
$mailer->setBody('<html><body><p>' . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY') . $this->buildOrderBody($order_id) . "</p></body></html>");
6868

6969
// Send message
7070
$mailer->IsHTML(true);
7171
$mailer->send();
7272
}
7373

74+
/**
75+
* Build the order body to include in email notification
76+
*
77+
* @param int $order_id
78+
* @return string
79+
*/
80+
private function buildOrderBody($order_id)
81+
{
82+
if (!$this->params->get("email_includes_order", 0))
83+
{
84+
$link = JURI::root() . JRoute::_("index.php?option=com_pizzabox&controller=orders&task=edit&id=$order_id");
85+
return "<a href=\"$link\">" . JText::_('PIZZABOX_EMAIL_NOTIFICATION_BODY_ORDER_DETAIL') . "</a>";
86+
}
87+
88+
$orderModel = new PizzaboxModelOrders();
89+
$orderModel->setId($order_id);
90+
$this->order = $orderModel->getItem();
91+
$parts = $orderModel->getParts();
92+
93+
foreach ($parts as &$part)
94+
{
95+
$part->container_image = JURI::root() . $this->getElementImage('containers', $part->container_id);
96+
$part->part_image = JURI::root() . $this->getElementImage('parts', $part->part_id);
97+
$part->flavour_image = JURI::root() . $this->getElementImage('flavours', $part->flavour_id);
98+
}
99+
100+
$this->order_total = $orderModel->getTotal();
101+
$this->parts = $parts;
102+
$this->orderData = $this->convertOrderRows($parts);
103+
$this->tpl = "confirmed";
104+
$this->helper = new PizzaboxHelper();
105+
106+
ob_start();
107+
include JPATH_COMPONENT_SITE . '/layouts/_order_details.php';
108+
return "<div>".ob_get_clean()."</div>";
109+
}
110+
74111
/**
75112
* Get all admin recipients which should receive the notification
76113
*/
77114
private function getAdminRecipients()
78115
{
79-
if ( ! $this->params->get('email_notification', 0))
116+
if (!$this->params->get('email_notification', 0))
80117
{
81118
return array();
82119
}
@@ -145,8 +182,8 @@ protected function _getSystemEmailAddresses()
145182
{
146183
$recipients = array();
147184
$query = "SELECT `name`, `email` " .
148-
"FROM `#__users` " .
149-
"WHERE `sendEmail` = '1'";
185+
"FROM `#__users` " .
186+
"WHERE `sendEmail` = '1'";
150187
$db = & JFactory::getDBO();
151188
$db->setQuery($query);
152189
if ($result = $db->loadObjectList())
@@ -155,4 +192,25 @@ protected function _getSystemEmailAddresses()
155192
}
156193
}
157194

195+
/**
196+
* Get image for a given element type and id
197+
*
198+
* @param string $elements_type
199+
* @param int $id
200+
* @return string
201+
*/
202+
private function getElementImage($elements_type, $id)
203+
{
204+
$class_name = "PizzaboxModel" . $elements_type;
205+
if (!class_exists($class_name))
206+
{
207+
require_once ( JPATH_COMPONENT_ADMINISTRATOR . '/models/' . $elements_type . '.php' );
208+
}
209+
210+
$model = new $class_name();
211+
$model->setId($id);
212+
$element = $model->getItem();
213+
return ( $element['row']->image );
214+
}
215+
158216
}

0 commit comments

Comments
 (0)