Ordermanager/src/Modules/Application/Model/d3_oxemail_ordermanager.php

921 regels
31 KiB
PHP

2017-12-20 13:43:20 +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 (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\Ordermanager\Modules\Application\Model;
2018-01-11 11:45:22 +01:00
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
2019-05-15 11:31:18 +02:00
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
2018-01-11 11:45:22 +01:00
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
2019-05-15 11:31:18 +02:00
use D3\ModCfg\Application\Model\Log\d3LogInterface;
2020-08-20 09:35:38 +02:00
use D3\Ordermanager\Application\Model\Actions\d3ordermanager_action_generatepdf;
use D3\Ordermanager\Application\Model\Actions\d3ordermanager_action_getpdfdocuments;
2017-12-20 13:43:20 +01:00
use D3\Ordermanager\Application\Model\d3ordermanager;
2019-10-22 08:41:49 +02:00
use D3\Ordermanager\Application\Model\d3ordermanager_conf;
2017-12-20 13:43:20 +01:00
use D3\Ordermanager\Application\Model\d3ordermanager_pdfhandler;
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
use D3\ModCfg\Application\Model\Shopcompatibility\d3ShopCompatibilityAdapterHandler;
use D3\ModCfg\Application\Model\d3str;
2021-03-16 10:10:19 +01:00
use D3\Ordermanager\Application\Model\d3ordermanager_renderererrorhandler;
use D3\Ordermanager\Application\Model\Exceptions\d3ordermanager_smartyException;
use D3\Ordermanager\Application\Model\Exceptions\d3ordermanager_templaterendererExceptionInterface;
2020-08-20 09:35:38 +02:00
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
2018-01-11 11:45:22 +01:00
use Doctrine\DBAL\DBALException;
2019-05-15 11:31:18 +02:00
use Exception;
2019-12-10 11:40:17 +01:00
use Html2Text\Html2Text;
2020-08-20 09:35:38 +02:00
use League\Flysystem\FileExistsException;
2017-12-20 13:43:20 +01:00
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Application\Model\Content;
2019-05-15 11:31:18 +02:00
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\ArticleException;
use OxidEsales\Eshop\Core\Exception\ArticleInputException;
2018-01-11 11:45:22 +01:00
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\DatabaseException;
2019-05-15 11:31:18 +02:00
use OxidEsales\Eshop\Core\Exception\NoArticleException;
2018-01-11 11:45:22 +01:00
use OxidEsales\Eshop\Core\Exception\StandardException;
2019-05-15 11:31:18 +02:00
use OxidEsales\Eshop\Core\Language;
2017-12-20 13:43:20 +01:00
use OxidEsales\Eshop\Core\Module\Module;
2020-04-21 18:20:54 +02:00
use OxidEsales\Eshop\Core\Registry;
2017-12-20 13:43:20 +01:00
use OxidEsales\Eshop\Core\UtilsView;
2021-03-16 10:10:19 +01:00
use OxidEsales\EshopCommunity\Internal\Application\ContainerFactory;
use Psr\Container\ContainerInterface;
2019-05-15 11:31:18 +02:00
use Smarty;
2017-12-20 13:43:20 +01:00
class d3_oxemail_ordermanager extends d3_oxemail_ordermanager_parent
{
2019-05-15 11:31:18 +02:00
private $_sModId = 'd3_ordermanager';
2017-12-20 13:43:20 +01:00
protected $_sOrderManagerInfoTemplate = 'd3ordermanager_info_html.tpl';
protected $_sOrderManagerInfoPlainTemplate = 'd3ordermanager_info_plain.tpl';
/** @var d3ordermanager */
public $oOrderManager;
/**
2019-05-15 11:31:18 +02:00
* d3_oxemail_ordermanager constructor.
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function __construct()
{
2019-05-15 11:31:18 +02:00
d3GetModCfgDIC()->setParameter('d3.ordermanager.modcfgid', $this->_sModId);
/** @var Config _oConfig */
$this->_oConfig = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Config::class);
2017-12-20 13:43:20 +01:00
parent::__construct();
}
/**
* @param array $aOrderManagerNotes
2019-05-15 11:31:18 +02:00
*
2017-12-20 13:43:20 +01:00
* @return bool
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function d3sendOrderManagerEmail($aOrderManagerNotes)
{
startProfile(__METHOD__);
$oShop = $this->_getShop();
2019-07-09 10:27:20 +02:00
/** @var Smarty $oSmarty */
2017-12-20 13:43:20 +01:00
$oSmarty = $this->_getSmarty();
2019-05-15 11:31:18 +02:00
/** @var Config $config */
$config = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Config::class);
2017-12-20 13:43:20 +01:00
$this->_setMailParams($oShop);
$this->setViewData("aNotes", $aOrderManagerNotes);
2019-05-15 11:31:18 +02:00
$this->setViewData("shopTemplateDir", $config->getTemplateDir(false));
2017-12-20 13:43:20 +01:00
$this->setViewData("oShop", $oShop);
2019-05-15 11:31:18 +02:00
$oSmarty->template_dir = $config->getTemplateDir(false);
2017-12-20 13:43:20 +01:00
$this->_processViewArray();
2021-03-16 10:10:19 +01:00
set_error_handler(
[d3GetModCfgDIC()->get(d3ordermanager_renderererrorhandler::class), 'd3HandleTemplateEngineErrors']
);
$this->d3OMsetBody($oSmarty->fetch($this->_sOrderManagerInfoTemplate));
$this->d3OMsetAltBody($oSmarty->fetch($this->_sOrderManagerInfoPlainTemplate));
restore_error_handler();
2017-12-20 13:43:20 +01:00
2019-05-15 11:31:18 +02:00
/** @var d3LogInterface $oLog */
$oLog = d3GetModCfgDIC()->get('d3.ordermanager.log');
$oLog->notice(
2017-12-20 13:43:20 +01:00
__CLASS__,
__FUNCTION__,
__LINE__,
'send job execution info mail',
$this->getBody()
);
2019-05-15 11:31:18 +02:00
/** @var Language $oLang */
$oLang = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Language::class);
$sSubject = $oLang->translateString('D3_ORDERMANAGER_MAIL_ORDERSUBJECT', 0);
2021-03-16 10:10:19 +01:00
$this->d3OMsetSubject($sSubject);
2017-12-20 13:43:20 +01:00
$sFullName = $oShop->__get('oxshops__oxname')->getRawValue();
$this->setRecipient($oShop->getFieldData('oxinfoemail'), $sFullName);
$this->setReplyTo($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
$blSuccess = $this->send();
stopProfile(__METHOD__);
return $blSuccess;
}
/**
* @param $sOxId
* @return Order
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function d3getOrder($sOxId)
{
if (strstr($sOxId, '@@')) {
$aOxId = explode('@@', $sOxId);
$sOxId = $aOxId[0];
}
/** @var $oOrder Order */
2019-05-15 11:31:18 +02:00
$oOrder = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Order::class);
$oOrder->load($sOxId);
2017-12-20 13:43:20 +01:00
return $oOrder;
}
/**
* @param $sOxId
* @return d3ordermanager
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function d3getOrderManager($sOxId)
{
/** @var $oOrder d3ordermanager */
2019-05-15 11:31:18 +02:00
$oOrderManager = d3GetModCfgDIC()->get(d3ordermanager::class);
$oOrderManager->load($sOxId);
return $oOrderManager;
2017-12-20 13:43:20 +01:00
}
/**
* @param d3ordermanager $oOrderManager
* @return bool
2018-01-11 11:45:22 +01:00
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws DatabaseException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function sendOrderManagerMail(d3ordermanager $oOrderManager)
{
$this->oOrderManager = $oOrderManager;
$aContent = $this->getOrderManagerMailContent($oOrderManager);
$oShop = $this->_getShop();
2021-03-16 10:10:19 +01:00
$this->d3OMsetBody($aContent['html']);
$this->d3OMsetAltBody($aContent['plain']);
$this->d3OMsetSubject($aContent['subject']);
2017-12-20 13:43:20 +01:00
$this->_d3SetOrderManagerReplyAddress($oOrderManager, $oShop);
$oRemark = $this->_d3SetOrderManagerMailRecipients($oShop);
$this->_d3AddOrderManagerPdfAttachment($oOrderManager);
$blSuccess = $this->send();
if ($blSuccess && $oRemark) {
$oRemark->save();
}
return $blSuccess;
}
2021-03-16 10:10:19 +01:00
/**
* @param $content
*
* @throws d3ordermanager_smartyException
*/
protected function d3OMsetBody($content)
{
$this->setBody($content);
if ((bool) strlen($content) && false === (bool) strlen($this->getBody())) {
$this->throwUnequalContentException();
}
}
/**
* @param $content
*
* @throws d3ordermanager_smartyException
*/
protected function d3OMsetAltBody($content)
{
$this->setAltBody($content);
if ((bool) strlen($content) && false === (bool) strlen($this->getAltBody())) {
$this->throwUnequalContentException();
}
}
/**
* @param $content
*
* @throws d3ordermanager_smartyException
*/
protected function d3OMsetSubject($content)
{
$this->setSubject($content);
if ((bool) strlen($content) && false === (bool) strlen($this->getSubject())) {
$this->throwUnequalContentException();
}
}
2017-12-20 13:43:20 +01:00
/**
2019-05-15 11:31:18 +02:00
* @param Shop $oShop
2017-12-20 13:43:20 +01:00
*
* @return null|Remark
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3SetOrderManagerMailRecipients(Shop $oShop)
{
$oRemark = null;
if ($this->_d3hasOrderManagerCustomerRecipient()) {
$oRemark = $this->_d3sendOrderManagerMailToCustomer($oShop);
} elseif ($this->_d3hasOrderManagerOwnerRecipient()) {
2019-12-10 11:40:17 +01:00
$oRemark = $this->_d3sendOrderManagerMailToOwner($oShop);
2017-12-20 13:43:20 +01:00
} elseif ($this->_d3hasOrderManagerCustomRecipient()) {
2019-12-10 11:40:17 +01:00
$oRemark = $this->_d3sendOrderManagerMailToCustom();
2017-12-20 13:43:20 +01:00
}
return $oRemark;
}
/**
* @param $sVarName
*
* @return mixed
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3getOrderManagerMailOption($sVarName)
{
$aEditedValues = $this->oOrderManager->getEditedValues();
2021-03-16 10:10:19 +01:00
return false === isset($aEditedValues[$sVarName]) || $aEditedValues[$sVarName] === false || $aEditedValues[$sVarName] === null ?
2017-12-20 13:43:20 +01:00
$this->oOrderManager->getValue($sVarName) :
$aEditedValues[$sVarName];
}
/**
* @return mixed
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3hasOrderManagerCustomerRecipient()
{
return $this->_d3getOrderManagerMailOption('blSendMailToCustomer');
}
/**
* @return mixed
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3hasOrderManagerOwnerRecipient()
{
return $this->_d3getOrderManagerMailOption('blSendMailToOwner');
}
/**
* @return mixed
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3hasOrderManagerCustomRecipient()
{
return $this->_d3getOrderManagerMailOption('blSendMailToCustom');
}
/**
* @return mixed
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3getOrderManagerCustomRecipientList()
{
return $this->_d3getOrderManagerMailOption('sSendMailToCustomAddress');
}
/**
* @return d3_cfg_mod
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function d3GetSet()
{
2019-05-15 11:31:18 +02:00
return d3GetModCfgDIC()->get('d3.ordermanager.modcfg');
}
/**
* @return Payment
* @throws Exception
*/
public function d3GetPayment()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Payment::class);
}
/**
* @return Language
* @throws Exception
*/
public function d3GetLang()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Language::class);
}
/**
* required for unit tests, can't mock getConfig method
* @return Config
* @throws Exception
*/
public function d3GetConfig()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Config::class);
2017-12-20 13:43:20 +01:00
}
/**
* @param d3ordermanager $oOrderManager
2019-05-15 11:31:18 +02:00
*
2017-12-20 13:43:20 +01:00
* @return array
2018-01-11 11:45:22 +01:00
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
2019-05-15 11:31:18 +02:00
* @throws ArticleException
* @throws ArticleInputException
* @throws NoArticleException
* @throws d3ParameterNotFoundException
2018-01-11 11:45:22 +01:00
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
2019-05-15 11:31:18 +02:00
* @throws Exception
2021-03-16 10:10:19 +01:00
* @throws d3ordermanager_templaterendererExceptionInterface
2017-12-20 13:43:20 +01:00
*/
public function getOrderManagerMailContent(d3ordermanager $oOrderManager)
{
$this->oOrderManager = $oOrderManager;
$aContent = array();
2021-03-16 10:10:19 +01:00
$blTplFromAdmin = $oOrderManager->getValue('sSendMailFromTheme') == 'admin';
2019-05-15 11:31:18 +02:00
$oConfig = $this->d3GetConfig();
$oConfig->setAdminMode($blTplFromAdmin);
2017-12-20 13:43:20 +01:00
$oShop = $this->_getShop();
$this->_setMailParams($oShop);
2019-07-09 10:27:20 +02:00
/** @var Smarty $oSmarty */
2017-12-20 13:43:20 +01:00
$oSmarty = $this->_getSmarty();
/** @var $oBasket Basket */
$oBasket = $oOrderManager->getCurrentItem()->d3getOrderBasket4OrderManager($oOrderManager);
2019-05-15 11:31:18 +02:00
$oPayment = $this->d3GetPayment();
2020-08-20 09:35:38 +02:00
$oPayment->loadInLang($this->oOrderManager->getCurrentItem()->getFieldData('oxlang'), $oBasket->getPaymentId());
2017-12-20 13:43:20 +01:00
$oOrderManager->getCurrentItem()->d3setBasket4OrderManager($oBasket);
$oOrderManager->getCurrentItem()->d3setPayment4OrderManager($oPayment);
$this->setViewData("oShop", $oShop);
$this->setViewData("oViewConf", $this->getViewConfig());
$this->setViewData("oOrder", $oOrderManager->getCurrentItem());
$this->setViewData("oUser", $oOrderManager->getCurrentItem()->getOrderUser());
2019-05-15 11:31:18 +02:00
$this->setViewData("shopTemplateDir", $this->d3GetConfig()->getTemplateDir(false));
$this->setViewData("charset", $this->d3GetLang()->translateString("charset"));
2017-12-20 13:43:20 +01:00
$this->setViewData("shop", $oShop);
$this->setViewData("order", $oOrderManager->getCurrentItem());
$this->setViewData("user", $oOrderManager->getCurrentItem()->getOrderUser());
$this->setViewData("payment", $oPayment);
$this->setViewData("oDelSet", $oOrderManager->getCurrentItem()->getDelSet());
$this->setViewData("currency", $oOrderManager->getCurrentItem()->getOrderCurrency());
$this->setViewData("basket", $oBasket);
$oSmarty->template_dir = $this->getTemplateDir4OrderManager($oOrderManager);
$this->_processViewArray();
if (false == $this->d3GetSet()->getLicenseConfigData('blUseMailSendOnly', 0)) {
$oSmarty = $this->d3SendMailHook($oSmarty);
}
$aContent = $this->_d3GenerateOrderManagerMailContent($aContent, $oSmarty);
2019-05-15 11:31:18 +02:00
$oConfig->setAdminMode(true);
2017-12-20 13:43:20 +01:00
return $aContent;
}
2019-05-15 11:31:18 +02:00
/**
* @return Module
* @throws Exception
*/
public function d3GetModule()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Module::class);
}
/**
* @return d3str
* @throws Exception
*/
public function getD3Str()
{
return d3GetModCfgDIC()->get(d3str::class);
}
/**
* @return d3ShopCompatibilityAdapterHandler
* @throws Exception
*/
public function d3GetShopCompatibilityAdapterHandler()
{
return d3GetModCfgDIC()->get(d3ShopCompatibilityAdapterHandler::class);
}
2017-12-20 13:43:20 +01:00
/**
* @param d3ordermanager $oOrderManager
2019-05-15 11:31:18 +02:00
*
2017-12-20 13:43:20 +01:00
* @return string
2018-01-11 11:45:22 +01:00
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function getTemplateDir4OrderManager($oOrderManager)
{
if ($oOrderManager->getValue('sSendMailFromTheme') == 'module') {
$sModuleId = $oOrderManager->getValue('sSendMailFromModulePath');
2019-05-15 11:31:18 +02:00
$sModulePath = $this->d3GetShopCompatibilityAdapterHandler()->call(
2017-12-20 13:43:20 +01:00
'oxmodule__getModuleFullPath',
2019-05-15 11:31:18 +02:00
array($this->d3GetModule(), $sModuleId)
2017-12-20 13:43:20 +01:00
);
2019-05-15 11:31:18 +02:00
$sPath = $this->getD3Str()->untrailingslashit($sModulePath);
2017-12-20 13:43:20 +01:00
} else {
2021-03-16 10:10:19 +01:00
$blAdmin = $oOrderManager->getValue('sSendMailFromTheme') == 'admin';
2019-05-15 11:31:18 +02:00
$sPath = $this->d3GetConfig()->getTemplateDir($blAdmin);
2017-12-20 13:43:20 +01:00
}
return $sPath;
}
/**
2019-05-15 11:31:18 +02:00
* @param Smarty $oSmarty
* @return Smarty
2017-12-20 13:43:20 +01:00
*/
2019-05-15 11:31:18 +02:00
public function d3SendMailHook( Smarty $oSmarty)
2017-12-20 13:43:20 +01:00
{
// available objects:
// oxEmail: $this
// Smarty: $oSmarty
// Ordermanager profile: $this->oOrderManager
// Order: inside smarty
// oxuser: inside smarty
return $oSmarty;
}
2019-05-15 11:31:18 +02:00
/**
* @codeCoverageIgnore because visual CMS extension issue
* @return UtilsView
* @throws Exception
*/
public function d3GetUtilsView()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.UtilsView::class);
}
/**
* @return Content
* @throws Exception
*/
public function d3GetContent()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Content::class);
}
2017-12-20 13:43:20 +01:00
/**
* @param $aContent
2019-05-15 11:31:18 +02:00
* @param Smarty $oSmarty
2017-12-20 13:43:20 +01:00
*
* @return mixed
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
* @throws Exception
2021-03-16 10:10:19 +01:00
* @throws d3ordermanager_templaterendererExceptionInterface
2017-12-20 13:43:20 +01:00
*/
2019-05-15 11:31:18 +02:00
protected function _d3GenerateOrderManagerMailContent($aContent, Smarty $oSmarty)
2017-12-20 13:43:20 +01:00
{
$aEditedValues = $this->oOrderManager->getEditedValues();
2020-04-21 18:20:54 +02:00
$iOrderLangId = $this->oOrderManager->getCurrentItem()->getFieldData('oxlang');
$oLang = $this->d3GetLang();
$iCurrentTplLang = $oLang->getTplLanguage();
$iCurrentBaseLang = $oLang->getBaseLanguage();
$oLang->setTplLanguage($iOrderLangId);
$oLang->setBaseLanguage($iOrderLangId);
2020-08-20 09:35:38 +02:00
$iCurrentCurrency = Registry::getConfig()->getShopCurrency();
$iOrderCurr = $this->oOrderManager->getCurrentItem()->getOrderCurrency()->id;
Registry::getConfig()->setActShopCurrency($iOrderCurr);
2021-03-16 10:10:19 +01:00
set_error_handler(
[d3GetModCfgDIC()->get(d3ordermanager_renderererrorhandler::class), 'd3HandleTemplateEngineErrors']
);
2017-12-20 13:43:20 +01:00
if ($this->d3HasOrderManagerEditorMailContent($aEditedValues)) {
$aContent = $aEditedValues['mail'];
2019-12-10 11:40:17 +01:00
if ($aContent['genplain']) {
$aContent['plain'] = $this->d3generatePlainContent($aContent['html']);
}
2017-12-20 13:43:20 +01:00
} elseif ($this->oOrderManager->getValue('sSendMailFromSource') == 'cms') {
2019-05-15 11:31:18 +02:00
$oUtilsView = $this->d3GetUtilsView();
$oContent = $this->d3GetContent();
2020-08-20 09:35:38 +02:00
$oContent->loadInLang($iOrderLangId, $this->oOrderManager->getValue('sSendMailFromContentname'));
2017-12-20 13:43:20 +01:00
$aContent['html'] = $oUtilsView->parseThroughSmarty(
$oContent->getFieldData('oxcontent'),
$oContent->getId() . 'oxcontent'
);
$aContent['subject'] = $oContent->getFieldData('oxtitle');
2020-08-20 09:35:38 +02:00
$oContent->loadInLang($iOrderLangId, $this->oOrderManager->getValue('sSendMailFromContentnamePlain'));
2017-12-20 13:43:20 +01:00
$aContent['plain'] = $oUtilsView->parseThroughSmarty(
$oContent->getFieldData('oxcontent'),
$oContent->getId() . 'oxcontent'
);
} elseif ($this->oOrderManager->getValue('sSendMailFromSource') == 'template') {
$aContent['html'] = $oSmarty->fetch($this->oOrderManager->getValue('sSendMailFromTemplatename'));
$aContent['plain'] = $oSmarty->fetch($this->oOrderManager->getValue('sSendMailFromTemplatenamePlain'));
$aContent['subject'] = $oSmarty->fetch($this->oOrderManager->getValue('sSendMailFromSubject'));
}
2021-03-16 10:10:19 +01:00
restore_error_handler();
2020-04-21 18:20:54 +02:00
$oLang->setTplLanguage($iCurrentTplLang);
$oLang->setBaseLanguage($iCurrentBaseLang);
2020-08-20 09:35:38 +02:00
Registry::getConfig()->setActShopCurrency($iCurrentCurrency);
2020-04-21 18:20:54 +02:00
2017-12-20 13:43:20 +01:00
return $aContent;
}
/**
* @param $aEditedValues
*
* @return bool
*/
public function d3HasOrderManagerEditorMailContent($aEditedValues)
{
return $this->isArrayEditorMailContent($aEditedValues) &&
$aEditedValues['mail']['subject'] &&
$aEditedValues['mail']['html'] &&
2019-12-10 11:40:17 +01:00
(
$aEditedValues['mail']['genplain'] ||
$aEditedValues['mail']['plain']
);
2017-12-20 13:43:20 +01:00
}
/**
* @param $aEditedValues
*
* @return bool
*/
public function isArrayEditorMailContent($aEditedValues)
{
2021-03-16 10:10:19 +01:00
return is_array($aEditedValues) && isset($aEditedValues['mail']) && is_array($aEditedValues['mail']);
2017-12-20 13:43:20 +01:00
}
2019-12-10 11:40:17 +01:00
/**
* @param $html
* @return string
*/
public function d3generatePlainContent($html)
{
d3GetModCfgDIC()->setParameter(Html2Text::class.'.args.html', $html);
/** @var Html2Text $html */
$html = d3GetModCfgDIC()->get(Html2Text::class);
return $html->getText();
}
2017-12-20 13:43:20 +01:00
/**
2019-05-15 11:31:18 +02:00
* @return Remark
* @throws Exception
*/
public function d3GetRemark()
{
2019-12-10 11:40:17 +01:00
/** @var Remark $remark */
$remark = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Remark::class);
return $remark;
2019-05-15 11:31:18 +02:00
}
/**
* @param Shop $oShop
2017-12-20 13:43:20 +01:00
*
* @return Remark
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
protected function _d3sendOrderManagerMailToCustomer(Shop $oShop)
{
$oOrderUser = $this->oOrderManager->getCurrentItem()->getOrderUser();
if ($oOrderUser->getId()) {
$sFullName = $oOrderUser->__get('oxuser__oxfname')->getRawValue() . " " .
$oOrderUser->__get('oxuser__oxlname')->getRawValue();
$this->setRecipient($oOrderUser->getFieldData('oxusername'), $sFullName);
} else {
$sFullName = $this->oOrderManager->getCurrentItem()->__get('oxorder__oxbillfname')->getRawValue() . " " .
$this->oOrderManager->getCurrentItem()->__get('oxorder__oxbilllname')->getRawValue();
$this->setRecipient($this->oOrderManager->getCurrentItem()->getFieldData('oxbillemail'), $sFullName);
}
if ($this->_d3hasOrderManagerOwnerRecipient()) {
2019-05-15 11:31:18 +02:00
$this->addBCC($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
2017-12-20 13:43:20 +01:00
}
if ($this->_d3HasOrderManagerCustomMailAddresses()) {
foreach ($this->_d3getOrderManagerCustomMailAddressList() as $sMailAdr) {
2019-05-15 11:31:18 +02:00
$this->addBCC(trim($sMailAdr), trim($sMailAdr));
2017-12-20 13:43:20 +01:00
}
}
2019-12-10 11:40:17 +01:00
return $this->d3generateRemark();
2017-12-20 13:43:20 +01:00
}
/**
2019-05-15 11:31:18 +02:00
* @param Shop $oShop
2019-12-10 11:40:17 +01:00
*
* @return Remark
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2021-03-16 10:10:19 +01:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
protected function _d3sendOrderManagerMailToOwner(Shop $oShop)
{
$sFullName = $oShop->__get('oxshops__oxname')->getRawValue();
$this->setRecipient($oShop->getFieldData('oxinfoemail'), $sFullName);
if ($this->_d3HasOrderManagerCustomMailAddresses()) {
foreach ($this->_d3getOrderManagerCustomMailAddressList() as $sMailAdr) {
2019-05-15 11:31:18 +02:00
$this->addBCC(trim($sMailAdr), trim($sMailAdr));
2017-12-20 13:43:20 +01:00
}
}
2019-12-10 11:40:17 +01:00
return $this->d3generateRemark();
2017-12-20 13:43:20 +01:00
}
2019-05-15 11:31:18 +02:00
/**
* @throws d3ParameterNotFoundException
*/
2017-12-20 13:43:20 +01:00
protected function _d3sendOrderManagerMailToCustom()
{
2019-05-15 11:31:18 +02:00
if ($this->_d3HasOrderManagerCustomMailAddresses()) {
2017-12-20 13:43:20 +01:00
foreach ($this->_d3getOrderManagerCustomMailAddressList() as $sMailAdr) {
$this->setRecipient(trim($sMailAdr), trim($sMailAdr));
}
}
2019-12-10 11:40:17 +01:00
return $this->d3generateRemark();
2017-12-20 13:43:20 +01:00
}
/**
* @return array
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
protected function _d3getOrderManagerCustomMailAddressList()
{
$aMailAddressList = array();
foreach (explode(';', $this->_d3getOrderManagerCustomRecipientList()) as $sAddress) {
if (strlen(trim($sAddress))) {
2019-05-15 11:31:18 +02:00
$aMailAddressList[] = trim($sAddress);
2017-12-20 13:43:20 +01:00
}
}
return $aMailAddressList;
}
/**
* @return bool
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
2017-12-20 13:43:20 +01:00
*/
public function _d3HasOrderManagerCustomMailAddresses()
{
return $this->_d3hasOrderManagerCustomRecipient() && $this->_d3getOrderManagerCustomRecipientList();
}
/**
* @param d3ordermanager $oOrderManager
2019-05-15 11:31:18 +02:00
* @return d3ordermanager_pdfhandler
* @throws Exception
*/
public function d3GetPdfHandler(d3ordermanager $oOrderManager)
{
d3GetModCfgDIC()->set(
d3ordermanager_pdfhandler::class.'.args.ordermanager',
$oOrderManager
);
d3GetModCfgDIC()->set(
d3ordermanager_pdfhandler::class.'.args.order',
$oOrderManager->getCurrentItem()
);
return d3GetModCfgDIC()->get(d3ordermanager_pdfhandler::class);
}
/**
* @param d3ordermanager $oOrderManager
*
2018-01-11 11:45:22 +01:00
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
protected function _d3AddOrderManagerPdfAttachment(d3ordermanager $oOrderManager)
{
2019-05-15 11:31:18 +02:00
$oPDFHandler = $this->d3GetPdfHandler($oOrderManager);
2017-12-20 13:43:20 +01:00
2020-08-20 09:35:38 +02:00
$this->addOXIDPdfAttachment($oOrderManager, $oPDFHandler);
$this->addPdfDocumentsAttachment($oOrderManager, $oPDFHandler);
}
/**
* @param d3ordermanager $oOrderManager
* @param d3ordermanager_pdfhandler $oPDFHandler
*
* @throws FileExistsException
*/
public function addOXIDPdfAttachment(d3ordermanager $oOrderManager, d3ordermanager_pdfhandler $oPDFHandler)
{
d3GetModCfgDIC()->set(
d3ordermanager_action_generatepdf::class.'.args.ordermanager',
d3GetModCfgDIC()->get(d3ordermanager::class)
);
d3GetModCfgDIC()->set(
d3ordermanager_action_generatepdf::class.'.args.order',
d3GetModCfgDIC()->get('d3ox.ordermanager.'.Order::class)
);
/** @var d3ordermanager_action_generatepdf $action */
$action = d3GetModCfgDIC()->get(d3ordermanager_action_generatepdf::class);
2021-03-16 10:10:19 +01:00
if ($oOrderManager->getValue($action->getActiveSwitchParameter())
2017-12-20 13:43:20 +01:00
&& $oOrderManager->getValue('blActionOrderPdfSendAttach')
2020-08-20 09:35:38 +02:00
&& $oPDFHandler->canGenerateOxidPdf()
2017-12-20 13:43:20 +01:00
) {
if ($oOrderManager->getValue('blActionOrderPdfTypeInvoice')) {
2020-08-20 09:35:38 +02:00
$oPDFHandler->createOxidPdf(d3ordermanager_conf::D3_ORDERMANAGER_PDFTYPE_INVOICE, d3ordermanager_conf::D3_ORDERMANAGER_PDFSENDTYPE_ATTACH);
$sFileName = $oPDFHandler->getOxidPdfFileName(d3ordermanager_conf::D3_ORDERMANAGER_PDFTYPE_INVOICE);
$sFilePath = $oPDFHandler->getOxidPdfSaveDir(d3ordermanager_conf::D3_ORDERMANAGER_PDFSENDTYPE_ATTACH) . $sFileName;
2017-12-20 13:43:20 +01:00
$this->addAttachment($sFilePath, $sFileName, 'base64', 'application/pdf');
}
if ($oOrderManager->getValue('blActionOrderPdfTypeDelnote')) {
2020-08-20 09:35:38 +02:00
$oPDFHandler->createOxidPdf(d3ordermanager_conf::D3_ORDERMANAGER_PDFTYPE_DELIVERYNOTE, d3ordermanager_conf::D3_ORDERMANAGER_PDFSENDTYPE_ATTACH);
$sFileName = $oPDFHandler->getOxidPdfFileName(d3ordermanager_conf::D3_ORDERMANAGER_PDFTYPE_DELIVERYNOTE);
$sFilePath = $oPDFHandler->getOxidPdfSaveDir(d3ordermanager_conf::D3_ORDERMANAGER_PDFSENDTYPE_ATTACH) . $sFileName;
2017-12-20 13:43:20 +01:00
$this->addAttachment($sFilePath, $sFileName, 'base64', 'application/pdf');
}
}
}
2020-08-20 09:35:38 +02:00
/**
* @param d3ordermanager $oOrderManager
* @param d3ordermanager_pdfhandler $oPDFHandler
*
* @throws FileExistsException
*/
public function addPdfDocumentsAttachment(d3ordermanager $oOrderManager, d3ordermanager_pdfhandler $oPDFHandler)
{
d3GetModCfgDIC()->set(
d3ordermanager_action_getpdfdocuments::class.'.args.ordermanager',
$oOrderManager
);
d3GetModCfgDIC()->set(
d3ordermanager_action_getpdfdocuments::class.'.args.order',
$oOrderManager->getCurrentItem()
);
/** @var d3ordermanager_action_getpdfdocuments $action */
$action = d3GetModCfgDIC()->get(d3ordermanager_action_getpdfdocuments::class);
2021-03-16 10:10:19 +01:00
if ($oOrderManager->getValue($action->getActiveSwitchParameter())
2020-08-20 09:35:38 +02:00
&& $oOrderManager->getValue('blActionOrderPdfDocumentSendAttach')
&& $oPDFHandler->canGeneratePdfDocuments()
) {
/** @var pdfdocumentsOrderInterface $document */
foreach ($action->getDocumentList() as $document) {
if ($oOrderManager->getValue($action->getDocumentRequestId($document))) {
$document->setOrder($action->getOrder());
$oPDFHandler->createPdfDocument($document, d3ordermanager_conf::D3_ORDERMANAGER_PDFSENDTYPE_ATTACH);
$sFilePath = $oPDFHandler->getOxidPdfSaveDir(d3ordermanager_conf::D3_ORDERMANAGER_PDFSENDTYPE_ATTACH).$document->getFilename();
$this->addAttachment($sFilePath, $document->getFilename(), 'base64', 'application/pdf');
}
}
}
}
2017-12-20 13:43:20 +01:00
/**
* @param d3ordermanager $oOrderManager
* @param Shop $oShop
*/
protected function _d3SetOrderManagerReplyAddress(d3ordermanager $oOrderManager, Shop $oShop)
{
if (strlen(trim($oOrderManager->getValue('sSendMailReplyAddress')))) {
$this->setFrom(trim($oOrderManager->getValue('sSendMailReplyAddress')));
$this->setReplyTo(
trim($oOrderManager->getValue('sSendMailReplyAddress')),
$oShop->__get('oxshops__oxname')->getRawValue()
);
} else {
$this->setReplyTo($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
}
}
2019-12-10 11:40:17 +01:00
/**
* add user history
* @return Remark
* @throws d3ParameterNotFoundException
2021-03-16 10:10:19 +01:00
* @throws Exception
2019-12-10 11:40:17 +01:00
*/
public function d3generateRemark() {
$oRemark = $this->d3GetRemark();
$aRemarkContent = array(
'oxtext' => $this->d3getRemarkText(),
2021-03-16 10:10:19 +01:00
'oxparentid' => $this->oOrderManager->getCurrentItem()->getOrderUser()->getId() ? :
$this->oOrderManager->getCurrentItem()->getId(),
2019-12-10 11:40:17 +01:00
'oxtype' => 'd3om',
);
$oRemark->assign( $aRemarkContent );
return $oRemark;
}
/**
* @return string
*/
public function d3getRemarkText()
{
return implode(
PHP_EOL.'---'.PHP_EOL,
[
'Recipients:',
implode(', ', array_keys($this->getAllRecipientAddresses())),
'HTML:',
$this->getBody(),
'Plain',
$this->getAltBody()
]
);
}
2021-03-16 10:10:19 +01:00
/**
* @return ContainerInterface
*/
public function d3getOrderManagerDIContainer()
{
return ContainerFactory::getInstance()->getContainer();
}
/**
* @throws d3ordermanager_smartyException
*/
protected function throwUnequalContentException()
{
d3GetModCfgDIC()->setParameter(
d3ordermanager_smartyException::class . '.args.message',
'empty mail content, possible file encoding error'
);
/** @var d3ordermanager_smartyException $e */
$e = d3GetModCfgDIC()->get( d3ordermanager_smartyException::class );
throw $e;
}
2017-12-20 13:43:20 +01:00
}