diff --git a/src/Application/Controller/Admin/AdminOrder.php b/src/Application/Controller/Admin/AdminOrder.php index 1e32319..0b0ace8 100644 --- a/src/Application/Controller/Admin/AdminOrder.php +++ b/src/Application/Controller/Admin/AdminOrder.php @@ -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' ) ); } diff --git a/src/Application/Model/Exceptions/successfullySentException.php b/src/Application/Model/Exceptions/successfullySentException.php new file mode 100644 index 0000000..78874fd --- /dev/null +++ b/src/Application/Model/Exceptions/successfullySentException.php @@ -0,0 +1,34 @@ + + * @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 ); + } +} \ No newline at end of file diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index c3daf1f..f4c2112 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -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' ]; } } \ No newline at end of file diff --git a/src/Application/Model/Sms.php b/src/Application/Model/Sms.php index 7ac2a0f..8165ed4 100644 --- a/src/Application/Model/Sms.php +++ b/src/Application/Model/Sms.php @@ -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; diff --git a/src/Application/views/admin/de/d3Linkmobility_lang.php b/src/Application/views/admin/de/d3Linkmobility_lang.php index 6035d1a..3b31b24 100644 --- a/src/Application/views/admin/de/d3Linkmobility_lang.php +++ b/src/Application/views/admin/de/d3Linkmobility_lang.php @@ -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' ]; diff --git a/src/Application/views/tpl/SMS/order_cust.tpl b/src/Application/views/tpl/SMS/order_cust.tpl index cd10b59..8203453 100644 --- a/src/Application/views/tpl/SMS/order_cust.tpl +++ b/src/Application/views/tpl/SMS/order_cust.tpl @@ -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"}] +*}] \ No newline at end of file diff --git a/src/Application/views/tpl/SMS/ordercanceled.tpl b/src/Application/views/tpl/SMS/ordercanceled.tpl new file mode 100644 index 0000000..2a72918 --- /dev/null +++ b/src/Application/views/tpl/SMS/ordercanceled.tpl @@ -0,0 +1 @@ +Ihre Bestellung wurde storniert. \ No newline at end of file diff --git a/src/Application/views/tpl/SMS/sendednow.tpl b/src/Application/views/tpl/SMS/sendednow.tpl new file mode 100644 index 0000000..4ad0390 --- /dev/null +++ b/src/Application/views/tpl/SMS/sendednow.tpl @@ -0,0 +1 @@ +Ihre Bestellung wurde eben versendet. \ No newline at end of file diff --git a/src/IntelliSenseHelper.php b/src/IntelliSenseHelper.php index 0a857bd..8ca12a0 100644 --- a/src/IntelliSenseHelper.php +++ b/src/IntelliSenseHelper.php @@ -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; diff --git a/src/Modules/Application/Controller/ContactController.php b/src/Modules/Application/Controller/ContactController.php deleted file mode 100644 index a13214c..0000000 --- a/src/Modules/Application/Controller/ContactController.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @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; - } - } -} \ No newline at end of file diff --git a/src/Modules/Application/Controller/StartController.php b/src/Modules/Application/Controller/StartController.php index 3aa1b11..f639efc 100644 --- a/src/Modules/Application/Controller/StartController.php +++ b/src/Modules/Application/Controller/StartController.php @@ -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(); } } \ No newline at end of file diff --git a/src/Modules/Application/Model/OrderModel.php b/src/Modules/Application/Model/OrderModel.php new file mode 100644 index 0000000..815272a --- /dev/null +++ b/src/Modules/Application/Model/OrderModel.php @@ -0,0 +1,32 @@ + + * @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); + } + } +} \ No newline at end of file diff --git a/src/Modules/Core/EmailCore.php b/src/Modules/Core/EmailCore.php index ce79fc2..ee4cb44 100644 --- a/src/Modules/Core/EmailCore.php +++ b/src/Modules/Core/EmailCore.php @@ -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(); diff --git a/src/metadata.php b/src/metadata.php index 8a0806b..b0a3251 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -19,7 +19,7 @@ $aModule = [ 'id' => $sModuleId, 'title' => $sD3Logo . ' Linkmobility', 'description' => [ - 'de' => 'Anbiundung an die Linkmobility API