2022-07-04 13:28:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-07-13 13:21:52 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2022-07-04 13:28:58 +02:00
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2022-07-13 13:21:52 +02:00
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2022-07-04 13:28:58 +02:00
|
|
|
*/
|
|
|
|
|
2022-07-13 13:21:52 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-04 13:28:58 +02:00
|
|
|
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
|
|
|
|
|
|
|
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
2022-07-08 09:49:39 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
|
2022-07-15 22:46:52 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
2022-07-04 13:28:58 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
|
2022-07-13 15:38:53 +02:00
|
|
|
use D3\LinkmobilityClient\Response\ResponseInterface;
|
2022-07-04 13:28:58 +02:00
|
|
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
|
|
|
use Exception;
|
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class AdminOrder extends AdminController
|
|
|
|
{
|
|
|
|
protected $_sThisTemplate = 'd3adminorder.tpl';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Sms
|
|
|
|
*/
|
|
|
|
protected $sms;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Order
|
|
|
|
*/
|
|
|
|
protected $order;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->order = $order = oxNew(Order::class);
|
|
|
|
$order->load($this->getEditObjectId());
|
|
|
|
|
|
|
|
$this->addTplParam('recipient', $this->getRecipientFromCurrentOrder());
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Recipient|false
|
|
|
|
*/
|
|
|
|
public function getRecipientFromCurrentOrder()
|
|
|
|
{
|
|
|
|
try {
|
2022-07-13 13:23:48 +02:00
|
|
|
return oxNew(OrderRecipients::class, $this->order)->getSmsRecipient();
|
2022-07-04 13:28:58 +02:00
|
|
|
} catch (noRecipientFoundException $e) {
|
|
|
|
Registry::getUtilsView()->addErrorToDisplay(
|
|
|
|
Registry::getLang()->translateString($e->getMessage())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function send()
|
|
|
|
{
|
2022-07-13 13:23:48 +02:00
|
|
|
$messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody');
|
2022-07-04 13:28:58 +02:00
|
|
|
|
2022-07-15 13:39:32 +02:00
|
|
|
if (false === is_string($messageBody) || strlen($messageBody) <= 1) {
|
2022-07-04 13:28:58 +02:00
|
|
|
Registry::getUtilsView()->addErrorToDisplay(
|
|
|
|
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = oxNew(Order::class);
|
|
|
|
$order->load($this->getEditObjectId());
|
|
|
|
|
2022-07-04 16:33:49 +02:00
|
|
|
try {
|
2022-07-13 13:23:48 +02:00
|
|
|
$sms = oxNew(Sms::class, $messageBody);
|
|
|
|
if ($sms->sendOrderMessage($order)) {
|
2022-07-08 09:49:39 +02:00
|
|
|
Registry::getUtilsView()->addErrorToDisplay(
|
2022-07-13 13:23:48 +02:00
|
|
|
oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount())
|
2022-07-08 09:49:39 +02:00
|
|
|
);
|
2022-07-04 16:33:49 +02:00
|
|
|
} else {
|
2022-07-13 15:38:53 +02:00
|
|
|
$errorMsg = $sms->getResponse() instanceof ResponseInterface ? $sms->getResponse()->getErrorMessage() : 'no response';
|
2022-07-12 13:44:05 +02:00
|
|
|
Registry::getUtilsView()->addErrorToDisplay(
|
|
|
|
sprintf(
|
2022-07-13 13:23:48 +02:00
|
|
|
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'),
|
2022-07-13 15:38:53 +02:00
|
|
|
$errorMsg
|
2022-07-12 13:44:05 +02:00
|
|
|
)
|
|
|
|
);
|
2022-07-04 16:33:49 +02:00
|
|
|
}
|
|
|
|
} catch (noRecipientFoundException $e) {
|
|
|
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
2022-07-04 13:28:58 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-13 13:23:48 +02:00
|
|
|
}
|