2022-08-05 00:43:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\Linkmobility4Ordermanager\Application\Model;
|
|
|
|
|
2022-08-07 00:45:00 +02:00
|
|
|
use D3\Linkmobility4Ordermanager\Application\Model\Exceptions\emptyMesageException;
|
|
|
|
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
|
2022-08-05 00:43:08 +02:00
|
|
|
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
|
|
|
|
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
|
|
|
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
2022-08-07 00:45:00 +02:00
|
|
|
use D3\ModCfg\Application\Model\d3str;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
|
2022-08-05 00:43:08 +02:00
|
|
|
use D3\Ordermanager\Application\Model\d3ordermanager;
|
2022-08-07 00:45:00 +02:00
|
|
|
use D3\Ordermanager\Application\Model\d3ordermanager as Manager;
|
|
|
|
use D3\Ordermanager\Application\Model\d3ordermanager_renderererrorhandler;
|
|
|
|
use D3\OxidServiceBridges\Internal\Framework\Module\Path\ModulePathResolverBridgeInterface;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Basket;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Content;
|
2022-08-05 00:43:08 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
2022-08-07 00:45:00 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Payment;
|
|
|
|
use OxidEsales\Eshop\Core\Email;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\ArticleException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\ArticleInputException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\EshopCommunity\Core\Controller\BaseController;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateEngineInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
|
2022-08-05 00:43:08 +02:00
|
|
|
|
|
|
|
class d3linkmobility_ordermanager_sender
|
|
|
|
{
|
|
|
|
/** @var d3ordermanager */
|
|
|
|
protected $manager;
|
|
|
|
|
|
|
|
/** @var Order */
|
|
|
|
protected $item;
|
|
|
|
|
2022-08-07 00:45:00 +02:00
|
|
|
/**
|
|
|
|
* @param Manager $manager
|
|
|
|
* @param Order $item
|
|
|
|
* @return void
|
|
|
|
* @throws ArticleException
|
|
|
|
* @throws ArticleInputException
|
|
|
|
* @throws noRecipientFoundException
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws emptyMesageException
|
|
|
|
*/
|
2022-08-05 00:43:08 +02:00
|
|
|
public function sendOrderManagerSms(d3ordermanager $manager, Order $item)
|
|
|
|
{
|
|
|
|
$this->setManager($manager);
|
|
|
|
$this->setItem($item);
|
2022-08-07 00:45:00 +02:00
|
|
|
dumpvar(__METHOD__.__LINE__.PHP_EOL);
|
|
|
|
dumpvar($this->getMessageBody());
|
|
|
|
dumpvar($this->getRecipients());
|
|
|
|
die();
|
2022-08-05 00:43:08 +02:00
|
|
|
$sms = oxNew(Sms::class, $this->getMessageBody());
|
|
|
|
$sms->sendCustomRecipientMessage($this->getRecipients());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
2022-08-07 00:45:00 +02:00
|
|
|
* @throws ArticleException
|
|
|
|
* @throws ArticleInputException
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws emptyMesageException
|
2022-08-05 00:43:08 +02:00
|
|
|
*/
|
|
|
|
protected function getMessageBody(): string
|
|
|
|
{
|
2022-08-07 00:45:00 +02:00
|
|
|
$oManager = $this->getManager();
|
|
|
|
|
|
|
|
$viewData = [];
|
|
|
|
|
|
|
|
$blTplFromAdmin = $oManager->getValue('sLinkMobilityMessageFromTheme') == 'admin';
|
|
|
|
|
|
|
|
$oConfig = Registry::getConfig();
|
|
|
|
$oConfig->setAdminMode($blTplFromAdmin);
|
|
|
|
|
|
|
|
/** @var TemplateRendererInterface $renderer */
|
|
|
|
$renderer = ContainerFactory::getInstance()->getContainer()
|
|
|
|
->get(TemplateRendererBridgeInterface::class)
|
|
|
|
->getTemplateRenderer();
|
|
|
|
$templateEngine = $renderer->getTemplateEngine();
|
|
|
|
|
|
|
|
/** @var $oBasket Basket */
|
|
|
|
$oBasket = $oManager->getCurrentItem()->d3getOrderBasket4OrderManager($oManager);
|
|
|
|
|
|
|
|
$oPayment = oxNew(Payment::class);
|
|
|
|
$oPayment->loadInLang($oManager->getCurrentItem()->getFieldData('oxlang'), $oBasket->getPaymentId());
|
|
|
|
|
|
|
|
$oManager->getCurrentItem()->d3setBasket4OrderManager($oBasket);
|
|
|
|
$oManager->getCurrentItem()->d3setPayment4OrderManager($oPayment);
|
|
|
|
|
|
|
|
$oShop = Registry::getConfig()->getActiveShop();
|
|
|
|
|
|
|
|
$viewData["oShop"] = $oShop;
|
|
|
|
$viewData["oViewConf"] = (oxNew(BaseController::class))->getViewConfig();
|
|
|
|
$viewData["oOrder"] = $oManager->getCurrentItem();
|
|
|
|
$viewData["oUser"] = $oManager->getCurrentItem()->getOrderUser();
|
|
|
|
$viewData["shopTemplateDir"] = $oConfig->getTemplateDir(false);
|
|
|
|
$viewData["charset"] = Registry::getLang()->translateString("charset");
|
|
|
|
|
|
|
|
$viewData["shop"] = $oShop;
|
|
|
|
$viewData["order"] = $oManager->getCurrentItem();
|
|
|
|
$viewData["user"] = $oManager->getCurrentItem()->getOrderUser();
|
|
|
|
$viewData["payment"] = $oPayment;
|
|
|
|
$viewData["oDelSet"] = $oManager->getCurrentItem()->getDelSet();
|
|
|
|
$viewData["currency"] = $oManager->getCurrentItem()->getOrderCurrency();
|
|
|
|
$viewData["basket"] = $oBasket;
|
|
|
|
$viewData["oEmailView"] = oxNew(Email::class);
|
|
|
|
|
|
|
|
// ToDo: check in TWIG and change to a generic solution (e.g. path names in template name)
|
|
|
|
// Smarty only
|
|
|
|
if (method_exists($templateEngine, '__set')) {
|
|
|
|
$templateEngine->__set( 'template_dir', $this->getTemplateDir4OrderManager( $oManager ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($viewData as $id => $value) {
|
|
|
|
$templateEngine->addGlobal($id, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = $this->_d3GenerateOrderManagerMessageContent($templateEngine);
|
|
|
|
$oConfig->setAdminMode(true);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param TemplateEngineInterface $templateEngine
|
|
|
|
* @return string
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws emptyMesageException
|
|
|
|
*/
|
|
|
|
protected function _d3GenerateOrderManagerMessageContent(TemplateEngineInterface $templateEngine)
|
|
|
|
{
|
|
|
|
$iOrderLangId = $this->getManager()->getCurrentItem()->getFieldData('oxlang');
|
|
|
|
$oLang = Registry::getLang();
|
|
|
|
$iCurrentTplLang = $oLang->getTplLanguage();
|
|
|
|
$iCurrentBaseLang = $oLang->getBaseLanguage();
|
|
|
|
$oLang->setTplLanguage($iOrderLangId);
|
|
|
|
$oLang->setBaseLanguage($iOrderLangId);
|
|
|
|
|
|
|
|
$iCurrentCurrency = Registry::getConfig()->getShopCurrency();
|
|
|
|
$iOrderCurr = $this->getManager()->getCurrentItem()->getOrderCurrency()->id;
|
|
|
|
Registry::getConfig()->setActShopCurrency($iOrderCurr);
|
|
|
|
|
|
|
|
set_error_handler(
|
|
|
|
[d3GetModCfgDIC()->get(d3ordermanager_renderererrorhandler::class), 'd3HandleTemplateEngineErrors']
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->getManager()->getValue('sLinkMobilityMessageFromSource') == 'cms') {
|
|
|
|
$oUtilsView = Registry::getUtilsView();
|
|
|
|
$oContent = oxNew(Content::class);
|
|
|
|
$oContent->loadInLang($iOrderLangId, $this->getManager()->getValue('sLinkMobilityMessageFromContentname'));
|
|
|
|
|
|
|
|
$content = $oUtilsView->getRenderedContent(
|
|
|
|
$oContent->getFieldData('oxcontent'),
|
|
|
|
$templateEngine->getGlobals(),
|
|
|
|
$oContent->getId() . 'oxcontent'
|
|
|
|
);
|
|
|
|
} elseif ($this->getManager()->getValue('sLinkMobilityMessageFromSource') == 'template') {
|
|
|
|
$content = $templateEngine->render($this->getManager()->getValue('sLinkMobilityMessageFromTemplatename'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === is_string($content) || false === (bool) strlen($content)) {
|
|
|
|
throw oxNew(emptyMesageException::class, 'message content is empty', $this->getManager()->getFieldData('oxtitle'));
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
$oLang->setTplLanguage($iCurrentTplLang);
|
|
|
|
$oLang->setBaseLanguage($iCurrentBaseLang);
|
|
|
|
Registry::getConfig()->setActShopCurrency($iCurrentCurrency);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Manager $oManager
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTemplateDir4OrderManager( Manager $oManager ): string
|
|
|
|
{
|
|
|
|
if ($oManager->getValue('sLinkMobilityMessageFromTheme') == 'module') {
|
|
|
|
$sModuleId = $oManager->getValue('sLinkMobilityMessageFromModulePath');
|
|
|
|
/** @var ModulePathResolverBridgeInterface $pathResolverBridge */
|
|
|
|
$pathResolverBridge = ContainerFactory::getInstance()->getContainer()->get(ModulePathResolverBridgeInterface::class);
|
|
|
|
$sModulePath = $pathResolverBridge->getFullModulePathFromConfiguration(
|
|
|
|
$sModuleId,
|
|
|
|
Registry::getConfig()->getShopId()
|
|
|
|
);
|
|
|
|
$sPath = (oxNew(d3str::class))->untrailingslashit($sModulePath);
|
|
|
|
} else {
|
|
|
|
$blAdmin = $oManager->getValue('sLinkMobilityMessageFromTheme') == 'admin';
|
|
|
|
$sPath = Registry::getConfig()->getTemplateDir($blAdmin);
|
|
|
|
}
|
|
|
|
return $sPath;
|
2022-08-05 00:43:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
2022-08-07 00:45:00 +02:00
|
|
|
* @throws noRecipientFoundException
|
2022-08-05 00:43:08 +02:00
|
|
|
*/
|
|
|
|
protected function getRecipients(): array
|
|
|
|
{
|
|
|
|
$recipients = [];
|
2022-08-07 00:45:00 +02:00
|
|
|
if ((bool) $this->getManager()->getValue('blLinkMobilityMessageToCustomer')) {
|
|
|
|
$recipients[] = (oxNew(OrderRecipients::class, $this->getItem()))->getSmsRecipient();
|
2022-08-05 00:43:08 +02:00
|
|
|
}
|
2022-08-07 00:45:00 +02:00
|
|
|
if ((bool) $this->getManager()->getValue('blLinkMobilityMessageToCustom') &&
|
|
|
|
strlen(trim($this->getManager()->getValue('sLinkMobilityMessageToCustomAddress')))
|
|
|
|
) {
|
|
|
|
foreach ($this->extractCustomAddresses() as $phoneNumber => $countryId) {
|
|
|
|
$recipients[] = oxNew(Recipient::class, $phoneNumber, $countryId);
|
|
|
|
}
|
2022-08-05 00:43:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $recipients;
|
|
|
|
}
|
|
|
|
|
2022-08-07 00:45:00 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function extractCustomAddresses(): array
|
|
|
|
{
|
|
|
|
$addresses = [];
|
|
|
|
$customAddresses = trim($this->getManager()->getValue('sLinkMobilityMessageToCustomAddress'));
|
|
|
|
|
|
|
|
if (strlen($customAddresses)) {
|
|
|
|
foreach (explode(';', $customAddresses) as $addressGroups) {
|
|
|
|
list($phoneNumber, $countryId) = explode('@', trim($addressGroups));
|
|
|
|
$addresses[trim($phoneNumber)] = trim($countryId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $addresses;
|
|
|
|
}
|
|
|
|
|
2022-08-05 00:43:08 +02:00
|
|
|
/**
|
|
|
|
* @return Order
|
|
|
|
*/
|
|
|
|
public function getItem(): Order
|
|
|
|
{
|
|
|
|
return $this->item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Order $item
|
|
|
|
*/
|
|
|
|
public function setItem(Order $item): void
|
|
|
|
{
|
|
|
|
$this->item = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param d3ordermanager $manager
|
|
|
|
*/
|
|
|
|
public function setManager(d3ordermanager $manager): void
|
|
|
|
{
|
|
|
|
$this->manager = $manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3ordermanager
|
|
|
|
*/
|
|
|
|
public function getManager(): d3ordermanager
|
|
|
|
{
|
|
|
|
return $this->manager;
|
|
|
|
}
|
|
|
|
}
|