8
0
Fork 1

add backend controller for orders

Dieser Commit ist enthalten in:
Daniel Seifert 2022-07-04 13:28:58 +02:00
Ursprung 7db6fce401
Commit f3402e6393
Signiert von: DanielS
GPG-Schlüssel-ID: 8A7C4C6ED1915C6F
4 geänderte Dateien mit 213 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,119 @@
<?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\Controller\Admin;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\Linkmobility4OXID\Application\Model\Sms;
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
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\Application\Model\User;
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->sms = oxNew(Sms::class);
$this->addTplParam('recipient', $this->getRecipientFromCurrentOrder());
parent::__construct();
}
/**
* @return Recipient|false
*/
public function getRecipientFromCurrentOrder()
{
try {
return oxNew( OrderRecipients::class, $this->order )->getSmsRecipient();
} catch (noRecipientFoundException $e) {
Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString($e->getMessage())
);
}
return false;
}
/**
* @throws Exception
*/
public function send()
{
$messageBody = Registry::getRequest()->getRequestEscapedParameter( 'messagebody' );
if (strlen($messageBody) <= 1) {
Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
);
return;
}
$order = oxNew(Order::class);
$order->load($this->getEditObjectId());
$sms = oxNew(Sms::class);
if ($sms->sendOrderMessage($order, $messageBody)) {
$this->setRemark( $messageBody );
Registry::getUtilsView()->addErrorToDisplay(
sprintf(
Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'),
$sms->getResponse()->getSmsCount()
)
);
} else {
Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND')
);
}
}
/**
* @param $messageBody
*
* @throws Exception
*/
protected function setRemark( $messageBody )
{
$remark = oxNew( Remark::class );
$remark->assign( [
'oxtype' => 'LMSMS',
'oxparentid' => $this->getEditObjectId(),
'oxtext' => $messageBody
] );
$remark->save();
}
}

Datei anzeigen

@ -0,0 +1,67 @@
<?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;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\LinkmobilityClient\ValueObject\Recipient;
use OxidEsales\Eshop\Application\Model\Country;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
class OrderRecipients
{
/**
* @var Order
*/
private $order;
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* @return Recipient
* @throws noRecipientFoundException
*/
public function getSmsRecipient(): Recipient
{
foreach ($this->getSmsRecipientFields() as $fieldName)
{
$content = trim($this->order->getFieldData($fieldName));
if (strlen($content)) {
$country = oxNew(Country::class);
$country->load($this->order->getUser()->getFieldData('oxcountryid'));
return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2'));
}
}
throw oxNew(noRecipientFoundException::class);
}
/**
* @return string[]
*/
public function getSmsRecipientFields(): array
{
return [
'oxdelfon',
'oxbillfon'
];
}
}

Datei anzeigen

@ -23,6 +23,7 @@ use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Sender;
use GuzzleHttp\Exception\GuzzleException;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
@ -51,6 +52,27 @@ class Sms
return false;
}
/**
* @param Order $order
* @param $message
*
* @return bool
*/
public function sendOrderMessage(Order $order, $message): bool
{
try {
return $this->sendCustomRecipientMessage(
[ oxNew( OrderRecipients::class, $order )->getSmsRecipient() ],
$message
);
} catch (noRecipientFoundException $e) {
Registry::getLogger()->warning($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e);
}
return false;
}
/**
* @param array $recipientsArray
* @param $message

Datei anzeigen

@ -3,6 +3,7 @@
* Metadata version
*/
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
$sMetadataVersion = '2.1';
@ -29,10 +30,12 @@ $aModule = [
\OxidEsales\Eshop\Application\Controller\ContactController::class => \D3\Linkmobility4OXID\Modules\Application\Controller\ContactController::class
],
'controllers' => [
'd3linkmobility_user' => AdminUser::class
'd3linkmobility_user' => AdminUser::class,
'd3linkmobility_order' => AdminOrder::class
],
'templates' => [
'd3adminuser.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl'
'd3adminuser.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl',
'd3adminorder.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl'
],
'events' => [],
'settings' => [