This commit is contained in:
Daniel Seifert 2022-08-05 15:47:14 +02:00
parent 7219eead2d
commit a0b2dc4eb6
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
3 changed files with 119 additions and 6 deletions

View File

@ -25,6 +25,7 @@ use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\DatabaseException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Language;
class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
{
@ -80,7 +81,7 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
startProfile(__METHOD__);
/** @var Language $oLang */
$oLang = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Language::class);
$oLang = oxNew(Language::class);
$this->getManager()->getRemarkHandler()->addNote(
sprintf(
@ -115,6 +116,21 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
return implode(', ', $aMailDesc);
}
/**
* @param bool $blExpected
*
* @return bool
*/
protected function hasRequiredValuesNoSource(bool $blExpected): bool
{
$source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' );
$return = strlen(trim($source)) &&
in_array(trim($source), [self::SOURCE_CMS, self::SOURCE_TEMPLATE]);
return $blExpected ? $return : false === $return;
}
/**
* @param bool $blExpected
*
@ -196,7 +212,7 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
/**
* @return d3linkmobility_ordermanager_sender
*/
public function getSendClass()
public function getSendClass(): d3linkmobility_ordermanager_sender
{
/** @var d3linkmobility_ordermanager_sender $mailer */
$sender = oxNew(d3linkmobility_ordermanager_sender::class);

View File

@ -19,7 +19,15 @@ use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\Ordermanager\Application\Model\d3ordermanager;
use D3\Ordermanager\Application\Model\d3ordermanager as Manager;
use D3\OxidServiceBridges\Internal\Framework\Module\Path\ModulePathResolverBridgeInterface;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
class d3linkmobility_ordermanager_sender
{
@ -43,7 +51,90 @@ class d3linkmobility_ordermanager_sender
*/
protected function getMessageBody(): string
{
return '';
$oManager = $this->getManager();
$aContent = array();
$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"] = $this->getViewConfig();
$viewData["oOrder"] = $oManager->getCurrentItem();
$viewData["oUser"] = $oManager->getCurrentItem()->getOrderUser();
$viewData["shopTemplateDir"] = $this->d3GetOrderManagerConfigObject()->getTemplateDir(false);
$viewData["charset"] = $this->d3GetOrderManagerLanguageObject()->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;
// 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);
}
if (false == $this->d3GetOrderManagerSet()->getLicenseConfigData('blUseMailSendOnly', 0)) {
$templateEngine = $this->d3SendMailHook($templateEngine);
}
$aContent = $this->_d3GenerateOrderManagerMailContent($aContent, $templateEngine);
$oConfig->setAdminMode(true);
return $aContent;
}
/**
* @param Manager $oManager
*
* @return string
* @throws Exception
*/
public function getTemplateDir4OrderManager( Manager $oManager ): string
{
if ($oManager->getValue('sSendMailFromTheme') == 'module') {
$sModuleId = $oManager->getValue('sSendMailFromModulePath');
/** @var ModulePathResolverBridgeInterface $pathResolverBridge */
$pathResolverBridge = $this->d3getOrderManagerDIContainer()->get(ModulePathResolverBridgeInterface::class);
$sModulePath = $pathResolverBridge->getFullModulePathFromConfiguration(
$sModuleId,
Registry::getConfig()->getShopId()
);
$sPath = $this->getD3OrderManagerStrObject()->untrailingslashit($sModulePath);
} else {
$blAdmin = $oManager->getValue('sSendMailFromTheme') == 'admin';
$sPath = $this->d3GetOrderManagerConfigObject()->getTemplateDir($blAdmin);
}
return $sPath;
}
/**

View File

@ -22,8 +22,8 @@ $aLang = array(
'D3_LINKMOBILITY_ORDERMANAGER_ACTION' => 'Mobile Messages (über LINK Mobility) senden',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings' => 'Der Nachrichtenempfänger wird aus den Kundendaten an den Bestellungen ermittelt.',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings_DESC' => 'Welche Daten der Bestellung hierfür verwendet werden, setzen Sie in den Einstellungen des LINK Mobility Moduls unter "Erweiterungen -> Module -> Einstell.".',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings' => '',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ToUseLMSettings_DESC' => '',
'D3_ORDERMANAGER_ACTION_MAILSEND' => 'E-Mail senden',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROM1' => '',
@ -38,6 +38,12 @@ $aLang = array(
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMTEMPLATE_DESC' => 'Geben Sie den vollständigen Templatenamen (inkl. Ordner ab tpl-Ordner und Dateiendung) an',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS' => 'aus Kundeninformation',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROMCMS_SOURCE' => 'CMS-Eintrag',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_FROM2' => 'an',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_TOCUSTOMER' => 'Kunde',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_TOCUSTOMER_DESC' => 'Der Nachrichtenempfänger wird aus den Kundendaten an den Bestellungen ermittelt. Welche Daten der Bestellung hierfür verwendet werden, setzen Sie in den Einstellungen des LINK Mobility Moduls unter "Erweiterungen -> Module -> Einstell.".',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_TOOWNER' => 'Shopbetreiber',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_TOMAIL' => 'folgende Mobilfunknummer(n)',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_TOMAIL_DESC' => '<p>Geben Sie in dem Eingabefeld eine oder mehrere gültige Mobilfunknummern und deren Herkunftsland in folgendem Format an und aktivieren Sie die Option mit dem Häkchenfeld:</p><code>017112345678@DE; 015212345678@AT</code>',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDSOURCE' => 'keine gültige Inhaltsquelle gesetzt',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDTPL' => 'keine gültigen Templatedaten gesetzt',