diff --git a/ajax/backend/shippingStatus/getNotificationText.php b/ajax/backend/shippingStatus/getNotificationText.php index c5d8562473dc10211ad68bfc6c8fb5776859f20b..0481fbabc4924a7bfd81e9f3d670e12baf25c6a9 100644 --- a/ajax/backend/shippingStatus/getNotificationText.php +++ b/ajax/backend/shippingStatus/getNotificationText.php @@ -16,17 +16,19 @@ */ QUI::$Ajax->registerFunction( 'package_quiqqer_shipping_ajax_backend_shippingStatus_getNotificationText', - function ($id, $orderId) { + function ($shippingId, $orderId) { try { $Order = OrderHandler::getInstance()->get($orderId); - return Handler::getInstance()->getShippingStatus($id)->getStatusChangeNotificationText($Order); + return Handler::getInstance() + ->getShippingStatus($shippingId) + ->getStatusChangeNotificationText($Order); } catch (\Exception $Exception) { QUI\System\Log::writeException($Exception); return ''; } }, - ['id', 'orderId'], + ['shippingId', 'orderId'], 'Permission::checkAdminUser' ); diff --git a/bin/backend/classes/ShippingStatus.js b/bin/backend/classes/ShippingStatus.js index 010d3adc881b91e6ed795e9575f01335cd5d8e06..7c2bb944990327c440319dbadf44ff28a2a4faa4 100644 --- a/bin/backend/classes/ShippingStatus.js +++ b/bin/backend/classes/ShippingStatus.js @@ -143,16 +143,16 @@ define('package/quiqqer/shipping/bin/backend/classes/ShippingStatus', [ /** * Get status change notification text for a specific shipping * - * @param {Number} id - ShippingStatus ID - * @param {Number} shippingId - shipping ID + * @param {Number} shippingId - ShippingStatus ID + * @param {Number} orderId - shipping ID * @return {Promise} */ - getNotificationText: function (id, shippingId) { + getNotificationText: function (shippingId, orderId) { return new Promise(function (resolve, reject) { QUIAjax.get('package_quiqqer_shipping_ajax_backend_shippingStatus_getNotificationText', resolve, { 'package' : 'quiqqer/shipping', - id : id, shippingId: shippingId, + orderId : orderId, onError : reject }); }); diff --git a/locale.xml b/locale.xml index 26cb98b1a52230bf32bc86f3a1d958ef20afd948..2ce0d0c18746c72c9c9ffc0ababd19437029c8a6 100644 --- a/locale.xml +++ b/locale.xml @@ -413,6 +413,23 @@ <de><![CDATA[Wählen Sie bitte hier Ihre standard Versandaddresse aus.]]></de> <en><![CDATA[Please select your standard shipping address here.]]></en> </locale> + + <locale name="shipping.status.notification.subject"> + <de><![CDATA[Änderung Ihrer Bestellung [orderNo]]]></de> + <en><![CDATA[Change of your order [orderNo]]]></en> + </locale> + <locale name="shipping.status.notification.template" html="true"> + <de><![CDATA[ + <p>Hallo [customerName],</p> + <p>der Versandstatus Ihrer Bestellung <b>[orderNo]</b> vom <b>[orderDate]</b> hat sich geändert. + Die Bestellung ist nun <b>[shippingStatus]</b>. + ]]></de> + <en><![CDATA[ + <p>Hello [customerName],</p> + <p>the shipping status of your order <b>[orderNo]</b> from <b>[orderDate]</b> changed. + The order is now <b>[shippingStatus]</b>. + ]]></en> + </locale> </groups> diff --git a/src/QUI/ERP/Shipping/Shipping.php b/src/QUI/ERP/Shipping/Shipping.php index 2e7573d9cec3998ee8250a72cf092d0ba85965a2..6c0600b9ddf5c506b9d205de7b1c7390cc812ece 100644 --- a/src/QUI/ERP/Shipping/Shipping.php +++ b/src/QUI/ERP/Shipping/Shipping.php @@ -363,4 +363,58 @@ public function getShippingByOrderId($orderId) return $this->getShippingByObject($Order); } + + + /** + * Notify customer about an Order status change (via e-mail) + * + * @param QUI\ERP\Order\AbstractOrder $Order + * @param int $statusId + * @param string $message (optional) - Custom notification message [default: default status change message] + * @return void + * + * @throws QUI\Exception + */ + public function sendStatusChangeNotification( + QUI\ERP\Order\AbstractOrder $Order, + $statusId, + $message = null + ) { + $Customer = $Order->getCustomer(); + $customerEmail = $Customer->getAttribute('email'); + + if (empty($customerEmail)) { + QUI\System\Log::addWarning( + 'Status change notification for order #'.$Order->getPrefixedId().' cannot be sent' + .' because customer #'.$Customer->getId().' has no e-mail address.' + ); + + return; + } + + if (empty($message)) { + $Status = ShippingStatus\Handler::getInstance()->getShippingStatus($statusId); + $message = $Status->getStatusChangeNotificationText($Order); + } + + $Mailer = new QUI\Mail\Mailer(); + /** @var QUI\Locale $Locale */ + $Locale = $Order->getCustomer()->getLocale(); + + $Mailer->setSubject( + $Locale->get('quiqqer/shipping', 'shipping.status.notification.subject', [ + 'orderNo' => $Order->getPrefixedId() + ]) + ); + + $Mailer->setBody($message); + $Mailer->addRecipient($customerEmail); + + try { + $Mailer->send(); + $Order->addStatusMail($message); + } catch (\Exception $Exception) { + QUI\System\Log::writeException($Exception); + } + } } diff --git a/src/QUI/ERP/Shipping/ShippingStatus/Status.php b/src/QUI/ERP/Shipping/ShippingStatus/Status.php index 18eb14316b3dccdf434ad389f7808cd5cb76dcb7..03e9f4a0760755d7faa27eec2c529732b3fdca88 100644 --- a/src/QUI/ERP/Shipping/ShippingStatus/Status.php +++ b/src/QUI/ERP/Shipping/ShippingStatus/Status.php @@ -107,12 +107,23 @@ public function getStatusChangeNotificationText(AbstractOrder $Order, $Locale = $Customer = $Order->getCustomer(); - return $Locale->get('quiqqer/shipping', 'shipping.status.notification.'.$this->id, [ - 'customerName' => $Customer->getName(), - 'orderNo' => $Order->getPrefixedId(), - 'orderDate' => $Locale->formatDate($Order->getCreateDate()), - 'orderStatus' => $this->getTitle($Locale) + $message = $Locale->get('quiqqer/shipping', 'shipping.status.notification.'.$this->id, [ + 'customerName' => $Customer->getName(), + 'orderNo' => $Order->getPrefixedId(), + 'orderDate' => $Locale->formatDate($Order->getCreateDate()), + 'shippingStatus' => $this->getTitle($Locale) ]); + + if (QUI::getLocale()->isLocaleString($message)) { + $message = $Locale->get('quiqqer/shipping', 'shipping.status.notification.template', [ + 'customerName' => $Customer->getName(), + 'orderNo' => $Order->getPrefixedId(), + 'orderDate' => $Locale->formatDate($Order->getCreateDate()), + 'shippingStatus' => $this->getTitle($Locale) + ]); + } + + return $message; } /** @@ -143,8 +154,9 @@ public function isAutoNotification() * @param null|QUI\Locale $Locale - optional. if no locale, all translations would be returned * @return array */ - public function toArray($Locale = null) - { + public function toArray( + $Locale = null + ) { $title = $this->getTitle($Locale); if ($Locale === null) {