Merge branch 'rel_1.x' into dev_1.x_tests

This commit is contained in:
Daniel Seifert 2022-07-15 22:56:41 +02:00
commit 42be99c268
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
10 changed files with 213 additions and 124 deletions

View File

@ -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->getUser()->getId(),
'oxtext' => $recipients.PHP_EOL.$messageBody
]);
$remark->save();
}
}

View File

@ -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();
}
}

View File

@ -58,7 +58,7 @@ class Configuration
$country = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderCountry'));
$country = strlen($country) ? strtoupper($country) : null;
Assert::that($country)->nullOr() || Assert::that($country)->string()->length(2);
Assert::that($country)->nullOr()->string()->length(2);
return $country;
}

View File

@ -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();
}
}

View File

@ -0,0 +1,113 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @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;
}

View File

@ -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(
[ $this->getOrderRecipient($order) ]
);
if ($return) {
$this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage());
}
Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
return $return;
} catch (noRecipientFoundException $e) {
@ -148,44 +152,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';
}
}

View File

@ -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:<br><div>Telefonnummernfeld => LänderIdFeld</div><div>Bsp.: "oxdelfon => oxdelcuntryid"</div>',
'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:<br><div>Telefonnummernfeld => LänderIdFeld</div><div>Bsp.: "oxdelfon => oxdelcountryid"</div>',
'SHOP_MODULE_GROUP_d3linkmobility_trigger' => 'Nachrichtenversand bei ...',
'SHOP_MODULE_d3linkmobility_orderActive' => 'abgeschlossener Bestellung',

View File

@ -0,0 +1,62 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @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:<br><div>Phone number field => country ID field</div><div>e.g.: "oxdelfon => oxdelcountryid"</div>',
'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'
];

View File

@ -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}]

View File

@ -31,8 +31,8 @@ $aModule = [
'id' => $sModuleId,
'title' => $sD3Logo . ' LINK Mobility Mobile Messaging',
'description' => [
'de' => 'Anbindung der LINK Mobility API <ul><li>Nachrichtenversand per SMS</li></ul> 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',