add order sent message and order canceled message

This commit is contained in:
Daniel Seifert 2022-07-08 09:49:39 +02:00
parent 4676d57ee2
commit eb5ece8fef
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
14 changed files with 176 additions and 91 deletions

View File

@ -16,6 +16,7 @@
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\Linkmobility4OXID\Application\Model\Sms;
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
@ -89,7 +90,9 @@ class AdminOrder extends AdminController
$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() ) );
Registry::getUtilsView()->addErrorToDisplay(
oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount() )
);
} else {
Registry::getUtilsView()->addErrorToDisplay( Registry::getLang()->translateString( 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' ) );
}

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;

View File

@ -35,5 +35,6 @@ $aLang = [
'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.',
'tbcluser_linkmobility' => 'SMS-Versand'
'tbcluser_linkmobility' => 'SMS-Versand',
'tbclorder_linkmobility' => 'SMS-Versand'
];

View File

@ -1,3 +1,6 @@
Vielen Dank für Ihre Bestellung!
[{*
[{assign var="shop" value=$oEmailView->getShop()}]
[{assign var="oViewConf" value=$oEmailView->getViewConfig()}]
[{assign var="currency" value=$oEmailView->getCurrency()}]
@ -55,30 +58,24 @@
------------------------------------------------------------------
[{if !$basket->getDiscounts()}]
[{block name="email_plain_order_cust_nodiscounttotalnet"}]
[{* netto price *}]
[{oxmultilang ident="TOTAL_NET"}] [{$basket->getProductsNetPrice()}] [{$currency->name}]
[{/block}]
[{block name="email_plain_order_cust_nodiscountproductvats"}]
[{* VATs *}]
[{foreach from=$basket->getProductVats() item=VATitem key=key}]
[{oxmultilang ident="VAT_PLUS_PERCENT_AMOUNT" suffix="COLON" args=$key}] [{$VATitem}] [{$currency->name}]
[{/foreach}]
[{/block}]
[{block name="email_plain_order_cust_nodiscounttotalgross"}]
[{* brutto price *}]
[{oxmultilang ident="TOTAL_GROSS"}] [{$basket->getFProductsPrice()}] [{$currency->name}]
[{/block}]
[{/if}]
[{* applied discounts *}]
[{if $basket->getDiscounts()}]
[{if $order->isNettoMode()}]
[{block name="email_plain_order_ownerdiscounttotalnet"}]
[{* netto price *}]
[{oxmultilang ident="TOTAL_NET"}] [{$basket->getProductsNetPrice()}] [{$currency->name}]
[{/block}]
[{else}]
[{block name="email_plain_order_discountownertotalgross"}]
[{* brutto price *}]
[{oxmultilang ident="TOTAL_GROSS"}] [{$basket->getFProductsPrice()}] [{$currency->name}]
[{/block}]
[{/if}]
@ -89,12 +86,10 @@
[{/block}]
[{if !$order->isNettoMode()}]
[{block name="email_plain_order_cust_totalnet"}]
[{* netto price *}]
[{oxmultilang ident="TOTAL_NET"}] [{$basket->getProductsNetPrice()}] [{$currency->name}]
[{/block}]
[{/if}]
[{block name="email_plain_order_cust_productvats"}]
[{* VATs *}]
[{foreach from=$basket->getProductVats() item=VATitem key=key}]
[{oxmultilang ident="VAT_PLUS_PERCENT_AMOUNT" suffix="COLON" args=$key}] [{$VATitem}] [{$currency->name}]
[{/foreach}]
@ -102,19 +97,16 @@
[{/if}]
[{if $order->isNettoMode()}]
[{block name="email_plain_order_ownertotalgross"}]
[{* brutto price *}]
[{oxmultilang ident="TOTAL_GROSS"}] [{$basket->getFProductsPrice()}] [{$currency->name}]
[{/block}]
[{/if}]
[{block name="email_plain_order_cust_voucherdiscount"}]
[{* voucher discounts *}]
[{if $oViewConf->getShowVouchers() && $basket->getVoucherDiscValue()}]
[{oxmultilang ident="COUPON"}] [{if $basket->getFVoucherDiscountValue() > 0}]-[{/if}][{$basket->getFVoucherDiscountValue()|replace:"-":""}] [{$currency->name}]
[{/if}]
[{/block}]
[{block name="email_plain_order_cust_delcosts"}]
[{* delivery costs *}]
[{if $basket->getDelCostNet()}]
[{oxmultilang ident="SHIPPING_NET" suffix="COLON"}] [{$basket->getDelCostNet()}] [{$currency->sign}]
[{if $basket->getDelCostVat()}] [{oxmultilang ident="BASKET_TOTAL_PLUS_PROPORTIONAL_VAT"}] [{else}] [{oxmultilang ident="VAT_PLUS_PERCENT_AMOUNT" suffix="COLON" args=$basket->getDelCostVatPercent()}][{/if}] [{$basket->getDelCostVat()}] [{$currency->sign}]
@ -124,7 +116,6 @@
[{/block}]
[{block name="email_plain_order_cust_paymentcosts"}]
[{* payment sum *}]
[{if $basket->getPayCostNet()}]
[{if $basket->getPaymentCosts() >= 0}][{oxmultilang ident="SURCHARGE"}][{else}][{oxmultilang ident="DEDUCTION"}][{/if}] [{oxmultilang ident="PAYMENT_METHOD"}] [{$basket->getPayCostNet()}] [{$currency->sign}]
[{if $basket->getPayCostVat()}]
@ -136,7 +127,6 @@
[{/block}]
[{block name="email_plain_order_cust_wrappingcosts"}]
[{* Gift wrapping *}]
[{if $oViewConf->getShowGiftWrapping()}]
[{if $basket->getWrappCostNet()}]
[{oxmultilang ident="BASKET_TOTAL_WRAPPING_COSTS_NET"}] [{$basket->getWrappCostNet()}] [{$currency->sign}]
@ -150,7 +140,6 @@
[{/block}]
[{block name="email_plain_order_cust_giftwrapping"}]
[{* Greeting card *}]
[{if $oViewConf->getShowGiftWrapping()}]
[{if $basket->getGiftCardCostNet()}]
[{oxmultilang ident="BASKET_TOTAL_GIFTCARD_COSTS_NET"}] [{$basket->getGiftCardCostNet()}] [{$currency->sign}]
@ -164,7 +153,6 @@
[{/block}]
[{block name="email_plain_order_cust_grandtotal"}]
[{* grand total price *}]
[{oxmultilang ident="GRAND_TOTAL"}] [{$basket->getFPrice()}] [{$currency->name}]
[{if $basket->getCard()}]
@ -245,3 +233,4 @@
[{/block}]
[{oxcontent ident="oxemailfooterplain"}]
*}]

View File

@ -0,0 +1 @@
Ihre Bestellung wurde storniert.

View File

@ -0,0 +1 @@
Ihre Bestellung wurde eben versendet.

View File

@ -20,6 +20,13 @@ namespace D3\Linkmobility4OXID\Modules\Application\Controller
class StartController_parent extends StartController {}
}
namespace D3\Linkmobility4OXID\Modules\Aplication\Model {
use OxidEsales\Eshop\Application\Model\Order;
class OrderModel_parent extends Order{}
}
namespace D3\Linkmobility4OXID\Modules\Core {
use OxidEsales\Eshop\Core\Email;

View File

@ -1,49 +0,0 @@
<?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\Modules\Application\Controller;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\SMS\Request;
use D3\LinkmobilityClient\ValueObject\Sender;
use D3\LinkmobilityClient\ValueObject\SmsMessage;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Domain\Contact\Form\ContactFormBridgeInterface;
class ContactController extends ContactController_parent
{
public function send()
{
$contactFormBridge = $this->getContainer()->get(ContactFormBridgeInterface::class);
$form = $contactFormBridge->getContactForm();
$form->handleRequest($this->getMappedContactFormRequest());
if ($form->isValid()) {
$contactMessageSender = oxNew(MessageSender::class);
$contactMessageSender->send(
$form->email->getValue(),
$form->subject->getValue(),
$contactFormBridge->getContactFormMessage($form)
);
} else {
foreach ($form->getErrors() as $error) {
Registry::getUtilsView()->addErrorToDisplay($error);
}
return false;
}
}
}

View File

@ -29,16 +29,13 @@ class StartController extends StartController_parent
//$message = "test\tMessage\ttest\tMessage";
$order = oxNew(Order::class);
$order->load('03444d89ad35b138c150003e69fdff34');
dumpvar(__METHOD__.__LINE__.PHP_EOL);
$order->load('eda00356201d7ec2bcf31166fa6c37dd');
/** @var EmailCore $mail */
$mail = oxNew(Email::class);
$mail->d3SendOrderMessage($order);
die();
$user = oxNew(User::class);
$user->load('oxdefaultadmin');
$success = oxNew(Sms::class)->sendUserAccountMessage($user, $message);
dumpvar($success);
return parent::render();
}
}

