set remarks from manually sent order or user messages

This commit is contained in:
Daniel Seifert 2022-07-08 10:17:59 +02:00
parent eb5ece8fef
commit b4ead1d4af
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
6 changed files with 49 additions and 9 deletions

View File

@ -89,7 +89,7 @@ class AdminOrder extends AdminController
try { try {
$sms = oxNew( Sms::class ); $sms = oxNew( Sms::class );
if ( $sms->sendOrderMessage( $order, $messageBody ) ) { if ( $sms->sendOrderMessage( $order, $messageBody ) ) {
$this->setRemark( $messageBody ); $this->setRemark( $sms->getRecipientsList(), $messageBody );
Registry::getUtilsView()->addErrorToDisplay( Registry::getUtilsView()->addErrorToDisplay(
oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount() ) oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount() )
); );
@ -106,13 +106,13 @@ class AdminOrder extends AdminController
* *
* @throws Exception * @throws Exception
*/ */
protected function setRemark( $messageBody ) protected function setRemark( $recipients, $messageBody )
{ {
$remark = oxNew( Remark::class ); $remark = oxNew( Remark::class );
$remark->assign( [ $remark->assign( [
'oxtype' => 'LMSMS', 'oxtype' => AdminUser::REMARK_IDENT,
'oxparentid' => $this->getEditObjectId(), 'oxparentid' => $this->order->getUser()->getId(),
'oxtext' => $messageBody 'oxtext' => $recipients.PHP_EOL.$messageBody
] ); ] );
$remark->save(); $remark->save();
} }

View File

@ -27,6 +27,8 @@ use OxidEsales\Eshop\Core\Registry;
class AdminUser extends AdminController class AdminUser extends AdminController
{ {
const REMARK_IDENT = 'LMSMS';
protected $_sThisTemplate = 'd3adminuser.tpl'; protected $_sThisTemplate = 'd3adminuser.tpl';
/** /**
@ -85,7 +87,7 @@ class AdminUser extends AdminController
$sms = oxNew(Sms::class); $sms = oxNew(Sms::class);
if ($sms->sendUserAccountMessage($user, $messageBody)) { if ($sms->sendUserAccountMessage($user, $messageBody)) {
$this->setRemark( $messageBody ); $this->setRemark( $sms->getRecipientsList(), $messageBody );
Registry::getUtilsView()->addErrorToDisplay( Registry::getUtilsView()->addErrorToDisplay(
sprintf( sprintf(
Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'),
@ -104,13 +106,13 @@ class AdminUser extends AdminController
* *
* @throws Exception * @throws Exception
*/ */
protected function setRemark( $messageBody ) protected function setRemark( $recipients, $messageBody )
{ {
$remark = oxNew( Remark::class ); $remark = oxNew( Remark::class );
$remark->assign( [ $remark->assign( [
'oxtype' => 'LMSMS', 'oxtype' => AdminUser::REMARK_IDENT,
'oxparentid' => $this->getEditObjectId(), 'oxparentid' => $this->getEditObjectId(),
'oxtext' => $messageBody 'oxtext' => $recipients.PHP_EOL.$messageBody
] ); ] );
$remark->save(); $remark->save();
} }

View File

@ -21,6 +21,7 @@ use D3\Linkmobility4OXID\Application\Model\RequestFactory;
use D3\LinkmobilityClient\Exceptions\ApiException; use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\Request\RequestInterface; use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\LinkmobilityClient\ValueObject\Sender; use D3\LinkmobilityClient\ValueObject\Sender;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
@ -30,6 +31,7 @@ use OxidEsales\Eshop\Core\Registry;
class Sms class Sms
{ {
private $response; private $response;
private $recipients = [];
/** /**
* @param User $user * @param User $user
@ -90,6 +92,7 @@ class Sms
public function sendCustomRecipientMessage(array $recipientsArray, $message): bool public function sendCustomRecipientMessage(array $recipientsArray, $message): bool
{ {
try { try {
$this->setRecipients($recipientsArray);
$configuration = oxNew( Configuration::class ); $configuration = oxNew( Configuration::class );
$client = oxNew( MessageClient::class )->getClient(); $client = oxNew( MessageClient::class )->getClient();
@ -130,4 +133,20 @@ class Sms
{ {
return $this->response; 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);
}
} }

View File

@ -35,6 +35,8 @@ $aLang = [
'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'Beim Versenden der Nachricht(en) ist ein unerwarteter Fehler aufgetreten.', 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' => 'Beim Versenden der Nachricht(en) ist ein unerwarteter Fehler aufgetreten.',
'D3LM_EXC_NO_RECIPIENT_SET' => 'Kein (verwendbarer) Empfänger gesetzt.', 'D3LM_EXC_NO_RECIPIENT_SET' => 'Kein (verwendbarer) Empfänger gesetzt.',
'D3LM_REMARK_SMS' => 'SMS-Nachr.',
'tbcluser_linkmobility' => 'SMS-Versand', 'tbcluser_linkmobility' => 'SMS-Versand',
'tbclorder_linkmobility' => 'SMS-Versand' 'tbclorder_linkmobility' => 'SMS-Versand'
]; ];

View File

@ -0,0 +1,5 @@
[{if $allitem->oxremark__oxtype->value == "LMSMS"}]
[{oxmultilang ident="D3LM_REMARK_SMS"}]
[{else}]
[{$smarty.block.parent}]
[{/if}]

View File

@ -44,6 +44,18 @@ $aModule = [
'd3sms_ordercanceled.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/ordercanceled.tpl', 'd3sms_ordercanceled.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/ordercanceled.tpl',
], ],
'events' => [], 'events' => [],
'blocks' => [
[
'template' => 'order_remark.tpl',
'block' => 'admin_order_remark_type',
'file' => 'Application/views/blocks/admin/admin_user_remark_type.tpl',
],
[
'template' => 'user_remark.tpl',
'block' => 'admin_user_remark_type',
'file' => 'Application/views/blocks/admin/admin_user_remark_type.tpl',
]
],
'settings' => [ 'settings' => [
[ [
'group' => $sModuleId.'_general', 'group' => $sModuleId.'_general',