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:56:55 +02:00
|
|
|
namespace D3\Devhelper\Modules\Application\Model;
|
|
|
|
|
2024-07-03 09:32:01 +02:00
|
|
|
use D3\Devhelper\Application\Model\Exception\NoOrderFoundException;
|
|
|
|
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
|
|
|
|
use Doctrine\DBAL\Exception as DBALException;
|
2024-07-02 17:03:38 +02:00
|
|
|
use Doctrine\DBAL\Query\QueryBuilder;
|
2020-11-11 22:29:10 +01:00
|
|
|
use oxarticleinputexception;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Basket;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Order;
|
2019-10-16 14:56:55 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Voucher;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
2024-07-03 09:32:01 +02:00
|
|
|
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
|
2019-10-16 14:56:55 +02:00
|
|
|
use OxidEsales\Eshop\Core\Model\ListModel;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2024-07-02 17:03:38 +02:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
|
2020-11-11 22:29:10 +01:00
|
|
|
use oxnoarticleexception;
|
2024-07-03 09:32:01 +02:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2019-10-16 14:56:55 +02:00
|
|
|
|
2018-01-25 11:30:17 +01:00
|
|
|
class d3_dev_oxorder extends d3_dev_oxorder_parent
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return d3_dev_oxbasket
|
|
|
|
*/
|
|
|
|
public function d3DevGetOrderBasket()
|
|
|
|
{
|
|
|
|
/** @var d3_dev_oxbasket $oBasket */
|
2024-07-02 17:03:38 +02:00
|
|
|
$oBasket = $this->getOrderBasket();
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
// add this order articles to basket and recalculate basket
|
2019-10-16 14:56:55 +02:00
|
|
|
$this->_d3AddOrderArticlesToBasket($oBasket, $this->getOrderArticles());
|
|
|
|
|
2018-01-25 11:30:17 +01:00
|
|
|
// recalculating basket
|
|
|
|
$oBasket->calculateBasket(true);
|
|
|
|
$oBasket->d3ClearBasketItemArticles();
|
|
|
|
|
2024-07-02 17:03:38 +02:00
|
|
|
$this->_oPayment = $this->setPayment($oBasket->getPaymentId());
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
return $oBasket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-07-03 09:32:01 +02:00
|
|
|
* @return false|string
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DBALException
|
|
|
|
* @throws DBALDriverException
|
|
|
|
* @throws NotFoundExceptionInterface
|
2018-01-25 11:30:17 +01:00
|
|
|
*/
|
2024-07-03 09:32:01 +02:00
|
|
|
public function d3getLastOrderId(): false|string
|
2018-01-25 11:30:17 +01:00
|
|
|
{
|
2024-07-02 17:03:38 +02:00
|
|
|
/** @var QueryBuilder $qb */
|
|
|
|
$qb = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
|
|
|
$qb->select('oxid')
|
|
|
|
->from((oxNew(Order::class))->getViewName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->and(
|
2024-07-03 09:32:01 +02:00
|
|
|
$qb->expr()->neq(
|
2024-07-02 17:03:38 +02:00
|
|
|
'oxuserid',
|
|
|
|
$qb->createNamedParameter('')
|
|
|
|
),
|
|
|
|
$qb->expr()->eq(
|
|
|
|
'oxshopid',
|
|
|
|
$qb->createNamedParameter(Registry::getConfig()->getShopId())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
->orderBy('oxorderdate', 'DESC')
|
|
|
|
->setMaxResults(1);
|
|
|
|
|
2020-11-11 22:29:10 +01:00
|
|
|
$orderNr = (int) Registry::getRequest()->getRequestEscapedParameter('d3ordernr');
|
2018-01-25 11:30:17 +01:00
|
|
|
if ($orderNr) {
|
2024-07-02 17:03:38 +02:00
|
|
|
$qb->andWhere(
|
|
|
|
$qb->expr()->eq(
|
|
|
|
'oxordernr',
|
|
|
|
$orderNr
|
|
|
|
)
|
|
|
|
);
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 17:03:38 +02:00
|
|
|
return $qb->execute()->fetchOne();
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-07-03 09:32:01 +02:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DBALDriverException
|
|
|
|
* @throws DBALException
|
2018-02-23 12:30:57 +01:00
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2024-07-03 09:32:01 +02:00
|
|
|
* @throws NoOrderFoundException
|
|
|
|
* @throws NotFoundExceptionInterface
|
2018-01-25 11:30:17 +01:00
|
|
|
*/
|
2024-07-03 09:32:01 +02:00
|
|
|
public function d3getLastOrder(): void
|
2018-01-25 11:30:17 +01:00
|
|
|
{
|
2024-07-03 09:32:01 +02:00
|
|
|
if ($orderId = $this->d3getLastOrderId()) {
|
|
|
|
$this->load($orderId);
|
|
|
|
$this->_d3AddVouchers();
|
|
|
|
} else {
|
|
|
|
throw new NoOrderFoundException();
|
|
|
|
}
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-11 22:29:10 +01:00
|
|
|
* @return d3_dev_oxbasket|Basket
|
2018-01-25 11:30:17 +01:00
|
|
|
*/
|
|
|
|
public function getBasket()
|
|
|
|
{
|
|
|
|
$oBasket = parent::getBasket();
|
|
|
|
|
|
|
|
if (false == $oBasket && Registry::getConfig()->getActiveView()->getClassKey() == 'd3dev') {
|
|
|
|
$oBasket = $this->d3DevGetOrderBasket();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $oBasket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-23 12:30:57 +01:00
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2018-01-25 11:30:17 +01:00
|
|
|
*/
|
|
|
|
protected function _d3AddVouchers()
|
|
|
|
{
|
2024-07-02 17:03:38 +02:00
|
|
|
/** @var QueryBuilder $qb */
|
|
|
|
$qb = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
|
|
|
$qb->select('oxid')
|
|
|
|
->from((oxNew(Voucher::class))->getViewName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->eq(
|
|
|
|
'oxorderid',
|
|
|
|
$qb->createNamedParameter($this->getId())
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$aResult = $qb->execute()->fetchAllAssociative();
|
2018-01-25 11:30:17 +01:00
|
|
|
|
|
|
|
foreach ($aResult as $aFields) {
|
2018-02-23 12:30:57 +01:00
|
|
|
$oVoucher = oxNew(Voucher::class);
|
2018-01-25 11:30:17 +01:00
|
|
|
$oVoucher->load($aFields['oxid']);
|
|
|
|
$this->_aVoucherList[$oVoucher->getId()] = $oVoucher;
|
|
|
|
}
|
|
|
|
}
|
2019-10-16 14:56:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds order articles back to virtual basket. Needed for recalculating order.
|
|
|
|
*
|
|
|
|
* @param d3_dev_oxbasket $oBasket basket object
|
|
|
|
* @param ListModel $aOrderArticles order articles
|
2020-11-11 22:29:10 +01:00
|
|
|
* @throws oxArticleInputException
|
|
|
|
* @throws oxNoArticleException
|
2019-10-16 14:56:55 +02:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 11:30:17 +01:00
|
|
|
}
|