View File

@ -0,0 +1,32 @@
<?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\Modules\Application\Model;
use D3\Linkmobility4OXID\Application\Model\MessageSender;
use OxidEsales\Eshop\Core\Email;
class OrderModel extends OrderModel_parent
{
public function cancelOrder()
{
parent::cancelOrder();
if ($this->getFieldData('oxstorno') === 1) {
$Email = oxNew( Email::class );
$Email->d3SendCancelMessage($this);
}
}
}

View File

@ -24,6 +24,8 @@ use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInte
class EmailCore extends EmailCore_parent
{
protected $orderCustSmsTemplate = 'd3sms_ordercust.tpl';
protected $orderSendedNowSmsTemplate = 'd3sms_sendednow.tpl';
protected $orderCanceledSmsTemplate = 'd3sms_ordercanceled.tpl';
/**
* @param Order $order
@ -40,6 +42,21 @@ class EmailCore extends EmailCore_parent
return $ret;
}
/**
* @param Order $order
* @param null $subject
*
* @return bool
*/
public function sendSendedNowMail($order, $subject = null)
{
$ret = parent::sendSendedNowMail($order, $subject);
$this->d3SendedNowMessage($order);
return $ret;
}
/**
* @param Order $order
*
@ -47,8 +64,6 @@ class EmailCore extends EmailCore_parent
*/
public function d3SendOrderMessage(Order $order)
{
dumpvar($this->d3GetOrderSmsMessageBody($order));
die();
$messageSender = oxNew(MessageSender::class);
$messageSender->sendOrderMessage($order, $this->d3GetOrderSmsMessageBody($order));
}
@ -63,11 +78,52 @@ class EmailCore extends EmailCore_parent
$renderer = $this->d3GetTplRenderer();
$this->setViewData("order", $order);
dumpvar($this->orderCustSmsTemplate);
return $renderer->renderTemplate($this->orderCustSmsTemplate, $this->getViewData());
}
/**
* @param Order $order
*
* @throws Exception
*/
public function d3SendedNowMessage(Order $order)
{
$messageSender = oxNew(MessageSender::class);
$messageSender->sendOrderMessage($order, $this->d3GetSendedNowSmsMessageBody($order));
}
/**
* @param Order $order
*
* @return string
*/
protected function d3GetSendedNowSmsMessageBody(Order $order): string
{
$renderer = $this->d3GetTplRenderer();
$this->setViewData("order", $order);
return $renderer->renderTemplate($this->orderSendedNowSmsTemplate, $this->getViewData());
}
public function d3SendCancelMessage($order)
{
$messageSender = oxNew(MessageSender::class);
$messageSender->sendCancelOrderMessage($order, $this->d3GetCancelOrderSmsMessageBody($order));
}
/**
* @param Order $order
*
* @return string
*/
protected function d3GetCancelOrderSmsMessageBody(Order $order): string
{
$renderer = $this->d3GetTplRenderer();
$this->setViewData("order", $order);
return $renderer->renderTemplate($this->orderCanceledSmsTemplate, $this->getViewData());
}
/**
* Templating instance getter
*
@ -75,7 +131,8 @@ class EmailCore extends EmailCore_parent
*/
protected function d3GetTplRenderer()
{
$bridge = \OxidEsales\EshopCommunity\Internal\Container\ContainerFactory::getInstance()->getContainer()->get(TemplateRendererBridgeInterface::class);
$bridge = \OxidEsales\EshopCommunity\Internal\Container\ContainerFactory::getInstance()->getContainer()
->get(TemplateRendererBridgeInterface::class);
$bridge->setEngine($this->_getSmarty());
return $bridge->getTemplateRenderer();

View File

@ -19,7 +19,7 @@ $aModule = [
'id' => $sModuleId,
'title' => $sD3Logo . ' Linkmobility',
'description' => [
'de' => 'Anbiundung an die Linkmobility API <ul><li>Nachrichtenversand per SMS</li></ul>',
'de' => 'Anbindung an die Linkmobility API <ul><li>Nachrichtenversand per SMS</li></ul>',
'en' => '',
],
'thumbnail' => 'picture.png',
@ -29,8 +29,8 @@ $aModule = [
'url' => 'https://www.oxidmodule.com/',
'extend' => [
\OxidEsales\Eshop\Application\Controller\StartController::class => \D3\Linkmobility4OXID\Modules\Application\Controller\StartController::class,
\OxidEsales\Eshop\Application\Controller\ContactController::class => \D3\Linkmobility4OXID\Modules\Application\Controller\ContactController::class,
Email::class => EmailCore::class
Email::class => EmailCore::class,
\OxidEsales\Eshop\Application\Model\Order::class => \D3\Linkmobility4OXID\Modules\Application\Model\OrderModel::class
],
'controllers' => [
'd3linkmobility_user' => AdminUser::class,
@ -40,6 +40,8 @@ $aModule = [
'd3adminuser.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl',
'd3adminorder.tpl' => 'd3/linkmobility/Application/views/admin/tpl/adminuser.tpl',
'd3sms_ordercust.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/order_cust.tpl',
'd3sms_sendednow.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/sendednow.tpl',
'd3sms_ordercanceled.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/ordercanceled.tpl',
],
'events' => [],
'settings' => [