From 006d1643e0540de7f455070dfa714142084f726f Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 14 Jul 2022 16:04:26 +0200 Subject: [PATCH 1/4] allow sender country is null --- src/Application/Model/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index 90f8777..9da0a7c 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -58,7 +58,7 @@ class Configuration $country = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderCountry')); $country = strlen($country) ? strtoupper($country) : null; - Assert::that($country)->null() || Assert::that($country)->string()->length(2); + Assert::that($country)->nullOr()->string()->length(2); return $country; } From c63db72ec49f41f1e954e6dd214e7a06417009dc Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 15 Jul 2022 09:39:13 +0200 Subject: [PATCH 2/4] adjust translation, add english translations --- .../views/admin/de/d3Linkmobility_lang.php | 6 +- .../views/admin/en/d3Linkmobility_lang.php | 62 +++++++++++++++++++ src/metadata.php | 4 +- 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 src/Application/views/admin/en/d3Linkmobility_lang.php diff --git a/src/Application/views/admin/de/d3Linkmobility_lang.php b/src/Application/views/admin/de/d3Linkmobility_lang.php index f6f2379..092d4f1 100644 --- a/src/Application/views/admin/de/d3Linkmobility_lang.php +++ b/src/Application/views/admin/de/d3Linkmobility_lang.php @@ -30,13 +30,13 @@ $aLang = [ 'SHOP_MODULE_GROUP_d3linkmobility_sms' => 'SMS-Versand', 'SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Sendernummer', - 'HELP_SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Ihre Mobilfunknummer, die als Antwortziel verwendet werden kann., Bitte lassen Sie die gewünschte Telefonnummer in Ihrem Konto hinterlegen.', + 'HELP_SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Ihre Mobilfunknummer, die als Absender verwendet wird. Bitte lassen Sie die gewünschte Telefonnummer in Ihrem Konto hinterlegen. Ist dort nur eine Nummer hinterlegt, brauchen Sie hier keine Angabe machen. Dann wird automatisch die Telefonnummer aus Ihrem Konto verwendet.', 'SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Landeskürzel', - 'HELP_SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Geben Sie hier das Landeskürzel (ISO-Alpha-2, z.B. DE, AT, FR) an, zu dem Ihre Mobilfunknummer zugeordnet ist.', + 'HELP_SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Geben Sie hier das Landeskürzel (ISO-Alpha-2, z.B. DE, AT, FR) an, zu dem Ihre Mobilfunknummer zugeordnet ist. Diese Angabe ist nur nötig, wenn Sie eine Sendernummer angegeben haben.', 'SHOP_MODULE_d3linkmobility_smsUserRecipientsFields'=> 'Felder des Benutzerkontos, die auf gültige Mobilfunknummern geprüft werden', 'HELP_SHOP_MODULE_d3linkmobility_smsUserRecipientsFields' => 'Die Felder werden in dieser Reihenfolge geprüft und das erste valide Vorkommen wird zum Senden der Nachricht verwendet. Ohne (gültige) Feldangabe werden die Felder "oxmobfon", "oxfon" und "oxprivfon" geprüft.', 'SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields'=> 'Felder der Bestellung, die auf gültige Mobilfunknummern und zugehörige Länderident geprüft werden', - 'HELP_SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields' => 'Die Felder werden in dieser Reihenfolge geprüft und das erste valide Vorkommen wird zum Senden der Nachricht verwendet. Ohne (gültige) Feldangabe werden die Felder "oxdelfon", und "oxbillfon" geprüft. Zum Telefonnummernfeld ist die Angabe des dazugehörigen Landesidentfeldes erforderlich. Individuelle Angaben erfolgen in diesem Format:
Telefonnummernfeld => LänderIdFeld
Bsp.: "oxdelfon => oxdelcuntryid"
', + 'HELP_SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields' => 'Die Felder werden in dieser Reihenfolge geprüft und das erste valide Vorkommen wird zum Senden der Nachricht verwendet. Ohne (gültige) Feldangabe werden die Felder "oxdelfon", und "oxbillfon" geprüft. Zum Telefonnummernfeld ist die Angabe des dazugehörigen Landesidentfeldes erforderlich. Individuelle Angaben erfolgen in diesem Format:
Telefonnummernfeld => LänderIdFeld
Bsp.: "oxdelfon => oxdelcountryid"
', 'SHOP_MODULE_GROUP_d3linkmobility_trigger' => 'Nachrichtenversand bei ...', 'SHOP_MODULE_d3linkmobility_orderActive' => 'abgeschlossener Bestellung', diff --git a/src/Application/views/admin/en/d3Linkmobility_lang.php b/src/Application/views/admin/en/d3Linkmobility_lang.php new file mode 100644 index 0000000..301e07a --- /dev/null +++ b/src/Application/views/admin/en/d3Linkmobility_lang.php @@ -0,0 +1,62 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +$sLangName = "English"; +// ------------------------------- +// RESOURCE IDENTITFIER = STRING +// ------------------------------- +$aLang = [ + +//Navigation + 'charset' => 'UTF-8', + + 'SHOP_MODULE_GROUP_d3linkmobility_general' => 'Basic settings', + 'SHOP_MODULE_d3linkmobility_debug' => 'Test mode', + 'HELP_SHOP_MODULE_d3linkmobility_debug' => 'With test mode enabled, Linkmobility will not send the messages. However, the request is processed and returns a system response.', + 'SHOP_MODULE_d3linkmobility_apitoken' => 'API token', + 'HELP_SHOP_MODULE_d3linkmobility_apitoken' => 'Please generate the API token in your Linkmobility account.', + + 'SHOP_MODULE_GROUP_d3linkmobility_sms' => 'Sending SMS', + 'SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Sender number', + 'HELP_SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Your mobile phone number, which will be used as the sender. Please have the desired telephone number stored in your account. If only one number is stored there, you do not need to enter anything here. In this case, the telephone number from your account will be used automatically.', + 'SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Country code', + 'HELP_SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Enter the country code (ISO alpha-2, e.g. DE, AT, FR) to which your mobile phone number is assigned. This information is only necessary if you have entered a sender number.', + 'SHOP_MODULE_d3linkmobility_smsUserRecipientsFields'=> 'User account fields checked for valid mobile numbers', + 'HELP_SHOP_MODULE_d3linkmobility_smsUserRecipientsFields' => 'The fields are checked in this order and the first valid occurrence is used to send the message. Without (valid) field specification, the fields "oxmobfon", "oxfon" and "oxprivfon" are checked.', + 'SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields'=> 'Fields of the order that are checked for valid mobile phone numbers and associated country identifiers', + 'HELP_SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields' => 'The fields are checked in this order and the first valid occurrence is used to send the message. Without (valid) field specification, the fields "oxdelfon" and "oxbillfon" are checked. For the telephone number field, the corresponding country ID field is required. Individual specifications are given in this format:
Phone number field => country ID field
e.g.: "oxdelfon => oxdelcountryid"
', + + 'SHOP_MODULE_GROUP_d3linkmobility_trigger' => 'Sending messages with ...', + 'SHOP_MODULE_d3linkmobility_orderActive' => 'finished order', + 'HELP_SHOP_MODULE_d3linkmobility_orderActive' => 'If an order was successfully completed in the frontend, the SMS message is also sent to the customer to send the order confirmation mail. The content of the SMS notification can be found in the template "Application/views/tpl/SMS/order_cust.tpl".', + 'SHOP_MODULE_d3linkmobility_sendedNowActive' => 'shipping notification', + 'HELP_SHOP_MODULE_d3linkmobility_sendedNowActive' => 'If the delivery date is set in the shop backend and this is communicated to the customer by e-mail (separate checkbox), the information is also sent via SMS. The content of the SMS notification can be found in the template "Application/views/tpl/SMS/sendednow.tpl".', + 'SHOP_MODULE_d3linkmobility_cancelOrderActive' => 'Order cancellation', + 'HELP_SHOP_MODULE_d3linkmobility_cancelOrderActive' => 'When cancelling the order, the customer receives an information by SMS. The content of the SMS notification can be found in the template "Application/views/tpl/SMS/ordercanceled.tpl".', + + 'D3LM_ADMIN_USER_RECIPIENT' => 'Recipient number', + 'D3LM_ADMIN_USER_MESSAGE' => 'Message', + 'D3LM_ADMIN_SEND' => 'submit', + + 'D3LM_EXC_MESSAGE_NO_LENGTH' => 'The message must have content', + 'D3LM_EXC_SMS_SUCC_SENT' => 'The message was sent successfully. (%1$s message(s) used)', + 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'This error occurred while sending the message(s): %1$s', + 'D3LM_EXC_NO_RECIPIENT_SET' => 'No (usable) recipient number is set.', + + 'D3LM_REMARK_SMS' => 'SMS message', + + 'tbcluser_linkmobility' => 'sending SMS', + 'tbclorder_linkmobility' => 'sending SMS' +]; diff --git a/src/metadata.php b/src/metadata.php index fbe85f7..e3a1efa 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -31,8 +31,8 @@ $aModule = [ 'id' => $sModuleId, 'title' => $sD3Logo . ' LINK Mobility Mobile Messaging', 'description' => [ - 'de' => 'Anbindung der LINK Mobility API an den Shop', - 'en' => '', + 'de' => 'Anbindung der LINK Mobility API (Nachrichtenversand per SMS) an den Shop', + 'en' => 'Connection of the LINK Mobility API ( sending messages via SMS) to the shop', ], 'version' => '1.0.0.0', 'thumbnail' => 'picture.png', From 0e6f66554ef0775e5b69ac260e074946b0a1783d Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 15 Jul 2022 13:39:32 +0200 Subject: [PATCH 3/4] use order user for remark instead of current session user --- src/Application/Controller/Admin/AdminOrder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application/Controller/Admin/AdminOrder.php b/src/Application/Controller/Admin/AdminOrder.php index 287b0e5..de588f9 100644 --- a/src/Application/Controller/Admin/AdminOrder.php +++ b/src/Application/Controller/Admin/AdminOrder.php @@ -73,7 +73,7 @@ class AdminOrder extends AdminController { $messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody'); - if (strlen($messageBody) <= 1) { + if (false === is_string($messageBody) || strlen($messageBody) <= 1) { Registry::getUtilsView()->addErrorToDisplay( Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH') ); @@ -115,7 +115,7 @@ class AdminOrder extends AdminController $remark = oxNew(Remark::class); $remark->assign([ 'oxtype' => AdminUser::REMARK_IDENT, - 'oxparentid' => $this->order->getUser()->getId(), + 'oxparentid' => $this->order->getOrderUser()->getId(), 'oxtext' => $recipients.PHP_EOL.$messageBody ]); $remark->save(); From 95249a247a85f77de5d3f1bf04a53acfc9872704 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 15 Jul 2022 22:46:52 +0200 Subject: [PATCH 4/4] move writing remarks to a more centralized class --- .../Controller/Admin/AdminOrder.php | 21 +--- .../Controller/Admin/AdminUser.php | 23 +--- src/Application/Model/MessageSender.php | 30 ++--- .../Model/MessageTypes/AbstractMessage.php | 113 ++++++++++++++++++ .../Model/{ => MessageTypes}/Sms.php | 74 ++++-------- .../blocks/admin/admin_user_remark_type.tpl | 2 +- 6 files changed, 145 insertions(+), 118 deletions(-) create mode 100644 src/Application/Model/MessageTypes/AbstractMessage.php rename src/Application/Model/{ => MessageTypes}/Sms.php (74%) diff --git a/src/Application/Controller/Admin/AdminOrder.php b/src/Application/Controller/Admin/AdminOrder.php index de588f9..7f276c1 100644 --- a/src/Application/Controller/Admin/AdminOrder.php +++ b/src/Application/Controller/Admin/AdminOrder.php @@ -17,14 +17,13 @@ namespace D3\Linkmobility4OXID\Application\Controller\Admin; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; +use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\OrderRecipients; -use D3\Linkmobility4OXID\Application\Model\Sms; use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\ValueObject\Recipient; use Exception; use OxidEsales\Eshop\Application\Controller\Admin\AdminController; use OxidEsales\Eshop\Application\Model\Order; -use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Core\Registry; class AdminOrder extends AdminController @@ -86,7 +85,6 @@ class AdminOrder extends AdminController try { $sms = oxNew(Sms::class, $messageBody); if ($sms->sendOrderMessage($order)) { - $this->setRemark($sms->getRecipientsList(), $sms->getMessage()); Registry::getUtilsView()->addErrorToDisplay( oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount()) ); @@ -103,21 +101,4 @@ class AdminOrder extends AdminController Registry::getUtilsView()->addErrorToDisplay($e); } } - - /** - * @param $recipients - * @param $messageBody - * - * @throws Exception - */ - protected function setRemark($recipients, $messageBody) - { - $remark = oxNew(Remark::class); - $remark->assign([ - 'oxtype' => AdminUser::REMARK_IDENT, - 'oxparentid' => $this->order->getOrderUser()->getId(), - 'oxtext' => $recipients.PHP_EOL.$messageBody - ]); - $remark->save(); - } } diff --git a/src/Application/Controller/Admin/AdminUser.php b/src/Application/Controller/Admin/AdminUser.php index ad659d2..e4a27b6 100644 --- a/src/Application/Controller/Admin/AdminUser.php +++ b/src/Application/Controller/Admin/AdminUser.php @@ -16,20 +16,17 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Controller\Admin; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; -use D3\Linkmobility4OXID\Application\Model\Sms; +use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\ValueObject\Recipient; use Exception; use OxidEsales\Eshop\Application\Controller\Admin\AdminController; -use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Registry; class AdminUser extends AdminController { - public const REMARK_IDENT = 'LMSMS'; - protected $_sThisTemplate = 'd3adminuser.tpl'; /** @@ -86,7 +83,6 @@ class AdminUser extends AdminController $sms = oxNew(Sms::class, $messageBody); if ($sms->sendUserAccountMessage($user)) { - $this->setRemark($sms->getRecipientsList(), $sms->getMessage()); Registry::getUtilsView()->addErrorToDisplay( sprintf( Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), @@ -103,21 +99,4 @@ class AdminUser extends AdminController ); } } - - /** - * @param $recipients - * @param $messageBody - * - * @throws Exception - */ - protected function setRemark($recipients, $messageBody) - { - $remark = oxNew(Remark::class); - $remark->assign([ - 'oxtype' => AdminUser::REMARK_IDENT, - 'oxparentid' => $this->getEditObjectId(), - 'oxtext' => $recipients.PHP_EOL.$messageBody - ]); - $remark->save(); - } } diff --git a/src/Application/Model/MessageSender.php b/src/Application/Model/MessageSender.php index 8d368e3..8aa7c18 100644 --- a/src/Application/Model/MessageSender.php +++ b/src/Application/Model/MessageSender.php @@ -15,10 +15,10 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Model; -use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; +use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; +use Exception; use OxidEsales\Eshop\Application\Model\Order; -use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Core\Registry; class MessageSender @@ -26,6 +26,7 @@ class MessageSender /** * @param Order $order * @param $messageBody + * @throws Exception */ public function sendOrderFinishedMessage(Order $order, $messageBody) { @@ -35,6 +36,7 @@ class MessageSender /** * @param Order $order * @param $messageBody + * @throws Exception */ public function sendSendedNowMessage(Order $order, $messageBody) { @@ -44,6 +46,7 @@ class MessageSender /** * @param Order $order * @param $messageBody + * @throws Exception */ public function sendCancelOrderMessage(Order $order, $messageBody) { @@ -54,6 +57,7 @@ class MessageSender * @param $configParam * @param Order $order * @param $messageBody + * @throws Exception */ public function sendMessageByOrder($configParam, Order $order, $messageBody) { @@ -65,28 +69,8 @@ class MessageSender try { $sms = oxNew(Sms::class, $messageBody); - if ($sms->sendOrderMessage($order)) { - $this->setRemark($order->getId(), $sms->getRecipientsList(), $sms->getMessage()); - } + $sms->sendOrderMessage($order); } catch (noRecipientFoundException $e) { } } - - /** - * @param $orderId - * @param $recipients - * @param $message - * - * @throws \Exception - */ - protected function setRemark($orderId, $recipients, $message) - { - $remark = oxNew(Remark::class); - $remark->assign([ - 'oxtype' => AdminUser::REMARK_IDENT, - 'oxparentid' => $orderId, - 'oxtext' => $recipients.PHP_EOL.$message - ]); - $remark->save(); - } } diff --git a/src/Application/Model/MessageTypes/AbstractMessage.php b/src/Application/Model/MessageTypes/AbstractMessage.php new file mode 100644 index 0000000..1bc8c70 --- /dev/null +++ b/src/Application/Model/MessageTypes/AbstractMessage.php @@ -0,0 +1,113 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4OXID\Application\Model\MessageTypes; + +use D3\LinkmobilityClient\Response\ResponseInterface; +use D3\LinkmobilityClient\ValueObject\Recipient; +use Exception; +use OxidEsales\Eshop\Application\Model\Remark; + +abstract class AbstractMessage +{ + const REMARK_IDENT = 'LINKMOB'; + + protected $message; + protected $removeLineBreaks = true; + protected $removeMultipleSpaces = true; + + protected $response; + protected $recipients = []; + + /** + * @param string $message + */ + public function __construct(string $message) + { + $this->message = $this->sanitizeMessage($message); + } + + /** + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * @param $userId + * @param $recipients + * @param $message + * + * @throws Exception + */ + protected function setRemark($userId, $recipients, $message) + { + $remark = oxNew(Remark::class); + $remark->assign([ + 'oxtype' => self::REMARK_IDENT, + 'oxparentid' => $userId, + 'oxtext' => $this->getTypeName().' -> '.$recipients.PHP_EOL.$message + ]); + $remark->save(); + } + + /** + * @return ResponseInterface|null + */ + public function getResponse() + { + return $this->response; + } + + /** + * @param array $recipients + * @return void + */ + protected function setRecipients(array $recipients) + { + $this->recipients = $recipients; + } + + /** + * @return string + */ + public function getRecipientsList(): string + { + $list = []; + /** @var Recipient $recipient */ + foreach ($this->recipients as $recipient) { + $list[] = $recipient->get(); + } + + return implode(', ', $list); + } + + /** + * @param $message + * + * @return string + */ + protected function sanitizeMessage($message): string + { + $message = trim(strip_tags($message)); + $message = $this->removeLineBreaks ? str_replace(["\r", "\n"], ' ', $message) : $message; + $regexp = '/\s{2,}/m'; + return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message; + } + + abstract public function getTypeName() : string; +} diff --git a/src/Application/Model/Sms.php b/src/Application/Model/MessageTypes/Sms.php similarity index 74% rename from src/Application/Model/Sms.php rename to src/Application/Model/MessageTypes/Sms.php index 092a14c..0045104 100644 --- a/src/Application/Model/Sms.php +++ b/src/Application/Model/MessageTypes/Sms.php @@ -13,46 +13,46 @@ declare(strict_types=1); -namespace D3\Linkmobility4OXID\Application\Model; +namespace D3\Linkmobility4OXID\Application\Model\MessageTypes; +use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Exceptions\abortSendingExceptionInterface; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; +use D3\Linkmobility4OXID\Application\Model\MessageClient; +use D3\Linkmobility4OXID\Application\Model\OrderRecipients; +use D3\Linkmobility4OXID\Application\Model\RequestFactory; +use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\LinkmobilityClient\Exceptions\ApiException; use D3\LinkmobilityClient\Request\RequestInterface; -use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\SMS\SmsRequestInterface; -use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Sender; +use Exception; use GuzzleHttp\Exception\GuzzleException; use InvalidArgumentException; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Registry; -class Sms +class Sms extends AbstractMessage { - private $response; - private $recipients = []; - private $message; - protected $removeLineBreaks = true; - protected $removeMultipleSpaces = true; - - public function __construct(string $message) - { - $this->message = $this->sanitizeMessage($message); - } - /** * @param User $user * * @return bool + * @throws Exception */ public function sendUserAccountMessage(User $user): bool { try { - return $this->sendCustomRecipientMessage( + Registry::getLogger()->debug('startRequest', ['userId' => $user->getId()]); + $return = $this->sendCustomRecipientMessage( [ oxNew(UserRecipients::class, $user)->getSmsRecipient() ] ); + if ($return) { + $this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage()); + } + Registry::getLogger()->debug('finishRequest', ['userId' => $user->getId()]); + return $return; } catch (noRecipientFoundException $e) { Registry::getLogger()->warning($e->getMessage()); Registry::getUtilsView()->addErrorToDisplay($e); @@ -66,6 +66,7 @@ class Sms * * @return bool * @throws noRecipientFoundException + * @throws Exception */ public function sendOrderMessage(Order $order): bool { @@ -74,6 +75,9 @@ class Sms $return = $this->sendCustomRecipientMessage( [ oxNew(OrderRecipients::class, $order)->getSmsRecipient() ] ); + if ($return) { + $this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage()); + } Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]); return $return; } catch (noRecipientFoundException $e) { @@ -138,44 +142,10 @@ class Sms } /** - * @return ResponseInterface|null - */ - public function getResponse() - { - return $this->response; - } - - protected function setRecipients(array $recipients) - { - $this->recipients = $recipients; - } - - public function getRecipientsList(): string - { - $list = []; - /** @var Recipient $recipient */ - foreach ($this->recipients as $recipient) { - $list[] = $recipient->get(); - } - - return implode(', ', $list); - } - - /** - * @param $message - * * @return string */ - protected function sanitizeMessage($message): string + public function getTypeName(): string { - $message = trim(strip_tags($message)); - $message = $this->removeLineBreaks ? str_replace(["\r", "\n"], ' ', $message) : $message; - $regexp = '/\s{2,}/m'; - return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message; - } - - public function getMessage(): string - { - return $this->message; + return 'SMS'; } } diff --git a/src/Application/views/blocks/admin/admin_user_remark_type.tpl b/src/Application/views/blocks/admin/admin_user_remark_type.tpl index 8c1ba19..94ce023 100644 --- a/src/Application/views/blocks/admin/admin_user_remark_type.tpl +++ b/src/Application/views/blocks/admin/admin_user_remark_type.tpl @@ -1,4 +1,4 @@ -[{if $allitem->oxremark__oxtype->value == "LMSMS"}] +[{if $allitem->oxremark__oxtype->value == "LINKMOB"}] [{oxmultilang ident="D3LM_REMARK_SMS"}] [{else}] [{$smarty.block.parent}]