add order sent message and order canceled message

This commit is contained in:
2022-07-08 09:49:39 +02:00
parent 4676d57ee2
commit eb5ece8fef
14 changed files with 176 additions and 91 deletions

View File

@ -0,0 +1,34 @@
<?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\Exceptions;
use OxidEsales\Eshop\Core\Registry;
use Throwable;
class successfullySentException extends \Exception
{
/**
* @param int $messageCount
* @param int $code
* @param Throwable|null $previous
*/
public function __construct( $messageCount = 1, $code = 0, Throwable $previous = null )
{
$message = sprintf( Registry::getLang()->translateString( 'D3LM_EXC_SMS_SUCC_SENT' ), $messageCount);
parent::__construct( $message, $code, $previous );
}
}

View File

@ -39,13 +39,13 @@ class OrderRecipients
*/
public function getSmsRecipient(): Recipient
{
foreach ($this->getSmsRecipientFields() as $fieldName)
foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName)
{
$content = trim($this->order->getFieldData($fieldName));
if (strlen($content)) {
$content = trim($this->order->getFieldData($phoneFieldName));
if (strlen($content)) {
$country = oxNew(Country::class);
$country->load($this->order->getUser()->getFieldData('oxcountryid'));
$country->load($this->order->getFieldData($countryIdFieldName));
return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2'));
}
@ -60,8 +60,8 @@ class OrderRecipients
public function getSmsRecipientFields(): array
{
return [
'oxdelfon',
'oxbillfon'
'oxdelfon' => 'oxdelcountryid',
'oxbillfon' => 'oxbillcountryid'
];
}
}

View File

@ -62,10 +62,19 @@ class Sms
public function sendOrderMessage(Order $order, $message): bool
{
try {
return $this->sendCustomRecipientMessage(
oxNew( OrderRecipients::class, $order )->getSmsRecipient();
} catch (Exception $e) {
dumpvar($e->getMessage());
}
try {
Registry::getLogger()->debug('startRequest', ['orderId' => $order->getId()]);
$return = $this->sendCustomRecipientMessage(
[ oxNew( OrderRecipients::class, $order )->getSmsRecipient() ],
$message
);
Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
return $return;
} catch (noRecipientFoundException $e) {
Registry::getLogger()->warning($e->getMessage());
throw $e;
@ -91,6 +100,7 @@ class Sms
foreach ($recipientsArray as $recipient) {
$recipientsList->add( $recipient );
}
$response = $client->request( $request );
$this->response = $response;