2022-07-04 16:33:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Linkmobility4OXID\Application\Model;
|
|
|
|
|
2022-07-08 15:13:05 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
|
2022-07-04 16:33:49 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Remark;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class MessageSender
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param Order $order
|
|
|
|
* @param $messageBody
|
|
|
|
*/
|
2022-07-08 15:13:05 +02:00
|
|
|
public function sendOrderFinishedMessage(Order $order, $messageBody)
|
2022-07-04 16:33:49 +02:00
|
|
|
{
|
2022-07-08 15:13:05 +02:00
|
|
|
$this->sendMessageByOrder('d3linkmobility_orderActive', $order, $messageBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Order $order
|
|
|
|
* @param $messageBody
|
|
|
|
*/
|
|
|
|
public function sendSendedNowMessage(Order $order, $messageBody)
|
|
|
|
{
|
|
|
|
$this->sendMessageByOrder('d3linkmobility_sendedNowActive', $order, $messageBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Order $order
|
|
|
|
* @param $messageBody
|
|
|
|
*/
|
|
|
|
public function sendCancelOrderMessage(Order $order, $messageBody)
|
|
|
|
{
|
|
|
|
$this->sendMessageByOrder('d3linkmobility_cancelOrderActive', $order, $messageBody);
|
|
|
|
}
|
|
|
|
|
2022-07-12 16:06:19 +02:00
|
|
|
/**
|
|
|
|
* @param $configParam
|
|
|
|
* @param Order $order
|
|
|
|
* @param $messageBody
|
|
|
|
*/
|
2022-07-08 15:13:05 +02:00
|
|
|
public function sendMessageByOrder($configParam, Order $order, $messageBody)
|
|
|
|
{
|
|
|
|
if (false === (bool) Registry::getConfig()->getConfigParam($configParam)
|
|
|
|
|| (bool) strlen(trim($messageBody)) === false
|
2022-07-04 16:33:49 +02:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-07-08 15:13:05 +02:00
|
|
|
$sms = oxNew( Sms::class, $messageBody );
|
|
|
|
if ( $sms->sendOrderMessage( $order ) ) {
|
|
|
|
$this->setRemark( $order->getId(), $sms->getRecipientsList(), $sms->getMessage() );
|
2022-07-04 16:33:49 +02:00
|
|
|
}
|
|
|
|
} catch (noRecipientFoundException $e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $orderId
|
|
|
|
* @param $message
|
|
|
|
*/
|
2022-07-08 15:13:05 +02:00
|
|
|
protected function setRemark($orderId, $recipients, $message)
|
2022-07-04 16:33:49 +02:00
|
|
|
{
|
|
|
|
$remark = oxNew( Remark::class );
|
|
|
|
$remark->assign( [
|
2022-07-08 15:13:05 +02:00
|
|
|
'oxtype' => AdminUser::REMARK_IDENT,
|
2022-07-04 16:33:49 +02:00
|
|
|
'oxparentid' => $orderId,
|
2022-07-08 15:13:05 +02:00
|
|
|
'oxtext' => $recipients.PHP_EOL.$message
|
2022-07-04 16:33:49 +02:00
|
|
|
] );
|
|
|
|
$remark->save();
|
|
|
|
}
|
|
|
|
}
|