diff --git a/src/Modules/Application/Controller/d3_dev_thankyou.php b/src/Modules/Application/Controller/d3_dev_thankyou.php index 89fc95c..22dc800 100644 --- a/src/Modules/Application/Controller/d3_dev_thankyou.php +++ b/src/Modules/Application/Controller/d3_dev_thankyou.php @@ -40,7 +40,12 @@ class d3_dev_thankyou extends d3_dev_thankyou_parent parent::init(); - Registry::getSession()->setVariable('sess_challenge', $sSessChallenge); + if (Registry::get(Request::class)->getRequestEscapedParameter("d3dev") + && false == (bool) Registry::getConfig()->getActiveShop()->isProductiveMode() + && Registry::getConfig()->getConfigParam('blD3DevAvoidDelBasket') + ) { + Registry::getSession()->setVariable( 'sess_challenge', $sSessChallenge ); + } if (Registry::get(Request::class)->getRequestEscapedParameter("d3dev") && false == (bool) Registry::getConfig()->getActiveShop()->isProductiveMode() @@ -96,6 +101,27 @@ class d3_dev_thankyou extends d3_dev_thankyou_parent } } + /** + * @return bool|d3_dev_oxorder|\oxOrder + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + */ + public function getOrder() + { + $oOrder = parent::getOrder(); + + if ((false == $oOrder || !$oOrder->getFieldData('oxordernr')) + && Registry::get(Request::class)->getRequestEscapedParameter("d3dev") + && false == (bool) Registry::getConfig()->getActiveShop()->isProductiveMode() + && Registry::getConfig()->getConfigParam('blD3DevShowThankyou') + ) { + $this->_oOrder = $this->d3GetLastOrder(); + $oOrder = $this->_oOrder; + } + + return $oOrder; + } + /** * @return bool|d3_dev_oxorder * @throws DatabaseConnectionException diff --git a/src/Modules/Application/Model/d3_dev_oxbasket.php b/src/Modules/Application/Model/d3_dev_oxbasket.php index ca65b7f..7d57d72 100644 --- a/src/Modules/Application/Model/d3_dev_oxbasket.php +++ b/src/Modules/Application/Model/d3_dev_oxbasket.php @@ -1,9 +1,5 @@ 0 + if ($oOrderArticle->oxorderarticles__oxamount->value > 0) { + $this->_isForOrderRecalculation = true; + $sItemId = $oOrderArticle->getId(); + + //inserting new + /** @var d3_dev_oxbasketitem $oBasketItem */ + $oBasketItem = oxNew( BasketItem::class); + $oBasketItem->initFromOrderArticle($oOrderArticle); + $oBasketItem->d3ConvertToArticleObject(); + $oBasketItem->setWrapping($oOrderArticle->oxorderarticles__oxwrapid->value); + $oBasketItem->setBundle($oOrderArticle->isBundle()); + + $this->_aBasketContents[$sItemId] = $oBasketItem; + + //calling update method + $this->onUpdate(); + + return $this->_aBasketContents[$sItemId]; + } + + return null; + } } diff --git a/src/Modules/Application/Model/d3_dev_oxbasketitem.php b/src/Modules/Application/Model/d3_dev_oxbasketitem.php index 1d23c3d..e8f0ef4 100644 --- a/src/Modules/Application/Model/d3_dev_oxbasketitem.php +++ b/src/Modules/Application/Model/d3_dev_oxbasketitem.php @@ -16,6 +16,12 @@ namespace D3\Devhelper\Modules\Application\Model; +use OxidEsales\Eshop\Application\Model\Article; +use OxidEsales\Eshop\Application\Model\OrderArticle; +use OxidEsales\Eshop\Core\Exception\ArticleException; +use OxidEsales\Eshop\Core\Exception\ArticleInputException; +use OxidEsales\Eshop\Core\Exception\NoArticleException; + class d3_dev_oxbasketitem extends d3_dev_oxbasketitem_parent { public function d3ClearArticle() @@ -25,9 +31,9 @@ class d3_dev_oxbasketitem extends d3_dev_oxbasketitem_parent /** * @return string - * @throws \OxidEsales\Eshop\Core\Exception\ArticleException - * @throws \OxidEsales\Eshop\Core\Exception\ArticleInputException - * @throws \OxidEsales\Eshop\Core\Exception\NoArticleException + * @throws ArticleException + * @throws ArticleInputException + * @throws NoArticleException */ public function getTitle() { @@ -40,4 +46,19 @@ class d3_dev_oxbasketitem extends d3_dev_oxbasketitem_parent return $this->_sTitle; } + + /** + * @throws \oxArticleInputException + * @throws \oxNoArticleException + */ + public function d3ConvertToArticleObject() + { + $oEmbeddedArticle = $this->getArticle(); + + if ($oEmbeddedArticle instanceof OrderArticle) { + $oArticle = oxNew(Article::class); + $oArticle->load($oEmbeddedArticle->getFieldData('oxartid')); + $this->_oArticle = $oArticle; + } + } } diff --git a/src/Modules/Application/Model/d3_dev_oxorder.php b/src/Modules/Application/Model/d3_dev_oxorder.php index c6eff1c..514b8ec 100644 --- a/src/Modules/Application/Model/d3_dev_oxorder.php +++ b/src/Modules/Application/Model/d3_dev_oxorder.php @@ -1,16 +1,5 @@ _getOrderBasket(); - // unsetting bundles - /** @var ListModel $oOrderArticles */ - $oOrderArticles = $this->getOrderArticles(); - foreach ($oOrderArticles as $sItemId => $oItem) { - /** @var $oItem OrderArticle */ - if ($oItem->isBundle()) { - $oOrderArticles->offsetUnset($sItemId); - } - } - // add this order articles to basket and recalculate basket - $this->_addOrderArticlesToBasket($oBasket, $oOrderArticles); + $this->_d3AddOrderArticlesToBasket($oBasket, $this->getOrderArticles()); + // recalculating basket $oBasket->calculateBasket(true); $oBasket->d3ClearBasketItemArticles(); @@ -66,7 +56,7 @@ class d3_dev_oxorder extends d3_dev_oxorder_parent $orderNr = (int) Registry::get(Request::class)->getRequestEscapedParameter('d3ordernr'); $sWhere = 1; if ($orderNr) { - $sWhere = ' oxordernr = ' . $orderNr; + $sWhere = ' oxordernr = ' . DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC)->quote($orderNr); } $sSelect = "SELECT oxid FROM ".getViewName('oxorder')." WHERE ".$sWhere." ORDER BY oxorderdate DESC LIMIT 1"; @@ -114,4 +104,21 @@ class d3_dev_oxorder extends d3_dev_oxorder_parent $this->_aVoucherList[$oVoucher->getId()] = $oVoucher; } } + + /** + * Adds order articles back to virtual basket. Needed for recalculating order. + * + * @param d3_dev_oxbasket $oBasket basket object + * @param ListModel $aOrderArticles order articles + */ + protected function _d3AddOrderArticlesToBasket($oBasket, $aOrderArticles) + { + // if no order articles, return empty basket + if (count($aOrderArticles) > 0) { + //adding order articles to basket + foreach ($aOrderArticles as $oOrderArticle) { + $oBasket->d3addOrderArticleToBasket($oOrderArticle); + } + } + } } diff --git a/src/Modules/Core/d3_dev_oxemail.php b/src/Modules/Core/d3_dev_oxemail.php index 258a665..b858ddc 100644 --- a/src/Modules/Core/d3_dev_oxemail.php +++ b/src/Modules/Core/d3_dev_oxemail.php @@ -1,10 +1,5 @@ getActiveShop()->isProductiveMode()) { return ''; @@ -154,6 +155,10 @@ class d3_dev_oxemail extends d3_dev_oxemail_parent return $oSmarty->fetch($myConfig->getTemplatePath($sTpl, false)); } + /** + * @return bool + * @throws StandardException + */ protected function _sendMail() { if (Registry::getConfig()->getActiveShop()->isProductiveMode()) { @@ -161,6 +166,8 @@ class d3_dev_oxemail extends d3_dev_oxemail_parent } $this->d3clearRecipients(); + $this->d3clearReplies(); + $this->d3clearReplyTo(); $this->d3clearCC(); $this->d3clearBCC(); @@ -190,6 +197,44 @@ class d3_dev_oxemail extends d3_dev_oxemail_parent $this->_aRecipients = $aRecipients; } + public function d3clearReplies() + { + $aRecipients = array(); + if (is_array($this->_aReplies) && count($this->_aReplies)) { + foreach ($this->_aReplies as $aRecInfo) { + if (($sNewRecipient = $this->getNewRecipient($aRecInfo[0])) + && $sNewRecipient != $aRecInfo[0] + ) { + $aRecInfo[1] = $aRecInfo[1]." (".$aRecInfo[0].")"; + $aRecInfo[0] = $sNewRecipient; + $aRecipients[] = $aRecInfo; + } elseif (($sNewRecipient = $this->getNewRecipient($aRecInfo[0]))) { + $aRecipients[] = $aRecInfo; + } + } + } + $this->_aReplies = $aRecipients; + } + + public function d3clearReplyTo() + { + $aRecipients = array(); + if (is_array($this->ReplyTo) && count($this->ReplyTo)) { + foreach ($this->ReplyTo as $aRecInfo) { + if (($sNewRecipient = $this->getNewRecipient($aRecInfo[0])) + && $sNewRecipient != $aRecInfo[0] + ) { + $aRecInfo[1] = $aRecInfo[1]." (".$aRecInfo[0].")"; + $aRecInfo[0] = $sNewRecipient; + $aRecipients[] = $aRecInfo; + } elseif (($sNewRecipient = $this->getNewRecipient($aRecInfo[0]))) { + $aRecipients[] = $aRecInfo; + } + } + } + $this->ReplyTo = $aRecipients; + } + public function d3clearCC() { $aCc = array(); @@ -230,6 +275,11 @@ class d3_dev_oxemail extends d3_dev_oxemail_parent $this->bcc = $aCc; } + /** + * @param $sMailAddress + * + * @return bool|string + */ public function getNewRecipient($sMailAddress) { if (Registry::getConfig()->getConfigParam('blD3DevBlockMails')) {