From 0c632e5b066d1030765307cace5e3100bafc00f7 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Thu, 4 Mar 2021 22:18:38 +0100 Subject: [PATCH] * compatibility TYPO3 10.4: make a new TaxajaxController which does not initialize the front end --- ChangeLog | 4 + Classes/Controller/OldTaxajaxController.php | 109 ++++++++++++++++++++ Classes/Controller/TaxajaxController.php | 27 ++--- control/class.tx_ttproducts_javascript.php | 2 +- eid/class.tx_ttproducts_db.php | 4 - ext_localconf.php | 3 +- 6 files changed, 126 insertions(+), 23 deletions(-) create mode 100755 Classes/Controller/OldTaxajaxController.php diff --git a/ChangeLog b/ChangeLog index ac3072cad..ec79f8502 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-03-04 Franz Holzinger + * compatibility TYPO3 10.4: make a new TaxajaxController which does not initialize the front end + * compatibility TYPO3 10.4: Ajax bugfix + 2021-03-03 Franz Holzinger * compatibility TYPO3 9.5: replace $GLOBALS['TSFE']->loginUser by \JambageCom\Div2007\Utility\CompatibilityUtility::isLoggedIn(). diff --git a/Classes/Controller/OldTaxajaxController.php b/Classes/Controller/OldTaxajaxController.php new file mode 100755 index 000000000..c7b9dfced --- /dev/null +++ b/Classes/Controller/OldTaxajaxController.php @@ -0,0 +1,109 @@ + + * @author Franz Holzinger + * @maintainer Franz Holzinger + * @package TYPO3 + * @subpackage tt_products + * + * + */ + +use TYPO3\CMS\Core\Utility\GeneralUtility; + + + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; + + + +class OldTaxajaxController { + + /** + * @param ServerRequestInterface $request + * @param ResponseInterface $response + * @return ResponseInterface + */ + public function processRequest ( + ServerRequestInterface $request, + ResponseInterface $response): ResponseInterface + { + global $TSFE, $BE_USER, $TYPO3_CONF_VARS, $error; + + $pageId = ''; + if ( + defined('TYPO3_version') && + version_compare(TYPO3_version, '9.0.0', '>=') + ) { + $pageId = \JambageCom\Div2007\Utility\FrontendUtility::getPageId($request); + if (!$pageId) { + throw new \RuntimeException('Error in tt_products: No page id for Ajax call.'); + } + } + + \JambageCom\Div2007\Utility\FrontendUtility::init($pageId); + + // ****************************************************** + // Start with tt_products + // ****************************************************** + + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.']; + $config = array(); + $config['LLkey'] = ''; + + // tt_products specific parts + + // Make instance: + $ajax = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_ttproducts_ajax'); + $ajax->init(); + + $SOBE = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_ttproducts_db'); + $errorCode = ''; + $SOBE->init($conf, $config, $ajax, $tmp = '', $errorCode); + + if($_POST['xajax']) { + $ajax->taxajax->processRequests(); + $SOBE->destruct(); + exit(); + } + $SOBE->main(); + $SOBE->printContent(); + $SOBE->destruct(); + return $response; + } +} + diff --git a/Classes/Controller/TaxajaxController.php b/Classes/Controller/TaxajaxController.php index bfa3c2d3b..05d0388c7 100755 --- a/Classes/Controller/TaxajaxController.php +++ b/Classes/Controller/TaxajaxController.php @@ -42,13 +42,14 @@ * */ -use TYPO3\CMS\Core\Utility\GeneralUtility; - use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Core\Http\NullResponse; +use TYPO3\CMS\Core\Utility\GeneralUtility; + class TaxajaxController { @@ -59,27 +60,20 @@ class TaxajaxController { * @return ResponseInterface */ public function processRequest ( - ServerRequestInterface $request, - ResponseInterface $response): ResponseInterface + ServerRequestInterface $request + ) { global $TSFE, $BE_USER, $TYPO3_CONF_VARS, $error; - $pageId = ''; - if ( - defined('TYPO3_version') && - version_compare(TYPO3_version, '9.0.0', '>=') - ) { - $pageId = \JambageCom\Div2007\Utility\FrontendUtility::getPageId($request); - if (!$pageId) { - throw new \RuntimeException('Error in tt_products: No page id for Ajax call.'); - } + $pageId = \JambageCom\Div2007\Utility\FrontendUtility::getPageId($request); + if (!$pageId) { + throw new \RuntimeException('Error in tt_products: No page id for Ajax call.'); } - \JambageCom\Div2007\Utility\FrontendUtility::init($pageId); - // ****************************************************** // Start with tt_products // ****************************************************** + $GLOBALS['TSFE']->getConfigArray($request); $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.']; $config = array(); @@ -103,7 +97,8 @@ public function processRequest ( $SOBE->main(); $SOBE->printContent(); $SOBE->destruct(); - return $response; + + return new NullResponse(); } } diff --git a/control/class.tx_ttproducts_javascript.php b/control/class.tx_ttproducts_javascript.php index fda025503..c4d1f58a7 100755 --- a/control/class.tx_ttproducts_javascript.php +++ b/control/class.tx_ttproducts_javascript.php @@ -495,7 +495,7 @@ function doFetchRow(table, view, uid) { \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(TAXAJAX_EXT) ); } else { - $path = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath(TAXAJAX_EXT)); + $path = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath(TAXAJAX_EXT); } $code = $this->ajax->taxajax->getJavascript($path); diff --git a/eid/class.tx_ttproducts_db.php b/eid/class.tx_ttproducts_db.php index 37745985f..1b6bb0c93 100755 --- a/eid/class.tx_ttproducts_db.php +++ b/eid/class.tx_ttproducts_db.php @@ -183,7 +183,6 @@ public function fetchRow ($data) { $priceTaxArray = $priceObj->getPriceTaxArray( $this->conf['discountPriceMode'], $basketExtra, 'price', tx_ttproducts_control_basket::getRoundFormat(), tx_ttproducts_control_basket::getRoundFormat('discount'), $tmpRow, $totalDiscountField, $priceTaxArray); - $csConvObj = $GLOBALS['TSFE']->csConvObj; $field = 'price'; foreach ($priceTaxArray as $priceKey => $priceValue) { $displayTax = $priceViewObj->convertKey($priceKey, $field); @@ -230,10 +229,7 @@ public function fetchRow ($data) { return $rc; } - protected function generateResponse ($view, &$rowArray, $rowArticle, &$variantArray) { - $csConvObj = $GLOBALS['TSFE']->csConvObj; - $theCode = strtoupper($view); $languageObj = GeneralUtility::makeInstance(\JambageCom\TtProducts\Api\Localization::class); $imageObj = GeneralUtility::makeInstance('tx_ttproducts_field_image'); diff --git a/ext_localconf.php b/ext_localconf.php index 06741d231..bdad021f3 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -155,13 +155,12 @@ if ( version_compare(TYPO3_version, '9.5.0', '<') ) { - $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][TT_PRODUCTS_EXT] = \JambageCom\TtProducts\Controller\TaxajaxController::class . '::processRequest'; + $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][TT_PRODUCTS_EXT] = \JambageCom\TtProducts\Controller\OldTaxajaxController::class . '::processRequest'; } else { $GLOBALS['TYPO3_CONF_VARS']['FE']['taxajax_include'][TT_PRODUCTS_EXT] = \JambageCom\TtProducts\Controller\TaxajaxController::class . '::processRequest'; } } - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig('options.saveDocNew.tt_products=1'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig( 'options.saveDocNew.tt_products_language=1'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig('options.saveDocNew.tt_products_cat=1');