adjust displayed mails to show bundle articles

This commit is contained in:
Daniel Seifert 2019-10-16 14:56:55 +02:00
parent 46d447dba7
commit 73f38afc7f
3 changed files with 93 additions and 30 deletions

View File

@ -1,9 +1,5 @@
<?php
namespace D3\Devhelper\Modules\Application\Model;
use OxidEsales\Eshop\Core\Registry;
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
@ -19,6 +15,12 @@ use OxidEsales\Eshop\Core\Registry;
* @link http://www.oxidmodule.com
*/
namespace D3\Devhelper\Modules\Application\Model;
use OxidEsales\Eshop\Application\Model\BasketItem;
use OxidEsales\Eshop\Application\Model\OrderArticle;
use OxidEsales\Eshop\Core\Registry;
class d3_dev_oxbasket extends d3_dev_oxbasket_parent
{
public function deleteBasket()
@ -61,4 +63,37 @@ class d3_dev_oxbasket extends d3_dev_oxbasket_parent
}
}
}
/**
* @param OrderArticle $oOrderArticle
*
* @return |null
* @throws \oxArticleInputException
* @throws \oxNoArticleException
*/
public function d3addOrderArticleToBasket($oOrderArticle)
{
// adding only if amount > 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;
}
}

View File

@ -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;
}
}
}

View File

@ -1,16 +1,5 @@
<?php
namespace D3\Devhelper\Modules\Application\Model;
use OxidEsales\Eshop\Application\Model\OrderArticle;
use OxidEsales\Eshop\Application\Model\Voucher;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Model\ListModel;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
@ -26,6 +15,16 @@ use OxidEsales\Eshop\Core\Request;
* @link http://www.oxidmodule.com
*/
namespace D3\Devhelper\Modules\Application\Model;
use OxidEsales\Eshop\Application\Model\Voucher;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Model\ListModel;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
class d3_dev_oxorder extends d3_dev_oxorder_parent
{
/**
@ -36,18 +35,9 @@ class d3_dev_oxorder extends d3_dev_oxorder_parent
/** @var d3_dev_oxbasket $oBasket */
$oBasket = $this->_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);
}
}
}
}