2018-01-25 11:30:17 +01:00
|
|
|
<?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 © D³ Data Development, Thomas Dartsch
|
2018-02-23 12:30:57 +01:00
|
|
|
* @author D³ Data Development - Daniel Seifert <info@shopmodule.com>
|
2018-01-25 11:30:17 +01:00
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
2019-10-16 14:59:57 +02:00
|
|
|
namespace D3\Devhelper\Modules\Core;
|
|
|
|
|
2024-07-03 09:32:01 +02:00
|
|
|
use D3\Devhelper\Application\Model\Exception\UnauthorisedException;
|
2019-10-16 14:59:57 +02:00
|
|
|
use D3\Devhelper\Modules\Application\Model as ModuleModel;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2020-11-11 23:59:40 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
2020-11-11 22:29:10 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
|
2019-10-16 14:59:57 +02:00
|
|
|
|
2018-01-25 11:30:17 +01:00
|
|
|
class d3_dev_oxemail extends d3_dev_oxemail_parent
|
|
|
|
{
|
|
|
|
/**
|
2018-02-23 12:30:57 +01:00
|
|
|
* @param ModuleModel\d3_dev_oxorder $oOrder
|
2018-01-25 11:30:17 +01:00
|
|
|
* @param $sType
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public function d3GetOrderMailContent($oOrder, $sType)
|
|
|
|
{
|
2018-02-23 12:30:57 +01:00
|
|
|
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
|
2024-07-03 09:32:01 +02:00
|
|
|
throw oxNew(UnauthorisedException::class);
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (strtolower($sType)) {
|
|
|
|
case 'owner_html':
|
|
|
|
$sTpl = $this->_sOrderOwnerTemplate;
|
|
|
|
break;
|
|
|
|
case 'owner_plain':
|
|
|
|
$sTpl = $this->_sOrderOwnerPlainTemplate;
|
|
|
|
break;
|
|
|
|
case 'user_plain':
|
|
|
|
$sTpl = $this->_sOrderUserPlainTemplate;
|
|
|
|
break;
|
|
|
|
case 'user_html':
|
|
|
|
default:
|
|
|
|
$sTpl = $this->_sOrderUserTemplate;
|
|
|
|
}
|
|
|
|
|
2020-11-11 22:29:10 +01:00
|
|
|
$myConfig = Registry::getConfig();
|
2018-01-25 11:30:17 +01:00
|
|
|
|
2024-07-02 17:03:38 +02:00
|
|
|
$oShop = $this->getShop();
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
// cleanup
|
2024-07-02 17:03:38 +02:00
|
|
|
$this->clearMailer();
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
// add user defined stuff if there is any
|
2024-07-02 17:03:38 +02:00
|
|
|
$oOrder = $this->addUserInfoOrderEMail($oOrder);
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
$oUser = $oOrder->getOrderUser();
|
|
|
|
$this->setUser($oUser);
|
|
|
|
|
|
|
|
// send confirmation to shop owner
|
|
|
|
// send not pretending from order user, as different email domain rise spam filters
|
2018-02-23 12:30:57 +01:00
|
|
|
$this->setFrom($oShop->getFieldData('oxowneremail'));
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
$oLang = Registry::getLang();
|
|
|
|
$iOrderLang = $oLang->getObjectTplLanguage();
|
|
|
|
|
|
|
|
// if running shop language is different from admin lang. set in config
|
|
|
|
// we have to load shop in config language
|
|
|
|
if ($oShop->getLanguage() != $iOrderLang) {
|
2024-07-02 17:03:38 +02:00
|
|
|
$oShop = $this->getShop($iOrderLang);
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->setSmtp($oShop);
|
|
|
|
|
|
|
|
// create messages
|
|
|
|
$this->setViewData("order", $oOrder);
|
|
|
|
|
|
|
|
// Process view data array through oxoutput processor
|
2024-07-02 17:03:38 +02:00
|
|
|
$this->processViewArray();
|
2018-01-25 11:30:17 +01:00
|
|
|
|
2020-11-11 23:59:40 +01:00
|
|
|
$renderer = $this->getRenderer();
|
2024-07-02 17:03:38 +02:00
|
|
|
|
|
|
|
$templateExtension = ContainerFactory::getInstance()->getContainer()
|
|
|
|
->getParameter('oxid_esales.templating.engine_template_extension');
|
|
|
|
$sTpl .= '.'.$templateExtension;
|
|
|
|
|
2020-11-11 23:59:40 +01:00
|
|
|
return $renderer->renderTemplate($myConfig->getTemplatePath($sTpl, false), $this->getViewData());
|
2020-11-11 22:29:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-12 08:50:36 +01:00
|
|
|
* required because private in Email class
|
2020-11-11 22:29:10 +01:00
|
|
|
* Templating instance getter
|
|
|
|
*
|
|
|
|
* @return TemplateRendererInterface
|
|
|
|
*/
|
|
|
|
protected function getRenderer()
|
|
|
|
{
|
2020-11-11 23:59:40 +01:00
|
|
|
$bridge = ContainerFactory::getInstance()->getContainer()
|
2020-11-11 22:29:10 +01:00
|
|
|
->get(TemplateRendererBridgeInterface::class);
|
2024-07-02 17:03:38 +02:00
|
|
|
// $bridge->setEngine($this->getSmarty());
|
2020-11-11 22:29:10 +01:00
|
|
|
|
|
|
|
return $bridge->getTemplateRenderer();
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 23:59:40 +01:00
|
|
|
/**
|
|
|
|
* @param $aRecInfo
|
|
|
|
* @param array $aCc
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function d3ChangeRecipient($aRecInfo, array $aCc): array
|
|
|
|
{
|
|
|
|
if (($sNewRecipient = $this->getNewRecipient($aRecInfo[0]))
|
|
|
|
&& $sNewRecipient != $aRecInfo[0]
|
|
|
|
) {
|
|
|
|
$aRecInfo[1] = $aRecInfo[1] . " (" . $aRecInfo[0] . ")";
|
|
|
|
$aRecInfo[0] = $sNewRecipient;
|
|
|
|
$aCc[] = $aRecInfo;
|
|
|
|
} elseif (($sNewRecipient = $this->getNewRecipient($aRecInfo[0]))) {
|
|
|
|
$aCc[] = $aRecInfo;
|
|
|
|
}
|
|
|
|
return $aCc;
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 23:59:40 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
* @throws StandardException
|
|
|
|
*/
|
|
|
|
protected function sendMail()
|
|
|
|
{
|
|
|
|
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
|
|
|
|
return parent::sendMail();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->d3clearRecipients();
|
|
|
|
$this->d3clearReplies();
|
|
|
|
$this->d3clearReplyTo();
|
|
|
|
$this->d3clearCC();
|
|
|
|
$this->d3clearBCC();
|
|
|
|
|
|
|
|
if (count($this->getRecipient())) {
|
|
|
|
return parent::sendMail();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-25 11:30:17 +01:00
|
|
|
public function d3clearRecipients()
|
|
|
|
{
|
|
|
|
$aRecipients = array();
|
|
|
|
if (is_array($this->_aRecipients) && count($this->_aRecipients)) {
|
|
|
|
foreach ($this->_aRecipients as $aRecInfo) {
|
2020-11-11 23:59:40 +01:00
|
|
|
$aRecipients = $this->d3ChangeRecipient($aRecInfo, $aRecipients);
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->_aRecipients = $aRecipients;
|
|
|
|
}
|
|
|
|
|
2019-10-16 14:59:57 +02:00
|
|
|
public function d3clearReplies()
|
|
|
|
{
|
|
|
|
$aRecipients = array();
|
|
|
|
if (is_array($this->_aReplies) && count($this->_aReplies)) {
|
|
|
|
foreach ($this->_aReplies as $aRecInfo) {
|
2020-11-11 23:59:40 +01:00
|
|
|
$aRecipients = $this->d3ChangeRecipient($aRecInfo, $aRecipients);
|
2019-10-16 14:59:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->_aReplies = $aRecipients;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function d3clearReplyTo()
|
|
|
|
{
|
|
|
|
$aRecipients = array();
|
|
|
|
if (is_array($this->ReplyTo) && count($this->ReplyTo)) {
|
|
|
|
foreach ($this->ReplyTo as $aRecInfo) {
|
2020-11-11 23:59:40 +01:00
|
|
|
$aRecipients = $this->d3ChangeRecipient($aRecInfo, $aRecipients);
|
2019-10-16 14:59:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->ReplyTo = $aRecipients;
|
|
|
|
}
|
|
|
|
|
2018-01-25 11:30:17 +01:00
|
|
|
public function d3clearCC()
|
|
|
|
{
|
|
|
|
$aCc = array();
|
|
|
|
if (is_array($this->cc) && count($this->cc)) {
|
|
|
|
foreach ($this->cc as $aRecInfo) {
|
2020-11-11 23:59:40 +01:00
|
|
|
$aCc = $this->d3ChangeRecipient($aRecInfo, $aCc);
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->cc = $aCc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function d3clearBCC()
|
|
|
|
{
|
|
|
|
$aCc = array();
|
|
|
|
if (is_array($this->bcc) && count($this->bcc)) {
|
|
|
|
foreach ($this->bcc as $aRecInfo) {
|
2020-11-11 23:59:40 +01:00
|
|
|
$aCc = $this->d3ChangeRecipient($aRecInfo, $aCc);
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->bcc = $aCc;
|
|
|
|
}
|
|
|
|
|
2019-10-16 14:59:57 +02:00
|
|
|
/**
|
|
|
|
* @param $sMailAddress
|
|
|
|
*
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
2018-01-25 11:30:17 +01:00
|
|
|
public function getNewRecipient($sMailAddress)
|
|
|
|
{
|
2020-11-11 22:29:10 +01:00
|
|
|
if (Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_BLOCKMAIL)) {
|
2018-01-25 11:30:17 +01:00
|
|
|
return false;
|
2020-11-11 22:29:10 +01:00
|
|
|
} elseif (Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_REDIRECTMAIL)) {
|
|
|
|
return trim(Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_REDIRECTMAIL));
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $sMailAddress;
|
|
|
|
}
|
|
|
|
}
|