2020-10-02 11:59:22 +02:00
|
|
|
<?php
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
namespace D3\Usermanager\Modules\Application\Model;
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
|
2020-10-02 11:59:22 +02:00
|
|
|
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
2021-03-15 15:17:45 +01:00
|
|
|
use D3\Usermanager\Application\Model\d3usermanager_configurationcheck;
|
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3ActionRequirementAbstract;
|
|
|
|
use D3\Usermanager\Application\Model\d3usermanager as Manager;
|
2020-10-02 11:59:22 +02:00
|
|
|
use D3\Usermanager\Application\Model\d3usermanager_conf;
|
|
|
|
use D3\Usermanager\Application\Model\d3usermanager_execute;
|
|
|
|
use D3\Usermanager\Application\Model\d3usermanagerlist;
|
2021-10-04 13:52:09 +02:00
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_actionException;
|
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_requirementException;
|
2021-03-15 15:17:45 +01:00
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_templaterendererExceptionInterface;
|
2020-10-02 11:59:22 +02:00
|
|
|
use Exception;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Basket;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
2021-03-15 15:17:45 +01:00
|
|
|
use OxidEsales\Eshop\Core\Config;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
2021-03-15 15:17:45 +01:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class d3_order_usermanager
|
|
|
|
*
|
|
|
|
* @package D3\Usermanager\Modules\Application\Model
|
|
|
|
*/
|
|
|
|
class d3_order_usermanager extends d3_order_usermanager_parent
|
|
|
|
{
|
2021-03-15 15:17:45 +01:00
|
|
|
CONST PREVENTION_FINALIZEORDER = 'd3PreventUMFinalizeOrderTrigger';
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
/**
|
|
|
|
* @param Basket $oBasket
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param User $oUser
|
2020-10-02 11:59:22 +02:00
|
|
|
* @param false $blRecalculatingOrder
|
|
|
|
*
|
2021-03-15 15:17:45 +01:00
|
|
|
* @return int
|
2020-10-02 11:59:22 +02:00
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
|
|
* @throws d3_cfg_mod_exception
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
* @throws StandardException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-05-07 11:22:58 +02:00
|
|
|
public function finalizeOrder(Basket $oBasket, $oUser, $blRecalculatingOrder = false)//: int // function declaration must be compatible with parent function
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$iRet = parent::finalizeOrder($oBasket, $oUser, $blRecalculatingOrder);
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var d3_cfg_mod $oSet */
|
|
|
|
$oSet = d3GetModCfgDIC()->get('d3.usermanager.modcfg');
|
2021-03-15 15:17:45 +01:00
|
|
|
$currentAdminMode = $this->isAdmin();
|
|
|
|
|
|
|
|
if ($oSet->isActive() && in_array(Registry::getSession()->getVariable(self::PREVENTION_FINALIZEORDER), [null, false], true)) {
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var d3usermanagerlist $oUserManagerList */
|
|
|
|
$oUserManagerList = d3GetModCfgDIC()->get(d3usermanagerlist::class);
|
2021-03-15 15:17:45 +01:00
|
|
|
/** @var Manager $oManager */
|
2020-12-21 10:44:49 +01:00
|
|
|
foreach ($oUserManagerList->d3GetOrderFinishTriggeredManagerTasks() as $oManager) {
|
2021-03-15 15:17:45 +01:00
|
|
|
try {
|
|
|
|
$this->d3UserManagerCheckForConfigurationException($oManager);
|
|
|
|
|
|
|
|
$oManagerExecute = $this->d3UsermanagerGetManagerExecute($oManager);
|
|
|
|
if ($oManagerExecute->userMeetsConditions($oUser->getId())) {
|
|
|
|
// prevent infinit loop because of circular reference in recalculate::method
|
|
|
|
Registry::getSession()->setVariable(self::PREVENTION_FINALIZEORDER, true);
|
|
|
|
$oManagerExecute->exec4user($oUser->getId(), d3usermanager_conf::EXECTYPE_ORDERFINISHTRIGGERED);
|
|
|
|
}
|
2021-10-04 13:52:09 +02:00
|
|
|
} catch (d3ActionRequirementAbstract | d3usermanager_templaterendererExceptionInterface $e) {
|
|
|
|
if (!defined('OXID_PHP_UNIT')) {
|
|
|
|
Registry::getLogger()->error($e->getMessage(), [$e]);
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
if (true === $currentAdminMode) {
|
|
|
|
/** @var UtilsView $utilsView */
|
|
|
|
$utilsView = d3GetModCfgDIC()->get('d3ox.usermanager.' . UtilsView::class);
|
|
|
|
$utilsView->addErrorToDisplay($e);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
Registry::getSession()->setVariable(self::PREVENTION_FINALIZEORDER, false);
|
|
|
|
$oConfig = d3GetModCfgDIC()->get('d3ox.usermanager.'.Config::class);
|
|
|
|
$oConfig->setAdminMode($currentAdminMode);
|
2020-12-21 10:44:49 +01:00
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $iRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-15 15:17:45 +01:00
|
|
|
* @param Manager $oManager
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return d3usermanager_execute
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3UsermanagerGetManagerExecute(Manager $oManager): d3usermanager_execute
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->set(
|
|
|
|
d3usermanager_execute::class.'.args.usermanager',
|
|
|
|
$oManager
|
|
|
|
);
|
|
|
|
|
|
|
|
/** @var d3usermanager_execute $execute */
|
|
|
|
$execute = d3GetModCfgDIC()->get(d3usermanager_execute::class);
|
|
|
|
|
|
|
|
return $execute;
|
|
|
|
}
|
2021-03-15 15:17:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Manager $oManager
|
2021-10-04 13:52:09 +02:00
|
|
|
* @throws d3usermanager_actionException
|
|
|
|
* @throws d3usermanager_requirementException
|
2021-03-15 15:17:45 +01:00
|
|
|
*/
|
|
|
|
protected function d3UserManagerCheckForConfigurationException(Manager $oManager): void
|
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->set(d3usermanager_configurationcheck::class.'.args.usermanager', $oManager);
|
|
|
|
d3GetModCfgDIC()->setParameter(
|
|
|
|
d3usermanager_configurationcheck::class.'.args.checktypes',
|
|
|
|
$oManager->getValue('sManuallyExecMeetCondition') ?
|
|
|
|
d3usermanager_configurationcheck::REQUIREMENTS_AND_ACTIONS :
|
|
|
|
d3usermanager_configurationcheck::ACTIONS_ONLY
|
|
|
|
);
|
|
|
|
/** @var d3usermanager_configurationcheck $confCheck */
|
|
|
|
$confCheck = d3GetModCfgDIC()->get(d3usermanager_configurationcheck::class);
|
|
|
|
$confCheck->checkThrowingExceptions();
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
}
|