diff --git a/Classes/Api/ActivityApi.php b/Classes/Api/ActivityApi.php index 2356834a1..af00504d3 100644 --- a/Classes/Api/ActivityApi.php +++ b/Classes/Api/ActivityApi.php @@ -42,6 +42,7 @@ use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; + class ActivityApi implements SingletonInterface { protected $subActivity = '0'; @@ -217,7 +218,8 @@ public function fixCountry($infoObj, $basketExtra, $conf): void ) { $overwrite = ControlApi::isOverwriteMode($infoArray); - $needsDeliveryAddress = \tx_ttproducts_control_basket::needsDeliveryAddresss($basketExtra); + $needsDeliveryAddress = + \tx_ttproducts_control_basket::needsDeliveryAddresss($basketExtra); $infoObj->mapPersonIntoDelivery( $basketExtra, $overwrite, diff --git a/Classes/Api/BasketApi.php b/Classes/Api/BasketApi.php index 3c5bd8dde..8ebd9f5b2 100644 --- a/Classes/Api/BasketApi.php +++ b/Classes/Api/BasketApi.php @@ -1,33 +1,34 @@ -* All rights reserved -* -* This script is part of the Typo3 project. The Typo3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ + * Copyright notice + * + * (c) 2020 Franz Holzinger + * All rights reserved + * + * This script is part of the Typo3 project. The Typo3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * A copy is found in the textfile GPL.txt and important notices to the license + * from the author is found in LICENSE.txt distributed with these scripts. + * + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ /** * Part of the tt_products (Shop System) extension. * @@ -38,21 +39,66 @@ * @package TYPO3 * @subpackage tt_products */ +use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; -use JambageCom\Div2007\Utility\TableUtility; - +use JambageCom\TtProducts\SessionHandler\SessionHandler; class BasketApi implements SingletonInterface { protected $basketExt = []; // "Basket Extension" - holds extended attributes - protected $basketExtra = []; // initBasket() uses this for additional information + protected $basketExtra = []; // initBasket() uses this for additional information like the current payment/shipping methods + + public function getBasketCount( + $row, + $basketExt, + $variant, + $quantityIsFloat, + $ignoreVariant = false + ) { + $count = ''; + $uid = $row['uid']; - public static function getQuantity($content, $basketConf) + if ( + isset($basketExt) && + is_array($basketExt) && + isset($basketExt[$uid]) && + is_array($basketExt[$uid]) + ) { + $subArr = $basketExt[$uid]; + if ( + $ignoreVariant + ) { + $count = 0; + foreach ($subArr as $subVariant => $subCount) { + $count += $subCount; + } + } elseif ( + isset($subArr[$variant]) + ) { + $tmpCount = $subArr[$variant]; + if ( + $tmpCount > 0 && + ( + $quantityIsFloat || + MathUtility::canBeInterpretedAsInteger($tmpCount) + ) + ) { + $count = $tmpCount; + } + } + } + + return $count; + } + + public function getQuantity($content, $basketConf) { $count = ''; - $basketExt = \tx_ttproducts_control_basket::getStoredBasketExt(); + $basketExt = $this->readBasketExt(); if ( isset($basketExt) && @@ -61,17 +107,22 @@ public static function getQuantity($content, $basketConf) isset($basketConf['ref']) && isset($basketConf['row']) ) { - $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + } $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $cnfObj->init( $conf, [] ); - $cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer'); // Local cObj. - $cObj->start([]); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - $uid = intval($basketConf['ref']); $row = $basketConf['row']; $variant = ''; @@ -83,99 +134,56 @@ public static function getQuantity($content, $basketConf) ) { $variant = $basketConf['variant']; } else { - $funcTablename = 'tt_products'; - $productTable = $tablesObj->get($funcTablename); + $variantApi = GeneralUtility::makeInstance(VariantApi::class); $variantRow = - $productTable->variant->getVariantRow($row, []); + $variantApi->getVariantRow($row, []); $variant = - $productTable->variant->getVariantFromProductRow( - $row, - $variantRow, - $useArticles - ); + $variantApi->getVariantFromProductRow( + $row, + $variantRow, + $useArticles + ); } - \tx_ttproducts_control_basket::init( - $conf, - $tablesObj, - $conf['pid_list'], - $useArticles - ); - $count = - \tx_ttproducts_control_basket::getBasketCount( - $row, - $variant, - $conf['quantityIsFloat'] - ); - \tx_ttproducts_control_basket::destruct(); + $this->getBasketCount( + $row, + $basketExt, + $variant, + $conf['quantityIsFloat'] + ); } return $count; } - /** - * get the product rows contained in the basket. - */ - public static function getRecords($conf, $where = '1=1') + public function getTotalQuantity() { - $result = false; - - $funcTablename = 'tt_products'; - $recs = \tx_ttproducts_control_basket::getRecs(); - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - - $pid_list = $conf['pid_list']; - \tx_ttproducts_control_basket::init($conf, $tablesObj, $pid_list, $conf['useArticles'], $recs); - $basketExt = $this->getBasketExt(); - - if (isset($basketExt) && is_array($basketExt)) { - $uidArr = []; - - foreach ($basketExt as $uidTmp => $tmp) { - if ($uidTmp != 'gift' && !in_array($uidTmp, $uidArr)) { - $uidArr[] = intval($uidTmp); - } - } - - if (count($uidArr) == 0) { - return false; - } - // $where .= ' AND uid IN (' . implode(',', $uidArr) . ')'; - $where .= ' AND uid IN (' . implode(',', $uidArr) . ')' . ($pid_list != '' ? ' AND pid IN (' . $pid_list . ')' : '') . TableUtility::enableFields($funcTablename); + $count = 0; + $basketExt = $this->readBasketExt(); - $rows = - $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - 'tt_products', - $where - ); - - if ( - is_array($rows) - ) { - $variant = ''; - foreach ($rows as $k => $row) { - $count = - \tx_ttproducts_control_basket::getBasketCount( - $row, - $variant, - $conf['quantityIsFloat'], - true - ); - - if ($count) { - $rows[$k]['count'] = $count; + if ( + isset($basketExt) && + is_array($basketExt) + ) { + foreach ($basketExt as $tmpUid => $tmpSubArr) { + if (is_array($tmpSubArr) && count($tmpSubArr)) { + foreach ($tmpSubArr as $tmpExtVar => $tmpCount) { + if ( + $tmpCount > 0 && + is_numeric($tmpCount) + ) { + $count += $tmpCount; + } } } } - $result = $rows; } - return $result; + return $count; } - public static function getRecordvariantAndPriceFromRows( + public function getRecordvariantAndPriceFromRows( &$variant, &$price, &$externalUidArray, @@ -198,7 +206,8 @@ public static function getRecordvariantAndPriceFromRows( } if ($externalUid) { - $variant .= '|records:dl=' . $externalUid; + $variant .= \tx_ttproducts_variant_int::EXTERNAL_RECORD_SEPARATOR + /* '|records: */ . 'dl=' . $externalUid; } $externalUidArray[$tablename] = $externalUid; break; @@ -229,11 +238,83 @@ public static function getRecordvariantAndPriceFromRows( return $result; } + /** + * get the product rows contained in the basket. + */ + public function getRecords($where = '1=1') + { + $result = false; + + $funcTablename = 'tt_products'; + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); + $pid_list = ''; + $basketExt = $this->readBasketExt(); + + if (isset($basketExt) && is_array($basketExt)) { + $uidArr = []; + + foreach ($basketExt as $uidTmp => $tmp) { + if ($uidTmp != 'gift' && !in_array($uidTmp, $uidArr)) { + $uidArr[] = intval($uidTmp); + } + } + + if (count($uidArr) == 0) { + return false; + } + $where .= ' AND uid IN (' . implode(',', $uidArr) . ')' . ($pid_list != '' ? ' AND pid IN (' . $pid_list . ')' : '') . + $pageRepository->enableFields($funcTablename); + + $rows = + $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + '*', + 'tt_products', + $where + ); + + if ( + is_array($rows) + ) { + $variant = ''; + $quantityIsFloat = false; + foreach ($rows as $k => $row) { + $count = + $this->getBasketCount( + $row, + $basketExt, + $variant, + $quantityIsFloat, + true + ); + if ($count) { + $rows[$k]['count'] = $count; + } + } + } + $result = $rows; + } + + return $result; + } + + public function getWeight($rows) + { + $totalWeight = 0; + if (is_array($rows)) { + foreach ($rows as $k => $row) { + $weight = floatval($row['weight']) * floatval($row['count']); + $totalWeight += $weight; + } + } + + return $totalWeight; + } + /** * get basket record for tracking, billing and delivery data row. */ - public static function getBasketRec( - $row, + public function getBasketRec( + array $row, $typeArray = [ 'payment', 'shipping', @@ -241,18 +322,48 @@ public static function getBasketRec( ] ) { $extraArray = []; - foreach ($typeArray as $type) { - if (!empty($row[$type])) { + if (!empty($row)) { + foreach ($typeArray as $type) { $tmpArray = GeneralUtility::trimExplode(':', $row[$type]); $extraArray[$type] = $tmpArray['0']; } } - $basketRec = ['tt_products' => $extraArray]; return $basketRec; } + public function storeItemArray(array $itemArray): void + { + SessionHandler::storeSession('itemArray', $itemArray); + } + + public function readItemArray() + { + $result = SessionHandler::readSession('itemArray'); + + return $result; + } + + public function storeCalculatedArray(array $calculatedArray): void + { + SessionHandler::storeSession('calculatedArray', $calculatedArray); + } + + public function readCalculatedArray() + { + $result = SessionHandler::readSession('calculatedArray'); + + return $result; + } + + public function readBasketExtra() + { + $result = SessionHandler::readSession('basketExtra'); + + return $result; + } + public function setBasketExt($basketExt): void { $this->basketExt = $basketExt; @@ -263,6 +374,44 @@ public function getBasketExt() return $this->basketExt; } + public function storeBasketExt(array $basketExt): void + { + SessionHandler::storeSession('basketExt', $basketExt); + $this->setBasketExt($basketExt); + } + + public function readBasketExt() + { + $result = SessionHandler::readSession('basketExt'); + + return $result; + } + + public function removeFromBasketExt($removeBasketExt): void + { + $basketExt = $this->readBasketExt(); + $bChanged = false; + + if (isset($removeBasketExt) && is_array($removeBasketExt)) { + foreach ($removeBasketExt as $uid => $removeRow) { + $allVariants = key($removeRow); + $bRemove = current($removeRow); + + if ( + $bRemove && + isset($basketExt[$uid]) && + isset($basketExt[$uid][$allVariants]) + ) { + unset($basketExt[$uid][$allVariants]); + $bChanged = true; + } + } + } + if ($bChanged) { + $this->storeBasketExt($basketExt); + } + } + public function setBasketExtra($basketExtra): void { $this->basketExtra = $basketExtra; @@ -272,4 +421,333 @@ public function getBasketExtra() { return $this->basketExtra; } + + public function storeBasketExtra(array $basketExtra): void + { + SessionHandler::storeSession('basketExtra', $basketExtra); + } + + public function storeBasketSetup(array $basketSetup): void + { + SessionHandler::storeSession('basketSetup', $basketSetup); + } + + // Use this only from Middleware. In all cases you should use $conf directly + public function readBasketSetup() + { + $result = SessionHandler::readSession('basketSetup'); + + return $result; + } + + public function addItem( + &$basketExt, + $uid, + $externalVariant, + $damUid, + $item, + $updateMode, + $bStoreBasket, + $basketMaxQuantity, + $alwaysInStock, + $alwaysUpdateOrderAmount, + $quantityIsFloat, + $useArticles + ): void { + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + $editVariantApi = GeneralUtility::makeInstance(EditVariantApi::class); + $priceObj = GeneralUtility::makeInstance('tx_ttproducts_field_price'); + + // quantities for single values are stored in an array. This is necessary because a HTML checkbox does not send any values if it has been unchecked + if ( + isset($item) && + is_array($item) && + isset($item['quantity']) && + is_array($item['quantity']) + ) { + reset($item['quantity']); + $item['quantity'] = current($item['quantity']); + } + + if ($updateMode) { + foreach ($item as $md5 => $quantity) { + $quantity = $priceObj->toNumber($quantityIsFloat, $quantity); + + if ( + isset($basketExt[$uid]) && + is_array($basketExt[$uid]) && + $md5 != 'additional' + ) { + foreach ($basketExt[$uid] as $allVariants => $tmp) { + $actMd5 = md5($allVariants); + + // useArticles if you have different prices and therefore articles for color, size, additional and gradings + if ($actMd5 == $md5) { + $count = $this->getMaxCount($quantity, $basketMaxQuantity, $alwaysInStock, $quantityIsFloat, $uid); + $basketExt[$uid][$allVariants] = $count; + + if (isset($item['additional']) && is_array($item['additional']) && + isset($item['additional'][$actMd5]['giftservice']) && is_array($item['additional'][$actMd5]['giftservice'])) { + if (isset($basketExt[$uid][$allVariants . '.']) && !is_array($basketExt[$uid][$allVariants . '.'])) { + $basketExt[$uid][$allVariants . '.'] = []; + } + + if (isset($basketExt[$uid][$allVariants . '.']['additional']) && !is_array($basketExt[$uid][$allVariants . '.']['additional'])) { + $basketExt[$uid][$allVariants . '.']['additional'] = []; + } + $bHasGiftService = $item['additional'][$actMd5]['giftservice']['1']; + if ($bHasGiftService) { + $basketExt[$uid][$allVariants . '.']['additional']['giftservice'] = '1'; + } else { + unset($basketExt[$uid][$allVariants . '.']); + } + } + } + } + } + } + } else { + if (!isset($item['quantity'])) { + return; + } + + $variant = $variantApi->getVariantFromRawRow($item, $useArticles); + $editVariant = $editVariantApi->getVariantFromRawRow($item); + $allVariants = + $variant . + ($editVariant != '' ? '|editVariant:' . $editVariant : '') . + ($externalVariant != '' ? '|records:' . $externalVariant : ''); + + if ($damUid) { + $tableVariant = $variantApi->getTableUid('tx_dam', $damUid); + $allVariants .= $tableVariant; + } + $oldcount = $basketExt[$uid][$allVariants] ?? 0; + $quantity = 0; + $quantity = $priceObj->toNumber($quantityIsFloat, $item['quantity']); + $count = $this->getMaxCount($quantity, $basketMaxQuantity, $alwaysInStock, $quantityIsFloat, $uid); + + if ($count >= 0 && $bStoreBasket) { + $newcount = $count; + + if ($newcount) { + if ($alwaysUpdateOrderAmount == 1) { + $basketExt[$uid][$allVariants] = $newcount; + } else { + $basketExt[$uid][$allVariants] = $oldcount + $newcount; + } + } else { + unset($basketExt[$uid][$allVariants]); + } + } + } + } + + public function getMaxCount($quantity, $basketMaxQuantity, $alwaysInStock, $quantityIsFloat, $uid = 0) + { + $count = 0; + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $prodTable = $tablesObj->get('tt_products'); + $row = $prodTable->get($uid); + + if ( + $row['basketmaxquantity'] > 0 && + $quantity > $row['basketmaxquantity'] + ) { + $basketmaxrowquantity = MathUtility::convertToPositiveInteger($row['basketmaxquantity']); + $count = MathUtility::forceIntegerInRange($quantity, 0, (int) $basketmaxrowquantity, 0); + $quantity = $count; // reduce the quantitiy to the product's maximum allowed quantity + } + + if ( + $basketMaxQuantity == 'inStock' && + !$alwaysInStock && + !empty($uid) + ) { + $count = MathUtility::forceIntegerInRange( + $quantity, + 0, + (int) $row['inStock'], + 0 + ); + } elseif ( + $basketMaxQuantity == 'creditpoint' && + !empty($uid) + ) { + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $creditpointsObj = GeneralUtility::makeInstance('tx_ttproducts_field_creditpoints'); + $missingCreditpoints = 0; + $creditpointsObj->getBasketMissingCreditpoints($row['creditpoints'] * $quantity, $missingCreditpoints, $tmp); + + if ($quantity > 1 && $missingCreditpoints > 0) { + $reduceQuantity = intval($missingCreditpoints / $row['creditpoints']); + if ($missingCreditpoints > $reduceQuantity * $row['creditpoints']) { + ++$reduceQuantity; + } + if ($quantity - $reduceQuantity >= 1) { + $count = $quantity - $reduceQuantity; + } else { + $count = 0; + } + } else { + $count = ($missingCreditpoints > 0 ? 0 : $quantity); + } + } elseif ($quantityIsFloat) { + $count = floatval($quantity); + if ($count < 0) { + $count = 0; + } + if ($count > $basketMaxQuantity) { + $count = $basketMaxQuantity; + } + } else { + $count = MathUtility::forceIntegerInRange($quantity, 0, (int) $basketMaxQuantity, 0); + } + + return $count; + } + + public function process( + array &$basketExt, + array $basketExtRaw, + $updateMode, + $bStoreBasket, + $basketMaxQuantity, + $alwaysInStock, + $alwaysUpdateOrderAmount, + $quantityIsFloat, + $useArticles + ): void { + $damUid = 0; + if (isset($basketExtRaw['dam'])) { + $damUid = intval($basketExtRaw['dam']); + } + + foreach ($basketExtRaw as $uid => $basketItem) { + if ( + MathUtility::canBeInterpretedAsInteger($uid) + ) { + if (isset($basketItem['quantity'])) { + if ( + isset($basketExtRaw['dam']) + ) { + foreach ($basketItem as $damUid => $damBasketItem) { + $this->addItem( + $basketExt, + $uid, + '', + $damUid, + $damBasketItem, + $updateMode, + $bStoreBasket, + $basketMaxQuantity, + $alwaysInStock, + $alwaysUpdateOrderAmount, + $quantityIsFloat, + $useArticles + ); + } + } else { + $this->addItem( + $basketExt, + $uid, + '', + $damUid, + $basketItem, + $updateMode, + $bStoreBasket, + $basketMaxQuantity, + $alwaysInStock, + $alwaysUpdateOrderAmount, + $quantityIsFloat, + $useArticles + ); + } + } else { + $addItems = false; + foreach ($basketItem as $basketKey => $basketValue) { + if ( + isset($basketValue) && + is_array($basketValue) && + isset($basketValue['quantity']) + ) { + $addItems = true; + $this->addItem( + $basketExt, + $uid, + $basketKey, + '', + $basketValue, + $updateMode, + $bStoreBasket, + $basketMaxQuantity, + $alwaysInStock, + $alwaysUpdateOrderAmount, + $quantityIsFloat, + $useArticles + ); + } + } + + if ($addItems) { + } else { + $this->addItem( + $basketExt, + $uid, + '', + '', + $basketItem, + $updateMode, + $bStoreBasket, + $basketMaxQuantity, + $alwaysInStock, + $alwaysUpdateOrderAmount, + $quantityIsFloat, + $useArticles + ); + } + } + } + } + + // I did not find another possibility to delete elements completely from a multidimensional array + // than to recreate the array + $basketExtNew = []; + foreach ($basketExt as $tmpUid => $tmpSubArr) { + if (is_array($tmpSubArr) && count($tmpSubArr)) { + foreach ($tmpSubArr as $tmpExtVar => $tmpCount) { + if ( + $tmpCount > 0 && + ( + $quantityIsFloat || + MathUtility::canBeInterpretedAsInteger($tmpCount) + ) + ) { + $basketExtNew[$tmpUid][$tmpExtVar] = $basketExt[$tmpUid][$tmpExtVar]; + if ( + isset($basketExt[$tmpUid][$tmpExtVar . '.']) && + is_array($basketExt[$tmpUid][$tmpExtVar . '.']) + ) { + $basketExtNew[$tmpUid][$tmpExtVar . '.'] = $basketExt[$tmpUid][$tmpExtVar . '.']; + } + } elseif (is_array($tmpCount)) { + $basketExtNew[$tmpUid][$tmpExtVar] = $tmpCount; + } else { + // nothing + } + } + } else { + $basketExtNew[$tmpUid] = $tmpSubArr; + } + } + $basketExt = $basketExtNew; + + if ($bStoreBasket) { + if (is_array($basketExt) && count($basketExt)) { + $this->storeBasketExt($basketExt); + } else { + $this->storeBasketExt([]); + } + } + } } diff --git a/Classes/Api/BasketItemApi.php b/Classes/Api/BasketItemApi.php new file mode 100644 index 000000000..649d2cf99 --- /dev/null +++ b/Classes/Api/BasketItemApi.php @@ -0,0 +1,125 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ +/** + * Part of the tt_products (Shop System) extension. + * + * functions for the basket item model + * + * @author Franz Holzinger + * + * @package TYPO3 + * @subpackage tt_products + */ +use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; + +class BasketItemApi implements SingletonInterface +{ + /** + * gets the quantity of an item. + * + * @param array reference to an item array with all the data of the item + * @param string overwrite amount or 'basket' + * + * @return array + * + * @access private + */ + public static function getQuantity( + &$item, + $overwriteAmount = '' + ) { + $result = $item['count']; + if ( + $overwriteAmount != 'basket' && + MathUtility::canBeInterpretedAsInteger($overwriteAmount) + ) { + $result = intval($overwriteAmount); + } + + return $result; + } + + /** + * gets the minimum necessary and maximum possible quantity of an item. + * + * @param array reference to an item array with all the data of the item + * @param string overwrite amount or 'basket' + * + * @return array + * + * @access private + */ + public static function getMinMaxQuantity( + &$minQuantity, + &$maxQuantity, + $row + ): void { + $minQuantity = $row['basketminquantity']; + $maxQuantity = $row['basketmaxquantity']; + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $prodTable = $tablesObj->get('tt_products', false); + $articleRow = $prodTable->getArticleRowFromExt($row); + + if (is_array($articleRow) && count($articleRow)) { + $minQuantity = ($articleRow['basketminquantity'] != '0.00' ? $articleRow['basketminquantity'] : $minQuantity); + $maxQuantity = ($articleRow['basketmaxquantity'] != '0.00' ? $articleRow['basketmaxquantity'] : $maxQuantity); + } + } + + public static function addMinMaxQuantities( + array &$quantityArray, + $row, + $quantity + ): void { + static::getMinMaxQuantity($minQuantity, $maxQuantity, $row); + + if ($minQuantity != '0.00' && $quantity < $minQuantity) { + $quantityArray['minimum'][] = + [ + 'rec' => $row, + 'limitQuantity' => $minQuantity, + 'quantity' => $quantity, + ]; + } + + if ($maxQuantity != '0.00' && $quantity > $maxQuantity) { + $quantityArray['maximum'][] = + [ + 'rec' => $row, + 'limitQuantity' => $maxQuantity, + 'quantity' => $quantity, + ]; + } + } +} diff --git a/Classes/Api/BasketItemViewApi.php b/Classes/Api/BasketItemViewApi.php new file mode 100644 index 000000000..644617d34 --- /dev/null +++ b/Classes/Api/BasketItemViewApi.php @@ -0,0 +1,751 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ +/** + * Part of the tt_products (Shop System) extension. + * + * functions for the basket item view + * + * @author Franz Holzinger + * + * @package TYPO3 + * @subpackage tt_products + */ +use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; +use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; + +use JambageCom\Div2007\Utility\FrontendUtility; + + +class BasketItemViewApi implements SingletonInterface +{ + public $useArticles = 0; + protected $keepNotEmpty = 1; + protected $config = [ + 'categoryHeader' => '', + 'categoryHeader.' => '', + 'PIDitemDisplay' => '', + 'PIDitemDisplay.' => '', + ]; + protected $displayBasketCatHeader = 1; + protected $viewTagArray = []; + protected $articleViewTagArray = []; + protected $damViewTagArray = []; + + + public function __construct(array $conf = []) + { + // Auskommentieren nicht möglich wenn mehrere Artikel dem Produkt zugewiesen werden + $this->keepNotEmpty = (bool) ($conf['keepProductData'] ?? 1); + foreach ($this->config as $key => $value) { + if (!empty($conf[$key])) { + $this->config[$key] = $conf[$key]; + } + } + $this->displayBasketCatHeader = ($conf['displayBasketCatHeader'] ?? 0); + } + + public function init( + array $markerFieldArray, + $itemFrameWork, + $useArticles + ): void { + $this->useArticles = $useArticles; + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); + $funcTablename = \tx_ttproducts_control_basket::getFuncTablename(); + $itemTableView = $tablesObj->get($funcTablename, true); + $itemTable = $itemTableView->getModelObj(); + + $viewTagArray = []; + $parentArray = []; + $fieldsArray = $markerObj->getMarkerFields( + $itemFrameWork, + $itemTable->getTableObj()->tableFieldArray, + $itemTable->getTableObj()->requiredFieldArray, + $markerFieldArray, + $itemTableView->getMarker(), + $viewTagArray, + $parentArray + ); + $this->setViewTagArray($viewTagArray); + + $articleViewTagArray = []; + if ( + $useArticles == 1 || + $useArticles == 3 + ) { + $articleViewObj = $tablesObj->get('tt_products_articles', true); + $articleTable = $articleViewObj->getModelObj(); + $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); + $markerFieldArray = []; + $articleParentArray = []; + $articleFieldsArray = $markerObj->getMarkerFields( + $itemFrameWork, + $itemTable->getTableObj()->tableFieldArray, + $itemTable->getTableObj()->requiredFieldArray, + $markerFieldArray, + $articleViewObj->getMarker(), + $articleViewTagArray, + $articleParentArray + ); + + $prodUidField = $cnf->getTableDesc($articleTable->getTableObj()->name, 'uid_product'); + $fieldsArray = array_merge($fieldsArray, $articleFieldsArray); + $uidKey = array_search($prodUidField, $fieldsArray); + if ($uidKey != '') { + unset($fieldsArray[$uidKey]); + } + } + $this->setArticleViewTagArray($articleViewTagArray); + + $damViewTagArray = []; + // DAM support + if (ExtensionManagementUtility::isLoaded('dam')) { + $damParentArray = []; + $damObj = $tablesObj->get('tx_dam'); + $fieldsArray = $markerObj->getMarkerFields( + $itemFrameWork, + $damObj->getTableObj()->tableFieldArray, + $damObj->getTableObj()->requiredFieldArray, + $markerFieldArray, + $damViewObj->getMarker(), + $damViewTagArray, + $damParentArray + ); + $this->setDamViewTagArray($damViewTagArray); + $damCatViewObj = $tablesObj->get('tx_dam_cat', true); + $damCatMarker = $damCatViewObj->getMarker(); + $damCatViewObj->setMarker('DAM_CAT'); + $damCatObj = $damCatViewObj->getModelObj(); + + $viewDamCatTagArray = []; + $catParentArray = []; + $catfieldsArray = $markerObj->getMarkerFields( + $itemFrameWork, + $damCatObj->getTableObj()->tableFieldArray, + $damCatObj->getTableObj()->requiredFieldArray, + $tmp = [], + $damCatViewObj->getMarker(), + $viewDamCatTagArray, + $catParentArray + ); + } + } + + public function generateItemView( + &$hiddenFields, + &$checkPriceArray, // neu + // $conf, neu + array $item, + $quantity, + $itemFrameWork, + // $useArticles, neu + $theCode, + $useBackPid, + $notOverwritePriceIfSet, // neu + $feUserRecord, // neu FHO + array $multiOrderArray, + array $productRowArray, + array $basketExtra, + array $basketRecs, + $index, + $inputEnabled, + $useHtmlFormat + ) { + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); + $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + $priceViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_price_view'); + $funcTablename = \tx_ttproducts_control_basket::getFuncTablename(); + $itemTableView = $tablesObj->get($funcTablename, true); + $itemTable = $itemTableView->getModelObj(); + $basketItemView = GeneralUtility::makeInstance('tx_ttproducts_basketitem_view'); + $checkPriceZero = true; + $urlObj = GeneralUtility::makeInstance('tx_ttproducts_url_view'); // a copy of it + $orderAddressObj = $tablesObj->get('fe_users', false); + $articleViewObj = $tablesObj->get('tt_products_articles', true); + $row = $item['rec']; + + if (!$row) { // avoid bug with missing row + return false; + } + + $extArray = $row['ext'] ?? []; + $pid = intval($row['pid']); + + if (!\tx_ttproducts_control_basket::getPidListObj()->getPageArray($pid)) { + // product belongs to another basket + return false; + } + + $copyProduct2Article = false; + + if ($this->useArticles == 0) { + if ( + strpos( + $itemFrameWork, + (string) $articleViewObj->getMarker() + ) !== false + ) { + $copyProduct2Article = true; + } + } + + $bIsNoMinPrice = $itemTable->hasAdditional($row, 'noMinPrice'); + if (!$bIsNoMinPrice) { + $checkPriceArray['minimum'] = true; + } + + $bIsNoMaxPrice = $itemTable->hasAdditional($row, 'noMaxPrice'); + + if (!$bIsNoMaxPrice) { + $checkPriceArray['maximum'] = true; + } + + // Fill marker arrays + $wrappedSubpartArray = []; + $subpartArray = []; + $markerArray = []; + + $bInputDisabled = !$useHtmlFormat || !$inputEnabled || ($row['inStock'] <= 0); + + $basketItemView->getItemMarkerArray( + $funcTablename, + false, + $item, + $markerArray, + $this->getViewTagArray(), + $hiddenFields, + $theCode, + $bInputDisabled, + $index, + false, + 'UTF-8' + ); + + $basketItemView->getItemMarkerSubpartArrays( + $itemFrameWork, + $funcTablename, + $row, + 'SINGLE', + $this->getViewTagArray(), + false, + $productRowArray, + $markerArray, + $subpartArray, + $wrappedSubpartArray + ); + + $catRow = $row['category'] ? $tablesObj->get('tt_products_cat')->get($row['category']) : []; + $catTitle = $catRow['title'] ?? ''; + $tmp = []; + + // use the product if no article row has been found + $prodVariantRow = $row; + $prodMarkerRow = $prodVariantRow; + $itemTable->tableObj->substituteMarkerArray($prodMarkerRow); + $parentProductRow = []; + + $itemTableView->getModelMarkerArray( + $prodMarkerRow, + '', + $markerArray, + $variantApi->getFieldArray(), // neu + $catTitle, + $this->getViewTagArray(), + 0, + 'basketImage', + $tmp, + $theCode, + $basketExtra, + $basketRecs, + $index, + '', + '', + '', + $useHtmlFormat, + 'UTF-8', + '', + $parentProductRow, // neu für Download + $parentFuncTablename = '', // neu für Download Object Liste + $parentRows = [], // neu für Download Object Liste + $multiOrderArray, + $productRowArray, + true, // korrigiert neu $bIsGift + $notOverwritePriceIfSet // neu + ); + + if ( + $this->useArticles == 1 || + $this->useArticles == 3 || + $copyProduct2Article + ) { + $articleTable = $articleViewObj->getModelObj(); + + $articleRows = []; + + if (!$copyProduct2Article) { + // get the article uid with these colors, sizes and gradings + if ( + is_array($extArray) && + isset($extArray['mergeArticles']) && + is_array($extArray['mergeArticles']) + ) { + $prodVariantRow = $extArray['mergeArticles']; + } elseif ( + isset($extArray[$articleTable->getFuncTablename()]) && + is_array($extArray[$articleTable->getFuncTablename()]) + ) { + $articleExtArray = $extArray[$articleTable->getFuncTablename()]; + foreach ($articleExtArray as $k => $articleData) { + $articleRows[$k] = $articleTable->get($articleData['uid']); + } + } else { + $articleRow = $itemTable->getArticleRow($row, $theCode); + if ($articleRow) { + $articleRows['0'] = $articleRow; + } + } + } + + if ( + is_array($articleRows) && + !empty($articleRows) + ) { + if ($this->useArticles == 3) { + $itemTable->fillVariantsFromArticles( + $prodVariantRow + ); + $variantApi->modifyRowFromVariant($prodVariantRow, $this->useArticles); + } + $calculationField = ''; + foreach ($articleRows as $articleRow) { + $itemTable->mergeAttributeFields( + $prodVariantRow, + $articleRow, + $this->keepNotEmpty, + true, + true, + $calculationField, + false, + true + ); + } + } else { + $variant = $variantApi->getVariantFromRow($row); + $variantApi->modifyRowFromVariant( + $prodVariantRow, + $this->useArticles, + $variant + ); + } + + $markerKeyIsDownload = '###IS_DOWNLOAD###'; + $markerKeyIsNotDownload = '###IS_NOT_DOWNLOAD###'; + + if ( + isset($extArray) && + isset($extArray['records']) && + is_array($extArray['records']) + ) { + $newTitleArray = []; + $externalRowArray = $extArray['records']; + $downloadTables = []; + $neededDownloadTables = ['tt_products_downloads', 'sys_file_reference']; + + foreach ($externalRowArray as $tablename => $externalRow) { + if ($externalRow['title']) { + $newTitleArray[] = $externalRow['title']; + } + if (in_array($tablename, $neededDownloadTables)) { + $downloadTables[$tablename] = true; + } + } + $downloadTables = array_keys($downloadTables); + $prodVariantRow['title'] = implode(' | ', $newTitleArray); + if ( + count($downloadTables) == count($neededDownloadTables) + ) { + $wrappedSubpartArray[$markerKeyIsDownload] = ''; + $subpartArray[$markerKeyIsNotDownload] = ''; + } else { + $subpartArray[$markerKeyIsDownload] = ''; + $wrappedSubpartArray[$markerKeyIsNotDownload] = ''; + } + } else { + $subpartArray[$markerKeyIsDownload] = ''; + $wrappedSubpartArray[$markerKeyIsNotDownload] = ''; + } + $prodMarkerRow = $prodVariantRow; + $itemTable->tableObj->substituteMarkerArray($prodMarkerRow); + + $parentRows = []; + $parentProductRow = []; + $parentFuncTablename = ''; + $articleViewObj->getModelMarkerArray( + $prodMarkerRow, + '', + $markerArray, + $variantApi->getFieldArray(), + $catTitle, + $this->getArticleViewTagArray(), + 0, + 'basketImage', + $tmp, + $theCode, + $basketExtra, + $basketRecs, + $index, + '', + '', + '', + $useHtmlFormat, + 'UTF-8', + '', + $parentProductRow, + $parentFuncTablename, + $parentRows, + $multiOrderArray, + $productRowArray, + false, // neu: FHO wieder zurück korrigiert, sonst wird bei Artikel Tax=0 nicht die TAXpercentage genommen. + $notOverwritePriceIfSet + ); + $articleViewObj->getItemMarkerSubpartArrays( + $itemFrameWork, + $articleViewObj->getModelObj()->getFuncTablename(), + $prodVariantRow, + $markerArray, + $subpartArray, + $wrappedSubpartArray, + $this->getArticleViewTagArray(), + [], + [], + $theCode, + $basketExtra, + $basketRecs, + $index, + $checkPriceZero, + false + ); + } + $itemTableView->getItemMarkerSubpartArrays( + $itemFrameWork, + $itemTableView->getModelObj()->getFuncTablename(), + $prodVariantRow, + $markerArray, + $subpartArray, + $wrappedSubpartArray, + $this->getViewTagArray(), + [], + [], + $theCode, + $basketExtra, + $basketRecs, + $index, + $checkPriceZero, + false + ); + + $cObj->setCurrentVal($catTitle); + $markerArray['###CATEGORY_TITLE###'] = + $cObj->cObjGetSingle( + $this->config['categoryHeader'], + $this->config['categoryHeader.'], + 'categoryHeader' + ); + $markerArray['###LINE_NO###'] = $index; + $markerArray['###PRICE_TOTAL_TAX###'] = $priceViewObj->priceFormat(($row['pricetax'] + $item['deposittax']) * $quantity); + $markerArray['###PRICE_TOTAL_NO_TAX###'] = $priceViewObj->priceFormat(($row['pricenotax'] + $item['depositnotax']) * $quantity); + $markerArray['###PRICE_TOTAL_ONLY_TAX###'] = $priceViewObj->priceFormat(($row['priceonlytax'] + ($item['deposittax'] - $item['depositnotax'])) * $quantity); + $markerArray['###PRICE_TOTAL_0_TAX###'] = $priceViewObj->priceFormat($row['oldpricetax'] * $quantity); + $markerArray['###PRICE_TOTAL_0_NO_TAX###'] = $priceViewObj->priceFormat($row['oldpricenotax'] * $quantity); + $markerArray['###PRICE_TOTAL_0_ONLY_TAX###'] = $priceViewObj->priceFormat(($row['oldpricetax'] - $row['oldpricenotax']) * $quantity); + $page = $tablesObj->get('pages'); + $pid = $page->getPID( + $this->config['PIDitemDisplay'], + $this->config['PIDitemDisplay.'], + $row, + $GLOBALS['TSFE']->rootLine[1] ?? '' + ); + + $addQueryString = []; + $addQueryString[$itemTable->type] = intval($row['uid']); + + if ( + is_array($extArray) && is_array($extArray[\tx_ttproducts_control_basket::getFuncTablename()]) + ) { + $addQueryString['variants'] = htmlspecialchars($extArray[\tx_ttproducts_control_basket::getFuncTablename()][0]['vars']); + } + $isImageProduct = $itemTable->hasAdditional($row, 'isImage'); + $damMarkerArray = []; + $damCategoryMarkerArray = []; + + if ( + ( + $isImageProduct || + $funcTablename == 'tt_products' + ) && + is_array($extArray) && + isset($extArray['tx_dam']) + ) { + reset($extArray['tx_dam']); + $damext = current($extArray['tx_dam']); + $damUid = $damext['uid']; + $damRow = $tablesObj->get('tx_dam')->get($damUid); + $damItem = []; + $damItem['rec'] = $damRow; + $damCategoryArray = + $tablesObj->get('tx_dam_cat')->getCategoryArray($damRow); + if (is_array($damCategoryArray) && count($damCategoryArray)) { + reset($damCategoryArray); + $damCat = current($damCategoryArray); + } + + $tablesObj->get('tx_dam_cat', true)->getMarkerArray( + $damCategoryMarkerArray, + $tablesObj->get('tx_dam_cat', true)->getMarker(), + $damCat, + $damRow['pid'], + $viewDamCatTagArray, + 'SINGLE', + 0, + 'basketImage', + [], + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'], + 1, + '', + '' + ); + + $tablesObj->get('tx_dam', true)->getModelMarkerArray( + $damRow, + '', + $damMarkerArray, + $variantApi->getFieldArray(), + $damCatRow['title'], + 0, + 'basketImage', + $this->getDamViewTagArray(), + $tmp, + $theCode, + $basketExtra, + $basketRecs, + $index, + '', + '', + '', + $useHtmlFormat, + 'UTF-8', + '', + [], + '', + [], + $multiOrderArray, + $productRowArray, + false, + $notOverwritePriceIfSet + ); + } + $markerArray = array_merge($markerArray, $damMarkerArray, $damCategoryMarkerArray); + + $tempUrl = + FrontendUtility::getTypoLink_URL( + $cObj, + $pid, + $urlObj->getLinkParams( + '', + $addQueryString, + true, + $useBackPid, + 0, + '' + ), + '', + [] + ); + + $css_current = ''; + $wrappedSubpartArray['###LINK_ITEM###'] = + [ + '', + '', + ]; + + if (is_object($variantApi)) { + $variantApi->removeEmptyMarkerSubpartArray( + $markerArray, + $subpartArray, + $wrappedSubpartArray, + $prodVariantRow, + // $conf, + $itemTable->hasAdditional($row, 'isSingle'), + !$itemTable->hasAdditional($row, 'noGiftService') + ); + } + + $orderAddressObj->setCondition($row, $funcTablename, $feUserRecord); + $feUserMarkerApi = GeneralUtility::makeInstance(FeUserMarkerApi::class); + + $feUserMarkerApi->getWrappedSubpartArray( + $orderAddressObj, + $this->getViewTagArray(), + $feUserRecord, + $subpartArray, + $wrappedSubpartArray + ); + + // workaround for TYPO3 bug #44270 + $tempContent = $templateService->substituteMarkerArrayCached( + $itemFrameWork, + [], + $subpartArray, + $wrappedSubpartArray + ); + + $result = $templateService->substituteMarkerArray( + $tempContent, + $markerArray + ); + + return $result; + } + + public function generateCategoryView( + &$out, + &$itemsOut, + &$currentP, + $item, + $itemFrameWork, + $categoryFrameWork, + array $calculatedArray, + $categoryQuantity + ) { + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); + $priceViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_price_view'); + $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); + + $row = $item['rec']; + if (!$row) { // avoid bug with missing row + return false; + } + $pid = intval($row['pid']); + + $pidcategory = ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'] == 1 ? $pid : ''); + $currentPnew = $pidcategory . '_' . $item['rec']['category']; + + // Print Category Title + if ($currentPnew != $currentP) { + if ($itemsOut) { + $out .= + $templateService->substituteSubpart( + $itemFrameWork, + '###ITEM_SINGLE###', + $itemsOut + ); + } + $itemsOut = ''; // Clear the item-code var + $currentP = $currentPnew; + + if ($this->displayBasketCatHeader) { + $markerArray = []; + $pageCatTitle = ''; + if ( + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'] == 1 + ) { + $page = $tablesObj->get('pages'); + $pageTmp = $page->get($pid); + $pageCatTitle = $pageTmp['title'] . '/'; + } + $catTmp = ''; + if ($item['rec']['category']) { + $catTmp = $tablesObj->get('tt_products_cat')->get($item['rec']['category']); + $catTmp = $catTmp['title'] ?? ''; + } + $catTitle = $pageCatTitle . $catTmp; + $cObj->setCurrentVal($catTitle); + $markerArray['###CATEGORY_TITLE###'] = + $cObj->cObjGetSingle( + $this->config['categoryHeader'], + $this->config['categoryHeader.'], + 'categoryHeader' + ); + + // compatible with bill/delivery + $currentCategory = $row['category']; + $markerArray['###CATEGORY_QTY###'] = $categoryQuantity[$currentCategory]; + + $categoryPriceTax = $calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$currentCategory] ?? 0; + $markerArray['###PRICE_GOODS_TAX###'] = $priceViewObj->priceFormat($categoryPriceTax); + $categoryPriceNoTax = $calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$currentCategory]; + $markerArray['###PRICE_GOODS_NO_TAX###'] = $priceViewObj->priceFormat($categoryPriceNoTax); + $markerArray['###PRICE_GOODS_ONLY_TAX###'] = $priceViewObj->priceFormat($categoryPriceTax - $categoryPriceNoTax); + + $out .= $templateService->substituteMarkerArray($categoryFrameWork, $markerArray); + } + } + } + + public function setViewTagArray($value): void + { + $this->viewTagArray = $value; + } + + public function getViewTagArray() + { + return $this->viewTagArray; + } + + public function setArticleViewTagArray($value): void + { + $this->articleViewTagArray = $value; + } + + public function getArticleViewTagArray() + { + return $this->articleViewTagArray; + } + + public function setDamViewTagArray($value): void + { + $this->damViewTagArray = $value; + } + + public function getDamViewTagArray() + { + return $this->damViewTagArray; + } +} diff --git a/Classes/Api/CreditpointsViewApi.php b/Classes/Api/CreditpointsViewApi.php new file mode 100644 index 000000000..74680d97a --- /dev/null +++ b/Classes/Api/CreditpointsViewApi.php @@ -0,0 +1,164 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ +/** + * Part of the tt_products (Shop System) extension. + * + * functions for the basket item view + * + * @author Franz Holzinger + * + * @package TYPO3 + * @subpackage tt_products + */ +use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +class CreditpointsViewApi implements SingletonInterface +{ + protected $creditsCategory = -1; + + public function __construct($conf) + { + if (isset($conf['creditsCategory'])) { + $this->creditsCategory = $conf['creditsCategory']; + } + } + + public function getItemMarkerSubpartArrays( + array $itemArray, + &$markerArray, + &$subpartArray, + &$wrappedSubpartArray, + $conf, + $priceViewObj, + $calculatedArray, + $amountCreditpoints + ): void { + $creditpointsObj = GeneralUtility::makeInstance(\tx_ttproducts_field_creditpoints::class); + $pricefactor = tx_ttproducts_creditpoints_div::getPriceFactor($conf); + $markerArray['###AMOUNT_CREDITPOINTS###'] = $amountCreditpoints; + $autoCreditpointsTotal = $amountCreditpoints; + + $sum_pricecredits_total_totunits_no_tax = 0; + $sum_price_total_totunits_no_tax = 0; + $sum_pricecreditpoints_total_totunits = 0; + $creditpoints = 0; + + // loop over all items in the basket indexed by sorting text + foreach ($itemArray as $sort => $actItemArray) { + foreach ($actItemArray as $k1 => $actItem) { + $row = $actItem['rec']; + if (!$row) { // avoid bug with missing row + continue 2; + } + $pricecredits_total_totunits_no_tax = 0; + $pricecredits_total_totunits_tax = 0; + if ($row['category'] == $this->creditsCategory) { + // creditpoint system start + $pricecredits_total_totunits_no_tax = $actItem['totalNoTax'] * ($row['unit_factor'] ?? 0); + $pricecredits_total_totunits_tax = $actItem['totalTax'] * ($row['unit_factor'] ?? 0); + } + // $markerArray['###PRICE_TOTAL_TOTUNITS_NO_TAX###'] = $priceViewObj->priceFormat($pricecredits_total_totunits_no_tax); + // $markerArray['###PRICE_TOTAL_TOTUNITS_TAX###'] = $priceViewObj->priceFormat($pricecredits_total_totunits_tax); + $sum_pricecredits_total_totunits_no_tax += $pricecredits_total_totunits_no_tax; + $sum_price_total_totunits_no_tax += $pricecredits_total_totunits_no_tax; + $sum_pricecreditpoints_total_totunits += $pricecredits_total_totunits_no_tax; + } + } + + $creditpoints = $autoCreditpointsTotal + $sum_pricecreditpoints_total_totunits * \tx_ttproducts_creditpoints_div::getCreditPoints($sum_pricecreditpoints_total_totunits, $conf['creditpoints.']); + $markerArray['###AUTOCREDITPOINTS_TOTAL###'] = number_format($autoCreditpointsTotal, 0); + $markerArray['###AUTOCREDITPOINTS_PRICE_TOTAL_TAX###'] = $priceViewObj->priceFormat($autoCreditpointsTotal * $pricefactor); + $remainingCreditpoints = 0; + $creditpointsObj->getBasketMissingCreditpoints(0, $tmp, $remainingCreditpoints); + $markerArray['###AUTOCREDITPOINTS_REMAINING###'] = number_format($remainingCreditpoints, 0); + + $markerArray['###CREDITPOINTS_AVAILABLE###'] = $amountCreditpoints; + $markerArray['###USERCREDITPOINTS_PRICE_TOTAL_TAX###'] = $priceViewObj->priceFormat(($autoCreditpointsTotal < $amountCreditpoints ? $autoCreditpointsTotal : $amountCreditpoints) * $pricefactor); + + // maximum1 amount of creditpoint to change is amount of FE user minus amount already spended in the credit-shop + $max1_creditpoints = $amountCreditpoints; + // maximum2 amount of creditpoint to change is amount bought multiplied with creditpointfactor + $max2_creditpoints = 0; + + if ($pricefactor > 0) { + $max2_creditpoints = intval(($calculatedArray['priceTax']['total']['ALL'] - $calculatedArray['priceTax']['vouchertotal']['ALL']) / $pricefactor); + } + // real maximum amount of creditpoint to change is minimum of both maximums + $markerArray['###AMOUNT_CREDITPOINTS_MAX###'] = number_format(min($max1_creditpoints, $max2_creditpoints), 0); + + // if quantity is 0 than + if ($amountCreditpoints == '0') { + $subpartArray['###SUB_CREDITPOINTS_DISCOUNT###'] = ''; + $wrappedSubpartArray['###SUB_CREDITPOINTS_DISCOUNT_EMPTY###'] = ''; + $subpartArray['###SUB_CREDITPOINTS_AMOUNT_EMPTY###'] = ''; + $subpartArray['###SUB_CREDITPOINTS_AMOUNT###'] = ''; + } else { + $wrappedSubpartArray['###SUB_CREDITPOINTS_DISCOUNT###'] = ''; + $subpartArray['###SUB_CREDITPOINTS_DISCOUNT_EMPTY###'] = ''; + $wrappedSubpartArray['###SUB_CREDITPOINTS_AMOUNT_EMPTY###'] = ''; + $wrappedSubpartArray['###SUB_CREDITPOINTS_AMOUNT###'] = ''; + } + $markerArray['###CHANGE_AMOUNT_CREDITPOINTS###'] = 'recs[tt_products][creditpoints]'; + if (empty($recs['tt_products']['creditpoints'])) { + $markerArray['###AMOUNT_CREDITPOINTS_QTY###'] = 0; + $subpartArray['###SUB_CREDITPOINTS_DISCOUNT###'] = ''; + // Added Els8: put credit_discount 0 for plain text email + $markerArray['###CREDIT_DISCOUNT###'] = '0.00'; + } else { + // quantity chosen can not be larger than the maximum amount, above calculated + if ($recs['tt_products']['creditpoints'] > min($max1_creditpoints, $max2_creditpoints)) { + $recs['tt_products']['creditpoints'] = min($max1_creditpoints, $max2_creditpoints); + } + $markerArray['###AMOUNT_CREDITPOINTS_QTY###'] = number_format($recs['tt_products']['creditpoints'], 0); + $subpartArray['###SUB_CREDITPOINTS_DISCOUNT_EMPTY###'] = ''; + $markerArray['###CREDIT_DISCOUNT###'] = $priceViewObj->priceFormat($calculatedArray['priceTax']['creditpoints']); + } + // Added els5: CREDITPOINTS_SPENDED: creditpoint needed, check if user has this amount of creditpoints on his FE user data, only if user has logged in + $markerArray['###CREDITPOINTS_SPENDED###'] = $sum_pricecredits_total_totunits_no_tax; + if ($sum_pricecredits_total_totunits_no_tax <= $amountCreditpoints) { + $subpartArray['###SUB_CREDITPOINTS_SPENDED_EMPTY###'] = ''; + $markerArray['###CREDITPOINTS_SPENDED###'] = $sum_pricecredits_total_totunits_no_tax; + // new saldo: creditpoints + $markerArray['###AMOUNT_CREDITPOINTS###'] = $amountCreditpoints - $markerArray['###CREDITPOINTS_SPENDED###']; + } else { + if (!$markerArray['###FE_USER_UID###']) { + $subpartArray['###SUB_CREDITPOINTS_SPENDED_EMPTY###'] = ''; + } else { + $markerArray['###CREDITPOINTS_SPENDED_ERROR###'] = 'Wijzig de artikelen in de kurkenshop: onvoldoende kurken op uw saldo (' . $amountCreditpoints . ') . '; // TODO + $markerArray['###CREDITPOINTS_SPENDED###'] = ' '; + } + } + $markerArray['###CREDITPOINTS_SAVED###'] = number_format($creditpoints, 0); + } +} diff --git a/Classes/Api/CustomerApi.php b/Classes/Api/CustomerApi.php index f86dad86a..012208d68 100644 --- a/Classes/Api/CustomerApi.php +++ b/Classes/Api/CustomerApi.php @@ -1,11 +1,13 @@ +* (c) 2017 Franz Holzinger * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is @@ -51,18 +53,23 @@ class CustomerApi { private static $billingInfo; private static $shippingInfo; - private static $fields = + private static string $fields = 'name,cnum,first_name,last_name,username,email,telephone,title,salutation,address,house_no,telephone,fax,email,company,city,zip,state,country,country_code,tt_products_vat,date_of_birth,tt_products_business_partner,tt_products_organisation_form'; - private static $requiredInfoFields = ''; + private static array $requiredInfoFields = []; protected static $possibleCheckFieldArray = ['name', 'last_name', 'email', 'telephone']; protected static $creditpointfields = 'tt_products_creditpoints,tt_products_vouchercode'; + protected static $feUserRecord = null; public static function init( $conf, + $feUserRecord, // neu FHO $billingRow, $deliveryRow, $basketExtra ): void { + + self::setFeUserRecord($feUserRecord); + if ( isset($basketRecs) && is_array($basketRecs) && @@ -89,6 +96,7 @@ public static function init( self::setFields($fields); $requiredInfoFieldArray = $conf['requiredInfoFields.'] ?? []; $typeArray = ['billing', 'delivery']; + $requiredInfoFields = []; foreach ($typeArray as $type) { if ( @@ -115,6 +123,16 @@ public static function init( self::setRequiredInfoFields($requiredInfoFields); } + public static function setFeUserRecord($feUserRecord) + { + self::$feUserRecord = $feUserRecord; + } + + public static function getFeUserRecord() + { + return self::$feUserRecord; + } + public static function setBillingInfo(array $value): void { if ( diff --git a/Classes/Api/DiscountApi.php b/Classes/Api/DiscountApi.php new file mode 100644 index 000000000..0db70c1d3 --- /dev/null +++ b/Classes/Api/DiscountApi.php @@ -0,0 +1,88 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ +/** + * Part of the tt_products (Shop System) extension. + * + * discount price functions + * + * @author Franz Holzinger + * + * @package TYPO3 + * @subpackage tt_products + */ +use JambageCom\Div2007\Utility\SystemUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +class DiscountApi +{ + protected static $feuserDiscountField = 'tt_products_discount'; + protected static $fegroupDiscountField = 'tt_products_discount'; + + public static function getFeuserDiscounts($feUserRecord) + { + $discountArray = []; + + $feGroupRows = SystemUtility::readFeGroupsRecords(); + + if (!empty($feGroupRows)) { + foreach ($feGroupRows as $feGroupRow) { + if ( + doubleval($feGroupRow[static::$fegroupDiscountField]) + ) { + $discountArray[] = doubleval($feGroupRow[static::$fegroupDiscountField]); + } + } + } + + if ( + isset($feUserRecord) && + !empty($feUserRecord['username']) && + + doubleval($feUserRecord[static::$feuserDiscountField]) + ) { + $discountArray[] = doubleval($feUserRecord[static::$feuserDiscountField]); + } + + return $discountArray; + } + + public static function getMaximumFeuserDiscount($feUserRecord) + { + $result = 0.0; + $discountArray = static::getFeuserDiscounts($feUserRecord); + if (!empty($discountArray)) { + $result = max($discountArray); + } + + return $result; + } +} diff --git a/Classes/Api/EditVariantApi.php b/Classes/Api/EditVariantApi.php index 25055f59d..cd0c4ba45 100644 --- a/Classes/Api/EditVariantApi.php +++ b/Classes/Api/EditVariantApi.php @@ -32,6 +32,8 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\TtProducts\Api\ParameterApi; + class EditVariantApi implements SingletonInterface { public function getFieldArray() @@ -362,7 +364,7 @@ public function getMarkerArray( } } - $ajaxFunction = \tx_ttproducts_control_basket::getAjaxVariantFunction( + $ajaxFunction = $parameterApi->getAjaxVariantFunction( $row, $funcTablename, $theCode diff --git a/Classes/Api/FeUserMarkerApi.php b/Classes/Api/FeUserMarkerApi.php index 659e46329..22d87807f 100644 --- a/Classes/Api/FeUserMarkerApi.php +++ b/Classes/Api/FeUserMarkerApi.php @@ -37,6 +37,7 @@ class FeUserMarkerApi implements SingletonInterface public function getWrappedSubpartArray( $modelObj, $viewTagArray, + $feUserRecord, array &$subpartArray, array &$wrappedSubpartArray ): void { @@ -116,7 +117,7 @@ public function getWrappedSubpartArray( if (isset($viewTagArray['FEUSER_HAS_DISCOUNT'])) { $discountApi = GeneralUtility::makeInstance(DiscountApi::class); - $discountArray = $discountApi->getFeuserDiscounts(); + $discountArray = $discountApi->getFeuserDiscounts($feUserRecord); $hasDiscount = is_array($discountArray) && (count($discountArray) > 0); if ( @@ -132,10 +133,11 @@ public function getWrappedSubpartArray( } public function getGlobalMarkerArray( - &$markerArray + &$markerArray, + $feUserRecord ): void { $discountApi = GeneralUtility::makeInstance(DiscountApi::class); - $discountValue = $discountApi->getMaximumFeuserDiscount(); + $discountValue = $discountApi->getMaximumFeuserDiscount($feUserRecord); $markerArray['###FEUSER_TOTAL_DISCOUNT###'] = $discountValue; $markerArray['###FE_USER_TT_PRODUCTS_DISCOUNT###'] = $discountValue; // deprecated -> 2025 } diff --git a/Classes/Api/ParameterApi.php b/Classes/Api/ParameterApi.php index 17f2a07c1..708105e68 100644 --- a/Classes/Api/ParameterApi.php +++ b/Classes/Api/ParameterApi.php @@ -5,30 +5,30 @@ namespace JambageCom\TtProducts\Api; /*************************************************************** -* Copyright notice -* -* (c) 2020 Franz Holzinger -* All rights reserved -* -* This script is part of the Typo3 project. The Typo3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ + * Copyright notice + * + * (c) 2020 Franz Holzinger + * All rights reserved + * + * This script is part of the Typo3 project. The Typo3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * A copy is found in the textfile GPL.txt and important notices to the license + * from the author is found in LICENSE.txt distributed with these scripts. + * + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ /** * Part of the tt_products (Shop System) extension. * @@ -39,9 +39,12 @@ * @package TYPO3 * @subpackage tt_products */ +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; + // replacement for the former class tx_ttproducts_model_control // class ParameterApi implements SingletonInterface @@ -79,6 +82,19 @@ class ParameterApi implements SingletonInterface protected $prefixId = 'tt_products'; protected $basketIntoIdPrefix = 'basket-into-id'; protected $basketInputErrorIdPrefix = 'basket-input-error-id'; + protected $request = null; + + public function setRequest( + ServerRequestInterface $request, + ): void + { + $this->request = $request; + } + + public function getRequest() + { + return $this->request; + } public function setPiVars($value): void { @@ -93,6 +109,21 @@ public function getPiVars() return $result; } + public function getParameter($param) + { + $request = $this->getRequest(); + $value = $request->getParsedBody()[$param] ?? $request->getQueryParams()[$param] ?? null; + return $value; + } + + public function getParameterMerged($param) + { + $request = $this->getRequest(); + $getMergedWithPost = $request->getQueryParams()[$param] ?? []; + ArrayUtility::mergeRecursiveWithOverrule($getMergedWithPost, $request->getParsedBody()[$param] ?? []); + return $getMergedWithPost; + } + // formerly getParamsTableArray and getParamsTable public function getParameterTable($parameter = '') { @@ -135,10 +166,12 @@ public function getTagName($uid, $fieldname) return $result; } + // neu Anfang variant public static function determineRegExpDelimiter($delimiter) { $regexpDelimiter = $delimiter; if ($delimiter == ';') { + // $regexpDelimiter = '[.semicolon.]'; // Leads to MYSQL ERROR: // Got error 'POSIX collating elements are not supported at offset 46' from regexp @@ -157,6 +190,7 @@ public static function determineRegExpDelimiter($delimiter) return $regexpDelimiter; } + // neu Ende variant public function getBasketIntoIdPrefix() { @@ -225,6 +259,8 @@ public function getAndVar($k) return $result; } + // neu Ende + public function getPointerPiVar($theCode) { $pointerParamsTableArray = $this->getPointerParamsCodeArray(); @@ -273,14 +309,13 @@ public function getControlArray() if (isset($piVars[$controlVar]) && is_array($piVars[$controlVar])) { $resultArray = $piVars[$controlVar]; } - return $resultArray; } public function getBasketExtRaw() { $basketVar = $this->getBasketVar(); - $result = GeneralUtility::_GP($basketVar); + $result = $this->getParameter($basketVar); return $result; } @@ -310,6 +345,7 @@ public function getTableConfArrays( if (isset($viewConfArray) && is_array($viewConfArray)) { $controlArray = $this->getControlArray(); + $typeArray = ['sortSelect', 'filterSelect', 'filterInput']; $typeSelectArray = ['sortSelect', 'filterSelect']; @@ -431,15 +467,17 @@ public function getWhereByFields( $fieldArray = GeneralUtility::trimExplode(',', $fields); if (isset($fieldArray) && is_array($fieldArray)) { $rcArray = []; + // neu Anfang variant $regexpDelimiter = static::determineRegExpDelimiter($delimiter); + // neu Ende variant foreach ($fieldArray as $field) { $rcArray[] = - $alias . $aliasPostfix . '.' . $field . ' REGEXP ' . - $GLOBALS['TYPO3_DB']->fullQuoteStr( - '^([[:print:]]*[' . $regexpDelimiter . '])*(' . $sword . ')([[:print:]]*[[:blank:]]*)*([' . $regexpDelimiter . '][[:print:]]*)*$', - $tablename - ); + $alias . $aliasPostfix . '.' . $field . ' REGEXP ' . + $GLOBALS['TYPO3_DB']->fullQuoteStr( + '^([[:print:]]*[' . $regexpDelimiter . '])*(' . $sword . ')([[:print:]]*[[:blank:]]*)*([' . $regexpDelimiter . '][[:print:]]*)*$', + $tablename + ); } $rc = implode(' OR ', $rcArray); } @@ -495,14 +533,14 @@ public function getSearchInfo( $delimiter = ''; $searchboxWhere = - $this->getWhereByFields( - $searchTablename, - $searchAlias, - $aliasPostfix, - $controlConfig['fields'], - $searchVars['sword'], - $delimiter - ); + $this->getWhereByFields( + $searchTablename, + $searchAlias, + $aliasPostfix, + $controlConfig['fields'], + $searchVars['sword'], + $delimiter + ); } } @@ -625,17 +663,17 @@ public function getSearchInfo( $searchboxWhereArray[] = $searchAlias . $aliasPostfix . '.' . $field . ' REGEXP ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('.*[' . $delimiter . ']*' . $positionSearchValue . '[' . $delimiter . ']*.*', $searchTablename); } $searchboxWhere = implode(' OR ', $searchboxWhereArray); - // TODO + // TODO } else { $searchboxWhere = - $this->getWhereByFields( - $searchTablename, - $searchAlias, - $aliasPostfix, - $field, - $positionSearchValue, - $delimiter - ); + $this->getWhereByFields( + $searchTablename, + $searchAlias, + $aliasPostfix, + $field, + $positionSearchValue, + $delimiter + ); } } else { if ($searchVars['query'] == 'IN') { diff --git a/Classes/Api/PaymentShippingHandling.php b/Classes/Api/PaymentShippingHandling.php index 49ac49183..040a19bd5 100644 --- a/Classes/Api/PaymentShippingHandling.php +++ b/Classes/Api/PaymentShippingHandling.php @@ -1846,7 +1846,7 @@ public static function getHandleLib($requestMode, $basketExtra) /** * Setting shipping, payment methods. */ - public static function getBasketExtras($tablesObj, $basketRec, &$conf) + public static function getBasketExtras(&$conf, $tablesObj, $basketRec, $feUserRecord) { $basketExtra = []; diff --git a/Classes/Api/PluginApi.php b/Classes/Api/PluginApi.php index 8aa9db285..01a2cd3b3 100644 --- a/Classes/Api/PluginApi.php +++ b/Classes/Api/PluginApi.php @@ -1,11 +1,13 @@ +* (c) 2018 Franz Holzinger * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is @@ -39,17 +41,20 @@ */ use Psr\EventDispatcher\EventDispatcherInterface; + use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; -use JambageCom\Div2007\Utility\ErrorUtility; use JambageCom\Div2007\Utility\ExtensionUtility; use JambageCom\Div2007\Utility\FlexformUtility; -use JambageCom\Div2007\Utility\FrontendUtility; +use JambageCom\Div2007\Utility\ErrorUtility; -use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\CustomerApi; +use JambageCom\TtProducts\Api\ParameterApi; +use JambageCom\TtProducts\View\RelatedList; abstract class RelatedProductsTypes { @@ -67,6 +72,7 @@ public static function init($conf): void $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $prefixId = $parameterApi->getPrefixId(); $defaults = $conf['_DEFAULT_PI_VARS.'] ?? ''; + if ( isset($defaults) && is_array($defaults) @@ -77,10 +83,9 @@ public static function init($conf): void $piVarsDefault = $defaults; } $parameterApi->setPiVarDefaults($piVarsDefault); - \tx_ttproducts_model_control::setPiVarDefaults($piVarsDefault); } - $piVars = GeneralUtility::_GPmerged($prefixId); + $piVars = $parameterApi->getParameterMerged($prefixId); if (!empty($piVarsDefault)) { $tmp = $piVarsDefault; @@ -96,9 +101,6 @@ public static function init($conf): void $parameterApi->setPiVars( $piVars ); - \tx_ttproducts_model_control::setPiVars( - $piVars - ); } public static function init2( @@ -145,10 +147,7 @@ public static function init2( // ### central initialization ### if (!$bRunAjax) { - $cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer'); // Local cObj. - $cObj->start([]); - - $db = GeneralUtility::makeInstance('tx_ttproducts_db'); + $db = GeneralUtility::makeInstance(\tx_ttproducts_db::class); $result = $db->init( $conf, @@ -200,6 +199,7 @@ public static function initUrl( $conf ): void { if (!isset($urlObj)) { + // FHO neu Hier Teile aus init von main hinein verschoben $urlObj = GeneralUtility::makeInstance('tx_ttproducts_url_view'); $urlObj->init($conf); } @@ -212,9 +212,10 @@ public static function initAjax( $debug ) { $result = true; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); if (ExtensionManagementUtility::isLoaded('taxajax')) { - $ajaxObj = GeneralUtility::makeInstance('tx_ttproducts_ajax'); + $ajaxObj = GeneralUtility::makeInstance(\tx_ttproducts_ajax::class); $result = $ajaxObj->init(); if (!$result) { return false; @@ -224,8 +225,8 @@ public static function initAjax( $cObj, $urlObj, $debug, - \tx_ttproducts_model_control::getPivar('tt_products'), - \tx_ttproducts_model_control::getPivar('tt_products_cat') + $parameterApi->getPivar('tt_products'), + $parameterApi->getPivar('tt_products_cat') ); } @@ -239,10 +240,14 @@ public static function initConfig( &$pageAsCategory, &$errorCode, $backPID + // $piVars ): bool { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $eInfo = ExtensionUtility::getExtensionInfo(TT_PRODUCTS_EXT); + if (!is_array($eInfo)) { + throw new \RuntimeException('Error in tt_products: Wrong file ext_emconf.php! ' . $eInfo); + } $config['version'] = $eInfo['version']; - $config['defaultCategoryID'] = FlexformUtility::get(self::getFlexform(), 'categorySelection'); // get template suffix string @@ -253,6 +258,7 @@ public static function initConfig( $templateSuffix = strtoupper($templateSuffix); $config['templateSuffix'] = ($templateSuffix ?: $config['templateSuffix']); $config['templateSuffix'] = ($config['templateSuffix'] ? '_' . $config['templateSuffix'] : ''); + $config['limit'] = $conf['limit'] ?: 50; $config['limitImage'] = MathUtility::forceIntegerInRange($conf['limitImage'], 0, 50, 1); $config['limitImage'] = $config['limitImage'] ?: 1; @@ -267,7 +273,7 @@ public static function initConfig( $config['displayCurrentRecord'] = $conf['displayCurrentRecord'] ?? ''; if ( - empty($conf['TAXmode']) || + !isset($conf['TAXmode']) || $conf['TAXmode'] == '' || $conf['TAXmode'] == '{$plugin.tt_products.TAXmode}' ) { @@ -275,17 +281,15 @@ public static function initConfig( } if ($conf['TAXmode'] < 1 || $conf['TAXmode'] > 2) { - $errorCode['0'] = 'error_range'; - $errorCode['1'] = 'TAXmode'; - $errorCode['2'] = '1'; - $errorCode['3'] = '2'; - $errorCode['4'] = $conf['TAXmode']; + $errorCode[0] = 'error_range'; + $errorCode[1] = 'TAXmode'; + $errorCode[2] = '1'; + $errorCode[3] = '2'; + $errorCode[4] = $conf['TAXmode']; return false; } - $backPID = ($backPID ?: GeneralUtility::_GP('backPID')); - $config['backPID'] = $backPID; // page where to go usually @@ -332,16 +336,25 @@ public function getRelatedProducts( $bRunAjax = false ) { $result = ''; - $pidListObj = GeneralUtility::makeInstance('tx_ttproducts_pid_list'); - $templateObj = GeneralUtility::makeInstance('tx_ttproducts_template'); + $pidListObj = GeneralUtility::makeInstance(\tx_ttproducts_pid_list::class); + $templateObj = GeneralUtility::makeInstance(\tx_ttproducts_template::class); $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $feUserRecord = CustomerApi::getFeUserRecord(); if (!self::$bHasBeenInitialised) { - $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + } + ArrayUtility::mergeRecursiveWithOverrule($conf, $pluginConf); $config = []; - $cObj = FrontendUtility::getContentObjectRenderer([]); - + $cObj = ControlApi::getCObj(); self::init2( $conf, $config, @@ -351,15 +364,18 @@ public function getRelatedProducts( ); } + $cnfObj = GeneralUtility::makeInstance(\tx_ttproducts_config::class); $uid = intval($pluginConf['ref']); + + // template' => 'ITEM_LIST_RELATED_TEMPLATE', $subtype = ''; switch ($type) { case RelatedProductsTypes::SystemCategory: $subtype = 'productsbysystemcategory'; break; default: - $errorCode['0'] = 'wrong_type'; - $errorCode['1'] = $type; + $errorCode[0] = 'wrong_type'; + $errorCode[1] = $type; return false; break; @@ -369,12 +385,11 @@ public function getRelatedProducts( $eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class); $relatedListView = GeneralUtility::makeInstance(RelatedList::class, $eventDispatcher); - $relatedListView->init( $config['pid_list'], $config['recursive'] ); - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $tablesObj = GeneralUtility::makeInstance(\tx_ttproducts_tables::class); $itemViewObj = $tablesObj->get($funcTablename, true); $itemObj = $itemViewObj->getModelObj(); @@ -382,44 +397,62 @@ public function getRelatedProducts( $relatedListView->getAddListArray( $theCode, $funcTablename, - $itemViewObj->getMarker(), + // $itemViewObj->getMarker(), $uid, $conf['useArticles'] ?? 3 ); + $funcArray = $addListArray[$subtype] ?? []; $pid = $GLOBALS['TSFE']->id; $paramUidArray['product'] = $uid; $relatedItemObj = $itemObj; - $parentFuncTablename = ''; - + $recordFuncTablename = ''; if ( !empty($funcArray) && $funcTablename != $funcArray['funcTablename'] ) { $relatedItemObj = $tablesObj->get($funcArray['funcTablename'], false); - $parentFuncTablename = $funcArray['funcTablename']; + $recordFuncTablename = $funcArray['funcTablename']; + } + $recordParentFuncTablename = ''; + if (isset($funcArray['parentFunctablename'])) { + $recordParentFuncTablename = $funcArray['parentFunctablename']; + } + $fieldName = ''; + if (isset($funcArray['fieldName'])) { + $fieldName = $funcArray['fieldName']; } + + $tableWhere = ''; + if (isset($funcArray['where'])) { + $tableWhere = $funcArray['where']; + } + $tableConf = $relatedItemObj->getTableConf($funcArray['code']); $orderBy = ''; if (isset($tableConf['orderBy'])) { $orderBy = $tableConf['orderBy']; } - $mergeRow = []; - $parentRows = []; + $rows = []; $relatedIds = - $itemObj->getRelated( - $parentFuncTablename, - $parentRows, + DatabaseTableApi::getRelated( + $rows, + $cnfObj->getTableName($funcTablename), + $cnfObj->getTableName($recordParentFuncTablename), + $cnfObj->getTableName($recordFuncTablename), + $fieldName, + $tableWhere, $multiOrderArray = [], $uid, $subtype, + $funcArray['mm'], $orderBy ); if (!empty($relatedIds)) { - $listView = GeneralUtility::makeInstance('tx_ttproducts_list_view'); + $listView = GeneralUtility::makeInstance(\tx_ttproducts_list_view::class); $listView->init( $pid, $paramUidArray, @@ -441,6 +474,7 @@ public function getRelatedProducts( $errorCode ); $notOverwritePriceIfSet = false; + $callFunctableArray = ''; $tmpContent = $listView->printView( $templateCode, @@ -450,17 +484,18 @@ public function getRelatedProducts( $listPids, '', $errorCode, - $funcArray['template'] . $config['templateSuffix'], $pageAsCategory, + $feUserRecord, + $funcArray['template'] . $config['templateSuffix'], $basketApi->getBasketExtra(), - \tx_ttproducts_control_basket::getRecs(), + $parameterApi->getRecs(), $mergeRow, 1, $callFunctableArray, $parentDataArray, $parentProductRow, $parentFuncTablename, - $parentRows, + $rows, $notOverwritePriceIfSet, $multiOrderArray, $productRowArray, diff --git a/Classes/Controller/ActivityController.php b/Classes/Controller/ActivityController.php index 417eacb8f..53b740e6c 100644 --- a/Classes/Controller/ActivityController.php +++ b/Classes/Controller/ActivityController.php @@ -164,7 +164,7 @@ protected function processPayment( if ($orderUid) { $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $infoViewObj = GeneralUtility::makeInstance('tx_ttproducts_info_view'); $cObj = ControlApi::getCObj(); $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); @@ -295,7 +295,7 @@ class_exists($callingClassName) && !$finalize && $localTemplateCode != '' ) { - $content = $basketView->getView( + $content = $basketViewObj->getView( $errorCode, $localTemplateCode, 'PAYMENT', @@ -506,7 +506,7 @@ public function getContent( $hiddenFields = ''; $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $basketApi = GeneralUtility::makeInstance(BasketApi::class); - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); $subpartmarkerObj = GeneralUtility::makeInstance('tx_ttproducts_subpartmarker'); @@ -518,6 +518,7 @@ public function getContent( $conf = $cnf->getConf(); $config = $cnf->getConfig(); $paymentScript = false; + $feUserRecord = CustomerApi::getFeUserRecord(); if ($checkBasket && !$basketEmpty) { $basketConf = $cnf->getBasketConf('minPrice'); // check the basket limits @@ -606,6 +607,7 @@ public function getContent( $feUserMarkerApi->getWrappedSubpartArray( $orderAddressObj, $viewTagArray, + $feUserRecord, $feuserSubpartArray, $feuserWrappedSubpartArray ); @@ -645,7 +647,7 @@ public function getContent( } $basketMarkerArray = - $basketView->getMarkerArray( + $basketViewObj->getMarkerArray( $basketExtra, $calculatedArray, $taxArray @@ -729,11 +731,12 @@ public function getContent( [] ); $mainMarkerArray['###FORM_URL_NEXT_ACTIVITY###'] = $nextUrl; - $paymentHTML = $basketView->getView( + $paymentHTML = $basketViewObj->getView( $errorCode, $templateCode, $theCode, $infoViewObj, + $feUserRecord, $activityArray['products_info'] ?? false, false, $calculatedArray, @@ -820,6 +823,7 @@ public function getContent( $paymentHTML, 0, $basketExtra, + $feUserRecord, $basketObj->getCalculatedArray(), $infoObj, $cardObj->getUid(), @@ -868,7 +872,6 @@ public function getContent( $accountRequired, $paymentErrorMsg ); - $markerArray['###ERROR_DETAILS###'] = $label; $markerArray['###FORM_NAME###'] = 'ErrorForm'; $finalize = false; @@ -923,7 +926,7 @@ public function processActivities( $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $infoViewObj = GeneralUtility::makeInstance('tx_ttproducts_info_view'); $infoObj = GeneralUtility::makeInstance('tx_ttproducts_info'); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); @@ -936,6 +939,7 @@ public function processActivities( $gateway = GeneralUtility::makeInstance(PaymentGatewayApi::class); $conf = $cnf->getConf(); $config = $cnf->getConfig(); + $feUserRecord = CustomerApi::getFeUserRecord(); if ( count($codes) < 2 && @@ -1546,7 +1550,7 @@ class_exists($callingClassName) && $usedCreditpoints = 0; if (isset($_REQUEST['recs'])) { - $usedCreditpoints = \tx_ttproducts_creditpoints_div::getUsedCreditpoints($_REQUEST['recs']); + $usedCreditpoints = \tx_ttproducts_creditpoints_div::getUsedCreditpoints($feUserRecord, $_REQUEST['recs']); } if ( $theCode != 'FINALIZE' && @@ -1570,6 +1574,7 @@ class_exists($callingClassName) && // $this->funcTablename, neu $orderUid, $orderArray, + $feUserRecord, $productRowArray, $alwaysInStock, $conf['useArticles'] ?? 3, @@ -1586,11 +1591,12 @@ class_exists($callingClassName) && ($conf['PIDthanks'] == $GLOBALS['TSFE']->id) ) { $tmpl = 'BASKET_ORDERTHANKS_TEMPLATE'; - $contentTmpThanks = $basketView->getView( + $contentTmpThanks = $basketViewObj->getView( $errorCode, $templateCode, $theCode, $infoViewObj, + $feUserRecord, false, false, $calculatedArray, @@ -1616,11 +1622,12 @@ class_exists($callingClassName) && $content = ''; } $content .= $contentTmp; - $contentNoSave = $basketView->getView( + $contentNoSave = $basketViewObj->getView( $errorCode, $templateCode, $theCode, $infoViewObj, + $feUserRecord, false, false, $calculatedArray, @@ -1705,7 +1712,7 @@ class_exists($callingClassName) && /** * Do all the things to be done for this activity - * former functions products_basket and basketView::printView + * former functions products_basket and basketViewObj::printView * Takes care of basket, address info, confirmation and gate to payment * Also the 'products_...' script parameters are used here. * @@ -1723,14 +1730,16 @@ public function doProcessing( ) { $content = ''; $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); - $basketView->init( + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $infoObj = GeneralUtility::makeInstance('tx_ttproducts_info'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj->init( $this->useArticles, $this->urlArray ); $activityApi = GeneralUtility::makeInstance(ActivityApi::class); $conf = $cnf->getConf(); - $infoArray = \tx_ttproducts_control_basket::getInfoArray(); + $infoArray = $infoObj->getInfoArray(); $activityArray = $activityApi->getActivityArray(); \tx_ttproducts_control_basket::uncheckAgb( $infoArray, @@ -1749,7 +1758,7 @@ public function doProcessing( $basketExt, $codes, $addressArray - ); + ); } if ( diff --git a/control/class.tx_ttproducts_control_creator.php b/Classes/Controller/Base/Creator.php similarity index 73% rename from control/class.tx_ttproducts_control_creator.php rename to Classes/Controller/Base/Creator.php index 4ed8bb697..9616725d4 100644 --- a/control/class.tx_ttproducts_control_creator.php +++ b/Classes/Controller/Base/Creator.php @@ -1,8 +1,11 @@ fileRepository; + } + public function init( - &$conf, - &$config, + array &$conf, + array &$config, $pObj, $cObj, $ajax, @@ -65,20 +82,27 @@ public function init( array $recs = [], array $basketRec = [] ): bool { + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $request = $parameterApi->getRequest(); + if (version_compare(PHP_VERSION, '8.0.0') >= 0) { $staticInfoApi = GeneralUtility::makeInstance(StaticInfoTablesApi::class); } else { $staticInfoApi = GeneralUtility::makeInstance(OldStaticInfoTablesApi::class); } - $basketApi = GeneralUtility::makeInstance(BasketApi::class); $useStaticInfoTables = $staticInfoApi->init(); if (!empty($conf['PIDstoreRoot'])) { $config['storeRootPid'] = $conf['PIDstoreRoot']; } elseif ( - ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface && - ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() + $request instanceof ServerRequestInterface + && + ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() && + isset($GLOBALS['TSFE']->tmpl->rootLine) && + is_array($GLOBALS['TSFE']->tmpl->rootLine) ) { foreach ($GLOBALS['TSFE']->tmpl->rootLine as $k => $row) { if ($row['doktype'] == 1) { @@ -101,14 +125,13 @@ public function init( ) { $conf['errorLog'] = ''; } elseif ($conf['errorLog']) { - $conf['errorLog'] = GeneralUtility::resolveBackPath(Environment::getLegacyConfigPath() . '/../' . $conf['errorLog']); + $conf['errorLog'] = GeneralUtility::resolveBackPath(Environment::getLegacyConfigPath() . '../' . $conf['errorLog']); } - $tmp = $cObj->stdWrap($conf['pid_list'] ?? '', $conf['pid_list.'] ?? ''); - $pid_list = (!empty($cObj->data['pages']) ? $cObj->data['pages'] : (!empty($conf['pid_list.']) ? trim($tmp) : '')); + $wrap = $cObj->stdWrap($conf['pid_list'] ?? '', $conf['pid_list.'] ?? ''); + $pid_list = (!empty($cObj->data['pages']) ? $cObj->data['pages'] : (!empty($conf['pid_list.']) ? trim($wrap) : '')); $pid_list = ($pid_list ?: $conf['pid_list'] ?? ''); $config['pid_list'] = ($pid_list ?? $config['storeRootPid'] ?? 0); - $recursive = (!empty($cObj->data['recursive']) ? $cObj->data['recursive'] : $conf['recursive'] ?? 99); $config['recursive'] = MathUtility::forceIntegerInRange($recursive, 0, 100); @@ -117,14 +140,13 @@ public function init( } else { $pLangObj = $this; } - $languageObj = static::getLanguageObj($pLangObj, $cObj, $conf); - $config['LLkey'] = $languageObj->getLocalLangKey(); - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $languageObj = static::getLanguageObj($pLangObj, $cObj, $conf); $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); + $piVars = $parameterApi->getPiVars(); $result = $markerObj->init( $conf, - tx_ttproducts_model_control::getPiVars() + $piVars['backPID'] ?? $parameterApi->getParameter('backPID') ); if ($result == false) { @@ -132,11 +154,15 @@ public function init( return false; } - tx_ttproducts_control_basket::init( + + $feUserRecord = $request->getAttribute('frontend.user')->user; + + \tx_ttproducts_control_basket::init( $conf, $tablesObj, $config['pid_list'], $conf['useArticles'] ?? 3, + $feUserRecord, $recs, $basketRec ); @@ -144,39 +170,66 @@ public function init( // corrections in the Setup: if ( ExtensionManagementUtility::isLoaded('voucher') && - isset($conf['gift.']['type']) && + isset($conf['gift.']) && $conf['gift.']['type'] == 'voucher' ) { $conf['table.']['voucher'] = 'tx_voucher_codes'; } + $config['LLkey'] = $languageObj->getLocalLangKey(); // $pibaseObj->LLkey; + $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $cnfObj->init( $conf, $config ); + $tableDesc = $cnfObj->getTableDesc('tt_products'); + $variantConf = ($tableDesc['variant.'] ?? []); + + $selectableArray = ''; + $selectableFieldArray = []; + $firstVariantArray = ''; + $variantApi->getParams( + $selectableArray, + $selectableFieldArray, + $firstVariantArray, + $conf, + $variantConf + ); + + $variantApi->storeVariantConf($variantConf); + $variantApi->storeSelectable($selectableArray); + $variantApi->setSelectableFieldArray($selectableFieldArray); + $variantApi->storeFirstVariant($firstVariantArray); + + $variantApi->init( + $variantConf, + $conf['useArticles'] ?? 3, + $selectableArray, + $firstVariantArray + ); ControlApi::init($conf, $cObj); - $infoArray = tx_ttproducts_control_basket::getStoredInfoArray(); + $infoArray = \tx_ttproducts_control_basket::getStoredInfoArray(); if (!empty($conf['useStaticInfoCountry'])) { - tx_ttproducts_control_basket::setCountry( + \tx_ttproducts_control_basket::setCountry( $infoArray, $basketApi->getBasketExtra() ); } - tx_ttproducts_control_basket::addLoginData( + \tx_ttproducts_control_basket::addLoginData( $infoArray, $conf['loginUserInfoAddress'] ?? 0, - $conf['useStaticInfoCountry'] ?? 0 + $conf['useStaticInfoCountry'] ?? 0, + $feUserRecord ); - tx_ttproducts_control_basket::setInfoArray($infoArray); + \tx_ttproducts_control_basket::setInfoArray($infoArray); // price $priceObj = GeneralUtility::makeInstance('tx_ttproducts_field_price'); $priceObj->init( - $cObj, $conf ); $priceViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_price_view'); @@ -186,7 +239,7 @@ public function init( // image $imageObj = GeneralUtility::makeInstance('tx_ttproducts_field_image'); - $imageObj->init($cObj); + $imageObj->init($this->fileRepository); // image view $imageViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_image_view'); @@ -206,6 +259,8 @@ public function init( $templateObj->setTemplateSuffix($config['templateSuffix']); } + $basketItemViewApi = GeneralUtility::makeInstance(BasketItemViewApi::class, $conf); + // Call all init hooks if ( isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['init']) && @@ -262,6 +317,6 @@ public static function getLanguageObj($pLangObj, $cObj, $conf) public function destruct(): void { - tx_ttproducts_control_basket::destruct(); + \tx_ttproducts_control_basket::destruct(); } } diff --git a/Classes/Hooks/ContentPostProcessor.php b/Classes/Hooks/ContentPostProcessor.php index c3f69ed10..50e1052b1 100644 --- a/Classes/Hooks/ContentPostProcessor.php +++ b/Classes/Hooks/ContentPostProcessor.php @@ -39,14 +39,18 @@ * @package TYPO3 * @subpackage tt_products */ + +use JambageCom\TtProducts\Api\ParameterApi; + class ContentPostProcessor { public function setPageTitle(&$params, TypoScriptFrontendController &$pObj): void { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; - $piVars = \tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $funcTablename = 'tt_products'; - $piVar = \tx_ttproducts_model_control::getPiVar($funcTablename); + $piVar = $parameterApi->getPiVar($funcTablename); $productUid = 0; $row = []; diff --git a/Classes/Hooks/FrontendProcessor.php b/Classes/Hooks/FrontendProcessor.php index 0f7a694f8..7699dd934 100644 --- a/Classes/Hooks/FrontendProcessor.php +++ b/Classes/Hooks/FrontendProcessor.php @@ -1,5 +1,7 @@ tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } - \tx_ttproducts_control_memo::copySession2Feuser($params, $pObj, $conf); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $feUserRecord = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user')->user; + \tx_ttproducts_control_memo::copySession2Feuser($params, $pObj, $conf, $feUserRecord); $this->resetAdresses($params, $pObj); } diff --git a/Classes/Hooks/OldStatusProvider.php b/Classes/Hooks/OldStatusProvider.php new file mode 100644 index 000000000..9fb0da622 --- /dev/null +++ b/Classes/Hooks/OldStatusProvider.php @@ -0,0 +1,60 @@ + $this->checkIfRequiredExtensionsAreInstalled(), + 'noConflictingExtensionIsInstalled' => $this->checkIfNoConflictingExtensionIsInstalled(), + 'globalVariablesAreSet' => StatusUtility::checkIfGlobalVariablesAreSet($this->getExtensionName(), $this->getGlobalVariables()), + ]; + + return $result; + } +} diff --git a/Classes/Hooks/TransactorListener.php b/Classes/Hooks/TransactorListener.php index f2611149b..7967635c3 100644 --- a/Classes/Hooks/TransactorListener.php +++ b/Classes/Hooks/TransactorListener.php @@ -1,5 +1,7 @@ loadExtensionTables(true); @@ -82,12 +86,19 @@ public function execute( $transactionRow = $params['row']; $testMode = $params['testmode']; $referenceId = $transactionRow['reference']; + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } - $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tt_products.'] ?? []; $config = []; $config['LLkey'] = ''; $errorCode = ''; - $cObj = FrontendUtility::getContentObjectRenderer( [], 'tt_products' @@ -106,10 +117,8 @@ public function execute( $where_clause = $orderTablename . '.uid=' . intval($orderUid); $where_clause .= ' AND ' . $orderTablename . '.deleted=0 AND ' . $orderTablename . '.hidden=1'; $orderRow = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $orderTablename, $where_clause); - $basketRec = $basketApi->getBasketRec($orderRow); - - $controlCreatorObj = GeneralUtility::makeInstance('tx_ttproducts_control_creator'); + $controlCreatorObj = GeneralUtility::makeInstance(Creator::class); $result = $controlCreatorObj->init( $conf, @@ -121,7 +130,6 @@ public function execute( [], $basketRec ); - if (!$result) { return false; } @@ -157,13 +165,12 @@ public function execute( $infoViewObj->init( $infoObj ); - $addressObj = $tablesObj->get('address', false); - $addressArray = $addressObj->fetchAddressArray($itemArray); + $mainMarkerArray = []; $mainMarkerArray['###MESSAGE_PAYMENT_SCRIPT###'] = ''; - + // neu Anfang FHO: Die Marker der Transactor PayPal auswerten: if ( isset($params['parameters']) && is_array($params['parameters']) && @@ -181,13 +188,14 @@ public function execute( } } + $feUserRecord = CustomerApi::getFeUserRecord(); $basketExtra = PaymentShippingHandling::getBasketExtras( + $conf, $tablesObj, $basketRec, - $conf + $feUserRecord, ); - $templateObj = GeneralUtility::makeInstance('tx_ttproducts_template'); $templateFile = ''; $errorCode = ''; @@ -205,11 +213,11 @@ public function execute( $errorMessage = ''; $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $basketView->init( + [], $conf['useArtcles'], - $errorCode, - [] + $errorCode ); - + $feUserRecord = $parameterApi->getRequest()->getAttribute('frontend.user')->user; if ($errorCode == '') { \tx_ttproducts_api::finalizeOrder( $this, @@ -218,6 +226,7 @@ public function execute( $funcTablename = 'tt_products', $orderUid, $orderRow, + $feUserRecord, $itemArray, $calculatedArray, $addressArray, diff --git a/Classes/Middleware/StoreBasket.php b/Classes/Middleware/StoreBasket.php new file mode 100644 index 000000000..4dc9cbba3 --- /dev/null +++ b/Classes/Middleware/StoreBasket.php @@ -0,0 +1,78 @@ +setRequest($request); + $basketExtRaw = $parameterApi->getBasketExtRaw(); + + if (is_array($basketExtRaw) && !empty($basketExtRaw)) { + $sessionHandler = GeneralUtility::makeInstance(SessionHandler::class); + $sessionHandler->allowCookie(); // TODO + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $basketExt = $basketApi->readBasketExt(); + $basketSetup = $basketApi->readBasketSetup(); + $variantConf = $variantApi->readVariantConf(); + $selectableArray = $variantApi->readSelectable(); + $firstVariantArray = $variantApi->readFirstVariant(); + $variantApi->init( + $variantConf, + $basketSetup['useArticles'] ?? 0, + $selectableArray, + $firstVariantArray + ); + + if (!empty($basketSetup) && is_array($variantConf)) { + $basketApi->process( + $basketExt, + $basketExtRaw, + $basketSetup['updateMode'] ?? 0, + true, + $basketSetup['basketMaxQuantity'] ?? 1000, + $basketSetup['alwaysInStock'] ?? 0, + $basketSetup['alwaysUpdateOrderAmount'] ?? 1, + $basketSetup['quantityIsFloat'] ?? 0, + $basketSetup['useArticles'] ?? 3, + $variantConf + ); + } + } + + return $handler->handle($request); + } +} diff --git a/Classes/SessionHandler/SessionHandler.php b/Classes/SessionHandler/SessionHandler.php new file mode 100644 index 000000000..c16d64ead --- /dev/null +++ b/Classes/SessionHandler/SessionHandler.php @@ -0,0 +1,47 @@ +getSessionData(); + $data[$internalKey] = $value; + $session->setSessionData($data); + $data = $session->getSessionData(); + } + + public static function readSession($internalKey = '') + { + $result = []; + $session = GeneralUtility::makeInstance(static::class); + $result = $session->getSessionData($internalKey); + + return $result; + } +} diff --git a/Classes/UserFunc/MatchCondition.php b/Classes/UserFunc/MatchCondition.php index c9e16c662..89bd80c49 100644 --- a/Classes/UserFunc/MatchCondition.php +++ b/Classes/UserFunc/MatchCondition.php @@ -1,11 +1,13 @@ getPropertyFromAspect('frontend.user', 'isLoggedIn', false); + + if ( + $isLoggedIn && + $field == 'country_code' + ) { $field = 'static_info_country'; } - $value = str_replace('\'', '', $value); - - if ($operator == '=') { - $result = ($GLOBALS['TSFE']->fe_user->user[$field] == $value); - } elseif ($operator == 'IN') { - $valueArray = GeneralUtility::trimExplode(',', $value); - $result = in_array($GLOBALS['TSFE']->fe_user->user[$field], $valueArray); - } elseif ($operator == 'NOT IN') { - $valueArray = GeneralUtility::trimExplode(',', $value); - $result = !in_array($GLOBALS['TSFE']->fe_user->user[$field], $valueArray); - } + $feUserRecord = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user')->user; + $result = $feUserRecord[$field]; } } @@ -122,9 +102,18 @@ public function checkShipping( public function hasBulkilyItem($params) { - $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } - $rcArray = BasketApi::getRecords($conf); + $rcArray = $basketApi->getRecords(); $bBukily = false; foreach ($rcArray as $uid => $row) { @@ -134,8 +123,6 @@ public function hasBulkilyItem($params) } } - \tx_ttproducts_control_basket::destruct(); - return $bBukily; } @@ -143,14 +130,13 @@ public function checkWeight( $params ) { $result = false; - $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? []; - - $rcArray = BasketApi::getRecords($conf); - $weight = BasketApi::getWeight($rcArray); + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $rcArray = $basketApi->getRecords(); + $weight = $basketApi->getWeight($rcArray); if ( - $weight >= floatval($params['0']) && - $weight <= floatval($params['1']) + $weight >= floatval($params[0]) && + $weight <= floatval($params[1]) ) { $result = true; } diff --git a/Classes/View/Bill.php b/Classes/View/Bill.php new file mode 100644 index 000000000..2c9cad042 --- /dev/null +++ b/Classes/View/Bill.php @@ -0,0 +1,150 @@ + + * + * @maintainer Franz Holzinger + * + * @package TYPO3 + * @subpackage tt_products + */ +use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +class Bill implements SingletonInterface +{ + /** + * generates the bill as a PDF file. + * + * @param string reference to an item array with all the data of the item + * + * @return string / boolean returns the absolute filename of the PDF bill or false + * for the tt_producst record, $row + * + * @access private + */ + public function generate( + $cObj, + $basketView, + $infoViewObj, + $templateCode, + $mainMarkerArray, + $itemArray, + $calculatedArray, + $orderArray, + $productRowArray, + $basketExtra, + $basketRecs, + $feUserRecord, // neu FHO + $typeCode, + $generationConf, + $absFileName, + $useArticles, // neu + $theCode // neu + ) { + $result = false; + + $infoArray = $infoViewObj->getInfoArray(); + + if ( + !empty($itemArray) && + !empty($infoArray) && + isset($generationConf['handleLib']) + ) { + switch (strtoupper($generationConf['handleLib'])) { + case 'PHPWORD': + $phpWord = + GeneralUtility::makeInstance( + PhpWord::class + ); + $result = + $phpWord->generate( + $basketView, + $infoViewObj, + $templateCode, + $mainMarkerArray, + $itemArray, + $calculatedArray, + $orderArray, + $productRowArray, + $basketExtra, + $basketRecs, + $feUserRecord, + $typeCode, + $generationConf, + $absFileName, + $useArticles, + $theCode + ); + break; + default: + // Hook + // Call all billing delivery hooks + if ( + isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['bill']) && + is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['bill']) + ) { + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['bill'] as $classRef) { + $hookObj = GeneralUtility::makeInstance($classRef); + + if (method_exists($hookObj, 'generate')) { + $result = $hookObj->generate( + $basketView, + $infoViewObj, + $templateCode, + $mainMarkerArray, + $itemArray, + $calculatedArray, + $orderArray, + $productRowArray, + $basketExtra, + $basketRecs, + $typeCode, + $generationConf, + $absFileName, + $useArticles, + $theCode + ); + } + } + } + break; + } + } + + return $result; + } +} diff --git a/Classes/View/RelatedList.php b/Classes/View/RelatedList.php new file mode 100644 index 000000000..36f40f79e --- /dev/null +++ b/Classes/View/RelatedList.php @@ -0,0 +1,408 @@ + + * + * @maintainer Franz Holzinger + * + * @package TYPO3 + * @subpackage tt_products + */ + +use Psr\EventDispatcher\EventDispatcherInterface; + +use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +use JambageCom\Div2007\Utility\FrontendUtility; + +use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\CustomerApi; +use JambageCom\TtProducts\Api\ParameterApi; +use JambageCom\TtProducts\Event\AddRelatedListEvent; + + +class RelatedList implements SingletonInterface +{ + public $pidListObj; + + /** + * Constructor. + */ + public function __construct( + private readonly EventDispatcherInterface $eventDispatcher, + ) + { + } + + public function init($pid_list, $recursive): void + { + $this->pidListObj = GeneralUtility::makeInstance('tx_ttproducts_pid_list'); + $this->pidListObj->applyRecursive($recursive, $pid_list, true); + $this->pidListObj->setPageArray(); + } + + public function getListUncachedMarkerArray( + $uid, + $conf, + $funcTablename, + $viewTagArray + ) { + $result = []; + + if ( + $funcTablename == 'tt_products' && + isset($conf['LISTRELATEDBYSYSTEMCATEGORY']) && + isset($conf['LISTRELATEDBYSYSTEMCATEGORY.']) && + isset($conf['LISTRELATEDBYSYSTEMCATEGORY.']['userFunc']) + ) { + if (isset($viewTagArray['PRODUCT_RELATED_SYSCAT'])) { + $cObjectType = $conf['LISTRELATEDBYSYSTEMCATEGORY']; + $relatedConf = $conf['LISTRELATEDBYSYSTEMCATEGORY.']; + $relatedConf['ref'] = $uid; + $relatedConf['code'] = 'LISTRELATEDBYSYSTEMCATEGORY'; + $relatedConf['userFunc'] = $conf['LISTRELATEDBYSYSTEMCATEGORY.']['userFunc']; + $cObjectType = $conf['LISTRELATEDBYSYSTEMCATEGORY']; + + $cObj = FrontendUtility::getContentObjectRenderer([]); + $output = $cObj->cObjGetSingle($cObjectType, $relatedConf); + $result['###PRODUCT_RELATED_SYSCAT###'] = $output; + } + } else { + if (isset($viewTagArray['PRODUCT_RELATED_SYSCAT'])) { + $result['###PRODUCT_RELATED_SYSCAT###'] = ''; + } + } + + return $result; + } + + public function getAddListArray( + $theCode, + $funcTablename, + $marker, + $uid, + array $paramUidArray, + $useArticles + ) { + $result = []; + $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); + $conf = $cnfObj->getConf(); + + switch ($funcTablename) { + case 'tt_products': + $result = + [ + 'articles' => [ + 'marker' => 'PRODUCT_RELATED_ARTICLES', + 'template' => 'ITEM_LIST_RELATED_ARTICLES_TEMPLATE', + 'require' => $useArticles, + 'code' => 'LISTRELATEDARTICLES', + 'additionalPages' => $conf['pidsRelatedArticles'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'tt_products_articles', + 'callFunctableArray' => [], + 'cached' => true, + ], + 'accessories' => [ + 'marker' => 'PRODUCT_ACCESSORY_UID', + 'template' => 'ITEM_LIST_ACCESSORY_TEMPLATE', + 'require' => true, + 'code' => 'LISTRELATEDACCESSORY', + 'additionalPages' => $conf['pidsRelatedAccessories'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'tt_products', + 'callFunctableArray' => [], + 'cached' => true, + ], + 'products' => [ + 'marker' => 'PRODUCT_RELATED_UID', + 'template' => 'ITEM_LIST_RELATED_TEMPLATE', + 'require' => true, + 'code' => 'LISTRELATED', + 'additionalPages' => $conf['pidsRelatedProducts'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'tt_products', + 'callFunctableArray' => [], + 'cached' => true, + ], + 'productsbysystemcategory' => [ + 'marker' => 'PRODUCT_RELATED_SYSCAT', + 'template' => 'ITEM_LIST_RELATED_BY_SYSTEMCATEGORY_TEMPLATE', + 'require' => true, + 'code' => 'LISTRELATEDBYSYSTEMCATEGORY', + 'additionalPages' => $conf['pidsRelatedProducts'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'tt_products', + 'callFunctableArray' => [], + 'cached' => false, + ], + 'complete_downloads' => [ + 'marker' => 'PRODUCT_COMPLETE_DOWNLOAD_UID', + 'template' => 'ITEM_LIST_COMPLETE_DOWNLOAD_TEMPLATE', + 'require' => true, + 'code' => 'LISTRELATEDCOMPLETEDOWNLOAD', + 'additionalPages' => $conf['pidsRelatedDownloads'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'sys_file_reference', + 'callFunctableArray' => [], + 'cached' => true, + ], + 'all_downloads' => [ + 'marker' => 'PRODUCT_ALL_DOWNLOAD_UID', + 'template' => 'ITEM_LIST_ALL_DOWNLOAD_TEMPLATE', + 'require' => true, + 'code' => 'LISTRELATEDALLDOWNLOAD', + 'additionalPages' => $conf['pidsRelatedDownloads'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'sys_file_reference', + 'callFunctableArray' => [], + 'cached' => true, + ], + 'partial_downloads' => [ + 'marker' => 'PRODUCT_PARTIAL_DOWNLOAD_UID', + 'template' => 'ITEM_LIST_PARTIAL_DOWNLOAD_TEMPLATE', + 'require' => true, + 'code' => 'LISTRELATEDPARTIALDOWNLOAD', + 'additionalPages' => $conf['pidsRelatedDownloads'] ?? '', + 'mergeRow' => [], + 'funcTablename' => 'sys_file_reference', + 'callFunctableArray' => [], + 'cached' => true, + ], + ]; + break; + + case 'tx_dam': + if (ExtensionManagementUtility::isLoaded('dam')) { + if ($uid > 0) { + $damext = ['tx_dam' => [ + ['uid' => $uid], + ], + ]; + $extArray = ['ext' => $damext]; + } else { + $extArray = []; + } + $result = + [ + 'products' => [ + 'marker' => 'DAM_PRODUCTS', + 'template' => 'DAM_ITEM_LIST_TEMPLATE', + 'require' => true, + 'code' => $theCode, + 'additionalPages' => false, + 'mergeRow' => $extArray, + 'funcTablename' => 'tt_products', + 'callFunctableArray' => [$marker => 'tx_dam'], + 'cached' => true, + ], + ]; + } + break; + } + + /** @var DoingThisAndThatEvent $event */ + $event = $this->eventDispatcher->dispatch( + new AddRelatedListEvent( + $result, + $theCode, + $funcTablename, + (int) $uid, + $paramUidArray, + (int) $useArticles + ) + ); + + $eventResult = $event->getResult(); + + if ( + isset($eventResult) && + is_array($eventResult) + ) { + $result = $eventResult; + } + + if (is_array($result)) { + foreach ($result as $subtype => $funcArray) { + $tablename = $cnfObj->getTableName($funcArray['funcTablename']); + if ($tablename == '' || !isset($GLOBALS['TCA'][$tablename]['columns'])) { + unset($result[$subtype]); // if the current TYPO3 version does not support the needed foreign table + } + } + } + + return $result; + } + + public function getListMarkerArray( + $theCode, + $templateCode, + $viewTagArray, + $funcTablename, + $uid, + array $paramUidArray, + $parentProductRow, + $notOverwritePriceIfSet, + $multiOrderArray, + $useArticles, + $pageAsCategory, + $pid, + &$error_code + ) { + $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); + $config = $cnfObj->getConfig(); + $feUserRecord = CustomerApi::getFeUserRecord(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + if (!in_array($uid, $paramUidArray)) { + $paramUidArray[] = $uid; + } + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $basketExtra = $basketApi->getBasketExtra(); + + $result = []; + $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); + $itemViewObj = $tablesObj->get($funcTablename, true); + $addListArray = + $this->getAddListArray( + $theCode, + $funcTablename, + $itemViewObj->getMarker(), + $uid, + $paramUidArray, + $useArticles + ); + + if (is_array($addListArray)) { + $listView = ''; + $itemObj = $itemViewObj->getModelObj(); + + foreach ($addListArray as $subtype => $funcArray) { + if (!$funcArray['cached']) { + continue; + } + + if (isset($viewTagArray[$funcArray['marker']]) && $funcArray['require']) { + $relatedItemObj = $itemObj; + $parentFuncTablename = ''; + if ($funcTablename != $funcArray['funcTablename']) { + $relatedItemObj = $tablesObj->get($funcArray['funcTablename'], false); + $parentFuncTablename = $funcArray['funcTablename']; + } + $tableConf = $relatedItemObj->getTableConf($funcArray['code']); + $orderBy = ''; + if (isset($tableConf['orderBy'])) { + $orderBy = $tableConf['orderBy']; + } + $mergeRow = []; + $parentRows = []; + $relatedIds = + $itemObj->getRelated( + $parentFuncTablename, + $parentRows, + $multiOrderArray, + $uid, + $subtype, + $orderBy + ); + + if (count($relatedIds)) { + // List all products: + + if (!is_object($listView)) { + $listView = GeneralUtility::makeInstance('tx_ttproducts_list_view'); + $listView->init( + $pid, + $paramUidArray, + $tmp = $this->pidListObj->getPidlist(), + 0 + ); + } + $callFunctableArray = $funcArray['callFunctableArray']; + $listPids = $funcArray['additionalPages']; + if ($listPids != '') { + $this->pidListObj->applyRecursive($config['recursive'], $listPids); + } else { + $listPids = $this->pidListObj->getPidlist(); + } + + $parentDataArray = [ + 'funcTablename' => $funcTablename, + 'uid' => $uid, + ]; + + $productRowArray = []; + $bEditableVariants = true; + + $tmpContent = $listView->printView( + $templateCode, + $funcArray['code'], + $funcArray['funcTablename'], + implode(',', $relatedIds), + $listPids, + '', + $error_code, + $funcArray['template'] . $config['templateSuffix'], + $pageAsCategory, + $feUserRecord, + $basketExtra, + \tx_ttproducts_control_basket::getRecs(), + $mergeRow, + 1, + $callFunctableArray, + $parentDataArray, + $parentProductRow, + $parentFuncTablename, + $parentRows, + $notOverwritePriceIfSet, + $multiOrderArray, + $productRowArray, + $bEditableVariants + ); + $result['###' . $funcArray['marker'] . '###'] = $tmpContent; + } else { + $result['###' . $funcArray['marker'] . '###'] = ''; + } + } else { + if (isset($viewTagArray[$funcArray['marker']])) { + $result['###' . $funcArray['marker'] . '###'] = ''; + } + } + } + } + + return $result; + } +} diff --git a/Configuration/RequestMiddlewares.php b/Configuration/RequestMiddlewares.php index 8779d67e6..44eeabba9 100644 --- a/Configuration/RequestMiddlewares.php +++ b/Configuration/RequestMiddlewares.php @@ -1,6 +1,7 @@ [ + 'jambagecom/tt-products/preprocessing' => [ + 'target' => StoreBasket::class, + 'description' => 'The basket items must be stored into the TYPO3 session at an early position, eben before the TypoScript is existent. A TypoScript condition based on the contents of the basket will then be no step behind. However only one shop is possible if you use a basket TypoScript condition.', + 'after' => [ + 'typo3/cms-frontend/tsfe', + ], + 'before' => [ + 'typo3/cms-frontend/prepare-tsfe-rendering', + ], + ], + ], ]; diff --git a/api/class.tx_ttproducts_api.php b/api/class.tx_ttproducts_api.php index 00680b510..7e5f217a4 100644 --- a/api/class.tx_ttproducts_api.php +++ b/api/class.tx_ttproducts_api.php @@ -36,7 +36,7 @@ * @package TYPO3 * @subpackage tt_products */ - +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException; use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory; @@ -367,12 +367,14 @@ public static function createFeuser( // send new user mail if (!empty($infoArray['billing']['email'])) { $empty = ''; + $feUserRecord = []; $emailContent = trim( $basketView->getView( $errorCode, $templateCode, 'EMAIL', $infoObj, + $feUserRecord, false, false, $calculatedArray, @@ -507,6 +509,7 @@ public static function finalizeOrder( $funcTablename, $orderUid, &$orderArray, + $feUserRecord, $itemArray, $calculatedArray, $addressArray, @@ -574,7 +577,7 @@ public static function finalizeOrder( CustomerApi::isSystemLoginUser( $conf ); - $defaultFromArray = $infoObj->getFromArray($customerEmail, $useLoginEmail); + $defaultFromArray = $infoObj->getFromArray($customerEmail, $useLoginEmail, $feUserRecord); $emailControlArray = $activityFinalize->getEmailControlArray( @@ -592,6 +595,7 @@ public static function finalizeOrder( $templateCode, 'EMAIL', $infoViewObj, + $feUserRecord, false, false, $calculatedArray, @@ -645,6 +649,7 @@ public static function finalizeOrder( $orderArray, $basketExtra, $basketRecs, + $feUserRecord, $type, $conf[$type . '.'] ); @@ -674,6 +679,7 @@ public static function finalizeOrder( $customerEmailHTML, 1, $basketExtra, + $feUserRecord, $calculatedArray, $infoObj, '', @@ -741,6 +747,7 @@ public static function finalizeOrder( $templateCode, 'EMAIL', $infoViewObj, + $feUserRecord, false, true, $calculatedArray, @@ -794,6 +801,7 @@ public static function finalizeOrder( if ( isset($conf['orderEmail.']) && is_array($conf['orderEmail.']) ) { + $context = GeneralUtility::makeInstance(Context::class); foreach ($conf['orderEmail.'] as $k => $emailConfig) { $suffix = strtolower($emailConfig['suffix']); if (!isset($suffix)) { @@ -802,9 +810,10 @@ public static function finalizeOrder( if ( !empty($emailConfig['to']) || - !empty($emailConfig['to.']) || + !empty($emailConfig['to.']) != '' || $suffix == 'shop' || - $suffix == 'customer' + $suffix == 'customer' || + $suffix == 'login' ) { if (!empty($emailConfig['shipping_point'])) { $shippingPoint = strtolower($emailConfig['shipping_point']); @@ -815,15 +824,14 @@ public static function finalizeOrder( if (!empty($emailConfig['to.'])) { $toConfig = $emailConfig['to.']; if ( - CompatibilityUtility::isLoggedIn() && - !empty($GLOBALS['TSFE']->fe_user->user) && - !empty($GLOBALS['TSFE']->fe_user->user['username']) && + $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && + !empty($feUserRecord['username']) && $toConfig['table'] == 'fe_users' && !empty($toConfig['field']) && !empty($toConfig['foreign_table']) && !empty($toConfig['foreign_field']) && !empty($toConfig['foreign_email_field']) && - !empty($GLOBALS['TSFE']->fe_user->user[$toConfig['field']]) + $feUserRecord[$toConfig['field']] != '' ) { $where_clause = $toConfig['foreign_table'] . '.' . @@ -1131,6 +1139,7 @@ public static function finalizeOrder( $templateCode, 'EMAIL', $infoViewObj, + $feUserRecord, false, true, $reducedCalculatedArray, @@ -1156,6 +1165,7 @@ public static function finalizeOrder( $templateCode, 'EMAIL', $infoViewObj, + $feUserRecord, false, false, $reducedCalculatedArray, @@ -1280,6 +1290,7 @@ public static function finalizeOrder( $templateCode, 'EMAIL', $infoViewObj, + $feUserRecord, false, true, $reducedCalculatedArray, @@ -1313,6 +1324,7 @@ public static function finalizeOrder( $templateCode, 'EMAIL', $infoViewObj, + $feUserRecord, false, true, $reducedCalculatedArray, diff --git a/api/class.tx_ttproducts_ts.php b/api/class.tx_ttproducts_ts.php index ccb057623..c8fa777e4 100644 --- a/api/class.tx_ttproducts_ts.php +++ b/api/class.tx_ttproducts_ts.php @@ -36,10 +36,15 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\FlexformUtility; -use JambageCom\Div2007\Utility\TableUtility; -use TYPO3\CMS\Core\SingletonInterface; + +use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; + +use JambageCom\Div2007\Utility\FlexformUtility; + +use JambageCom\TtProducts\Api\CustomerApi; +use JambageCom\TtProducts\Api\ParameterApi; class tx_ttproducts_ts implements SingletonInterface { @@ -189,4 +194,24 @@ public function processMemo(): void tx_ttproducts_control_memo::process($funcTablename, $piVars, $conf); } + + + public function processMemo(): void + { + $funcTablename = 'tt_products'; + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.'][TT_PRODUCTS_EXT . '.'] ?? null; + } + + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $piVars = $parameterApi->getParameterMerged('tt_products'); + $feUserRecord = CustomerApi::getFeUserRecord(); + tx_ttproducts_control_memo::process($feUserRecord, $funcTablename, $piVars, $conf); + } } diff --git a/control/class.tx_ttproducts_activity_finalize.php b/control/class.tx_ttproducts_activity_finalize.php index c965ad3f2..da6c19197 100644 --- a/control/class.tx_ttproducts_activity_finalize.php +++ b/control/class.tx_ttproducts_activity_finalize.php @@ -1,29 +1,32 @@ $emailConfig) { $suffix = strtolower($emailConfig['suffix']); @@ -63,31 +68,49 @@ public function getEmailControlArray( } } - if (in_array('customer', $suffixArray)) { + if ( + in_array('customer', $suffixArray) + ) { $emailControlArray = []; $emailControlArray['customer']['none']['template'] = 'EMAIL_PLAINTEXT_TEMPLATE'; // keep this on first position of the array $emailControlArray['customer']['none']['recipient'] = []; - if ($fromArray['customer']['email']) { + + if ( + isset($fromArray['customer']) && + $fromArray['customer']['email'] + ) { $emailControlArray['customer']['none']['recipient'][] = $fromArray['customer']['email']; } $templateSubpart = 'EMAIL_HTML_TEMPLATE'; - if (strpos($templateCode, '###' . $templateSubpart . '###') === false) { + if (!str_contains($templateCode, '###' . $templateSubpart . '###')) { $templateSubpart = 'BASKET_ORDERCONFIRMATION_TEMPLATE'; } $emailControlArray['customer']['none']['htmltemplate'] = $templateSubpart; - $emailControlArray['customer']['none']['from'] = $fromArray['customer']; + if (isset($fromArray['customer'])) { + $emailControlArray['customer']['none']['from'] = $fromArray['customer']; + } } if (in_array('shop', $suffixArray)) { $emailControlArray['shop']['none']['from'] = $fromArray['shop']; - if (!empty($conf['orderEmail_to'])) { + if ($conf['orderEmail_to'] != '') { // neu FHO $emailControlArray['shop']['none']['recipient'][] = $conf['orderEmail_to']; } } + if ( + in_array('login', $suffixArray) && + isset($fromArray['login']) + ) { + $emailControlArray['login']['none']['from'] = $fromArray['shop']; + if ($fromArray['login']['email']) { + $emailControlArray['login']['none']['recipient'][] = $fromArray['login']['email']; + } + } + return $emailControlArray; } @@ -96,8 +119,10 @@ public function doProcessing( $mainMarkerArray, array $subpartArray, array $wrappedSubpartArray, + // $funcTablename, neu $orderUid, &$orderArray, + $feUserRecord, $productRowArray, $bAlwaysInStock, $useArticles, @@ -105,69 +130,66 @@ public function doProcessing( $bFinalVerify, $basketExt, $usedCreditpoints, - &$errorCode, + &$errorCode, // neu &$errorMessage ) { $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); - $cnfObj->setConf('domain', '###LICENCE_DOMAIN###'); - $conf = $cnfObj->getConf(); $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $languageObj = GeneralUtility::makeInstance(Localization::class); - $orderObj = $tablesObj->get('sys_products_orders'); $basketApi = GeneralUtility::makeInstance(BasketApi::class); - - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $infoObj = GeneralUtility::makeInstance('tx_ttproducts_info'); $infoViewObj = GeneralUtility::makeInstance('tx_ttproducts_info_view'); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $funcTablename = tx_ttproducts_control_basket::getFuncTablename(); - + $conf = $cnfObj->getConf(); $customerEmail = - $infoObj->getCustomerEmail(); + $infoObj->getCustomerEmail(); $useLoginEmail = - CustomerApi::isSystemLoginUser( - $conf - ); + CustomerApi::isSystemLoginUser( + $conf + ); + $defaultFromArray = - $infoObj->getFromArray( - $customerEmail, - $useLoginEmail - ); + $infoObj->getFromArray( + $customerEmail, + $useLoginEmail, + $feUserRecord + ); $activityConf = $cnfObj->getBasketConf('activity', 'finalize'); - $basketExtra = $basketApi->getBasketExtra(); $basketRecs = tx_ttproducts_control_basket::getRecs(); - - + $cnfObj->setConf('domain', '###LICENCE_DOMAIN###'); $empty = ''; $orderConfirmationHTML = - $basketView->getView( - $errorCode, - $templateCode, - 'FINALIZE', - $infoViewObj, - false, - false, - $basketObj->getCalculatedArray(), - true, - 'BASKET_ORDERCONFIRMATION_TEMPLATE', - $mainMarkerArray, - $subpartArray, - $wrappedSubpartArray, - '', - $basketObj->getItemArray(), - $notOverwritePriceIfSet = false, - ['0' => $orderArray], - [], - $basketExtra - ); - + $basketViewObj->getView( + $errorCode, + $templateCode, + 'FINALIZE', + $infoViewObj, + $feUserRecord, + false, + false, + $basketObj->getCalculatedArray(), + true, + 'BASKET_ORDERCONFIRMATION_TEMPLATE', + $mainMarkerArray, + $subpartArray, // neu + $wrappedSubpartArray, // neu + '', + $basketObj->getItemArray(), + $notOverwritePriceIfSet = false, + ['0' => $orderArray], + [], + $basketExtra + ); $markerArray = array_merge($mainMarkerArray, $markerObj->getGlobalMarkerArray()); - $markerArray['###CUSTOMER_RECIPIENTS_EMAIL###'] = $infoObj->getCustomerEmail(); + $markerArray['###CUSTOMER_RECIPIENTS_EMAIL###'] = $customerEmail; $orderConfirmationHTML = $templateService->substituteMarkerArray( $orderConfirmationHTML, $markerArray @@ -175,20 +197,26 @@ public function doProcessing( $result = $orderConfirmationHTML; if (!$bAlwaysInStock) { - $emailControlArray = $this->getEmailControlArray($templateCode, $conf, $defaultFromArray); + $emailControlArray = + $this->getEmailControlArray( + $templateCode, + $conf, + $defaultFromArray + ); + $itemObj = $tablesObj->get($funcTablename); $instockTableArray = - $itemObj->reduceInStockItems( - $basketObj->getItemArray(), - $useArticles - ); + $itemObj->reduceInStockItems( + $basketObj->getItemArray(), + $useArticles + ); if (is_array($instockTableArray) && $conf['warningInStockLimit']) { $tableDescArray = - [ - 'tt_products' => 'product', - 'tt_products_articles' => 'article', - ]; + [ + 'tt_products' => 'product', + 'tt_products_articles' => 'article', + ]; foreach ($instockTableArray as $tablename => $instockArray) { $tableDesc = $languageObj->getLabel($tableDescArray[$tablename]); @@ -198,26 +226,27 @@ public function doProcessing( if ($count <= $conf['warningInStockLimit']) { $content = - sprintf( - $languageObj->getLabel('instock_warning'), + sprintf( + $languageObj->getLabel('instock_warning'), $tableDesc, $uidItemnrTitle[2], $uidItemnrTitle[1], intval($count) - ); + ); $subject = - sprintf( - $languageObj->getLabel('instock_warning_header'), + sprintf( + $languageObj->getLabel('instock_warning_header'), $uidItemnrTitle[2], intval($count) - ); + ); if ( isset($emailControlArray['shop']['none']['recipient']) && is_array($emailControlArray['shop']['none']['recipient']) ) { + $tmp = ''; foreach ($emailControlArray['shop']['none']['recipient'] as $key => $recipient) { - $tmp = ''; + // $headers variable removed everywhere! MailUtility::send( $recipient, $subject, @@ -242,12 +271,15 @@ public function doProcessing( } } + $infoArray = $infoObj->getInfoArray(); + $context = GeneralUtility::makeInstance(Context::class); + if ( - !empty($infoViewObj->infoArray['billing']['email']) && - !CompatibilityUtility::isLoggedIn() && + $infoArray['billing']['email'] != '' && + !$context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && ( - empty($GLOBALS['TSFE']->fe_user->user) || - empty($GLOBALS['TSFE']->fe_user->user['username']) + empty($feUserRecord) || + empty($feUserRecord['username']) ) ) { // Move the user creation in front so that when we create the order we have a fe_userid so that the order lists work. @@ -257,13 +289,14 @@ public function doProcessing( $templateCode, $conf, $infoViewObj, - $basketView, + $basketViewObj, $basketObj->getCalculatedArray(), - $defaultFromArray + $defaultFromArray ); if ($feuserUid) { - $infoViewObj->infoArray['billing']['feusers_uid'] = $feuserUid; + $infoArray['billing']['feusers_uid'] = $feuserUid; + $infoObj->setInfoArray($infoArray); } } @@ -276,11 +309,8 @@ public function doProcessing( $feuserField = 'tt_products_memoItems'; $memoItems = ''; - if ( - CompatibilityUtility::isLoggedIn() && - !empty($GLOBALS['TSFE']->fe_user->user[$feuserField]) - ) { - $memoItems = $GLOBALS['TSFE']->fe_user->user[$feuserField]; + if ($feUserRecord[$feuserField] != '') { + $memoItems = $feUserRecord[$feuserField]; } $uidArray = $basketObj->getUidArray(); if ( @@ -309,25 +339,33 @@ public function doProcessing( } if (!$bFinalVerify) { + $orderArray['order_no'] = + DatabaseTableApi::generateOrderNo( + $orderUid, + $conf['orderNumberPrefix'] + ); + tx_ttproducts_api::finalizeOrder( - $this, + $languageObj, $templateCode, - $mainMarkerArray, + $markerArray, $funcTablename, $orderUid, $orderArray, + $feUserRecord, $basketObj->getItemArray(), $basketObj->getCalculatedArray(), $addressArray, $basketExtra, $basketRecs, - $basketExt['gift'] ?? '', $usedCreditpoints, - $conf['debug'] ?? '', + $useArticles, // neu + $conf['debug'], $errorMessage ); } + $orderObj = $tablesObj->get('sys_products_orders'); $orderObj->clearUid(); return $result; diff --git a/control/class.tx_ttproducts_control_basket.php b/control/class.tx_ttproducts_control_basket.php index 93f79428c..95965085e 100644 --- a/control/class.tx_ttproducts_control_basket.php +++ b/control/class.tx_ttproducts_control_basket.php @@ -1,29 +1,32 @@ decryptIncomingFields( - $recs, - $errorCode, - $errorMessage - ); - } - - if ( - is_array($recs) - ) { - $api = GeneralUtility::makeInstance(Frontend::class); - // If any record registration is submitted, register the record. - $api->record_registration( - $recs, - 0, - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['checkCookies'] - ); - } - } public static function init( &$conf, $tablesObj, $pid_list, $useArticles, + $feUserRecord, array $recs = [], array $basketRec = [] ): void { - if (!self::$bHasBeenInitialised) { - self::setRecs($recs); - $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + + if (!static::$bHasBeenInitialised) { + static::setRecs($recs); if ( isset($GLOBALS['TSFE']) && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController ) { - $basketApi->setBasketExt(self::getStoredBasketExt()); - $basketExtra = PaymentShippingHandling::getBasketExtras($tablesObj, $recs, $conf); + $baketExt = $basketApi->readBasketExt(); + $basketApi->setBasketExt($baketExt); + $feUserRecord = CustomerApi::getFeUserRecord(); + $basketExtra = + PaymentShippingHandling::getBasketExtras( + $conf, + $tablesObj, + $recs, // Korrektur auf $basketRec?, + $feUserRecord + ); $basketApi->setBasketExtra($basketExtra); } else { - self::setRecs($recs); + static::setRecs($recs); $basketApi->setBasketExt([]); $basketApi->setBasketExtra([]); } - self::$pidListObj = GeneralUtility::makeInstance('tx_ttproducts_pid_list'); - self::$pidListObj->applyRecursive( + static::$pidListObj = GeneralUtility::makeInstance('tx_ttproducts_pid_list'); + static::$pidListObj->applyRecursive( 99, $pid_list, true ); - self::$pidListObj->setPageArray(); + static::$pidListObj->setPageArray(); if ($useArticles == 2) { $funcTablename = 'tt_products_articles'; } else { $funcTablename = 'tt_products'; } - self::setFuncTablename($funcTablename); - $recs = self::getRecs(); + static::setFuncTablename($funcTablename); + $recs = static::getRecs(); CustomerApi::init( $conf, + $feUserRecord, $recs[BasketRecsIndex::Billing] ?? '', $recs[BasketRecsIndex::Delivery] ?? '', $basketApi->getBasketExtra() ); - self::$bHasBeenInitialised = true; + static::$bHasBeenInitialised = true; } } + // FHO neu Anfang + public static function storeNewRecs($transmissionSecurity = false): void + { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $recs = $parameterApi->getParameter('recs') ?? ''; + + if ( + is_array($recs) && + $transmissionSecurity + ) { + // TODO transmission security + $errorCode = []; + $errorMessage = ''; + $security = GeneralUtility::makeInstance(TransmissionSecurity::class); + $decryptionResult = $security->decryptIncomingFields( + $recs, + $errorCode, + $errorMessage + ); + } + + if ( + is_array($recs) + ) { + $api = GeneralUtility::makeInstance(Frontend::class); + // If any record registration is submitted, register the record. + $api->record_registration( + $recs, + 0, + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['checkCookies'] + ); + } + } public static function getCmdArray() { @@ -163,32 +179,34 @@ public static function getCmdArray() public static function getPidListObj() { - return self::$pidListObj; + return static::$pidListObj; } public static function doProcessing(): void { - $piVars = tx_ttproducts_model_control::getPiVars(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $piVars = $parameterApi->getPiVars(); $basketExtModified = false; + $basketExt = $basketApi->getBasketExt(); if (isset($piVars) && is_array($piVars)) { foreach ($piVars as $piVar => $value) { switch ($piVar) { case 'delete': $uid = $value; - - $basketVar = tx_ttproducts_model_control::getBasketParamVar(); + $basketVar = $parameterApi->getBasketParamVar(); if (isset($piVars[$basketVar])) { if ( - isset(self::$basketExt[$uid]) && - is_array(self::$basketExt[$uid]) + isset($basketExt[$uid]) && + is_array($basketExt[$uid]) ) { - foreach (self::$basketExt[$uid] as $allVariants => $count) { + foreach ($basketExt[$uid] as $allVariants => $count) { if ( md5($allVariants) == $piVars[$basketVar] ) { - unset(self::$basketExt[$uid][$allVariants]); + unset($basketExt[$uid][$allVariants]); $basketExtModified = true; } } @@ -200,26 +218,26 @@ public static function doProcessing(): void } if ($basketExtModified) { - self::storeBasketExt(self::$basketExt); + $basketApi->storeBasketExt($basketExt); } } public static function setFuncTablename($funcTablename): void { - self::$funcTablename = $funcTablename; + static::$funcTablename = $funcTablename; } public static function getFuncTablename() { - return self::$funcTablename; + return static::$funcTablename; } public static function getRecs() { - return self::$recs; + return static::$recs; } - public static function setRecs($recs): void + public static function setRecs(array $recs): void { $newRecs = []; $allowedTags = '
'; @@ -227,21 +245,30 @@ public static function setRecs($recs): void foreach ($recs as $type => $valueArray) { if (is_array($valueArray)) { foreach ($valueArray as $k => $infoRow) { - $newRecs[$type][$k] = strip_tags($infoRow, $allowedTags); + $newRecs[$type][$k] = strip_tags((string) $infoRow, $allowedTags); } } else { $newRecs[$type] = strip_tags($valueArray, $allowedTags); } } - self::$recs = $newRecs; + static::$recs = $newRecs; } public static function getStoredRecs() { $result = []; + $recs = []; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $frontendUser = $parameterApi->getRequest()->getAttribute('frontend.user'); + + if ( + isset($frontendUser) && + $frontendUser instanceof FrontendUserAuthentication + ) { + $recs = $frontendUser->getKey('ses', 'recs'); + } - $recs = tx_ttproducts_control_session::readSession('recs'); if (!empty($recs)) { $result = $recs; } @@ -251,55 +278,32 @@ public static function getStoredRecs() public static function setStoredRecs($valueArray): void { - self::store('recs', $valueArray); + static::store('recs', $valueArray); } public static function getStoredVariantRecs() { - $result = tx_ttproducts_control_session::readSession('variant'); - + $result = SessionHandler::readSession('variant'); return $result; } public static function setStoredVariantRecs($valueArray): void { - self::store('variant', $valueArray); + static::store('variant', $valueArray); } public static function store($type, $valueArray): void { - tx_ttproducts_control_session::writeSession($type, $valueArray); - } - - public static function getBasketExtRaw() - { - $basketVar = tx_ttproducts_model_control::getBasketVar(); - $result = GeneralUtility::_GP($basketVar); - - return $result; - } - - public static function getStoredBasketExt() - { - $result = tx_ttproducts_control_session::readSession('basketExt'); - - return $result; + SessionHandler::storeSession($type, $valueArray); } public static function getStoredOrder() { - $result = tx_ttproducts_control_session::readSession('order'); + $result = SessionHandler::readSession('order'); return $result; } - public static function storeBasketExt($basketExt): void - { - $basketApi = GeneralUtility::makeInstance(BasketApi::class); - self::store('basketExt', $basketExt); - $basketApi->setBasketExt($basketExt); - } - public static function generatedBasketExtFromRow($row, $count) { $basketExt = []; @@ -311,78 +315,9 @@ public static function generatedBasketExtFromRow($row, $count) return $basketExt; } - public static function removeFromBasketExt($removeBasketExt): void - { - $basketExt = self::getStoredBasketExt(); - $bChanged = false; - - if (isset($removeBasketExt) && is_array($removeBasketExt)) { - foreach ($removeBasketExt as $uid => $removeRow) { - $allVariants = key($removeRow); - $bRemove = current($removeRow); - - if ( - $bRemove && - isset($basketExt[$uid]) && - isset($basketExt[$uid][$allVariants]) - ) { - unset($basketExt[$uid][$allVariants]); - $bChanged = true; - } - } - } - if ($bChanged) { - self::storeBasketExt($basketExt); - } - } - - public static function getBasketCount( - $row, - $variant, - $quantityIsFloat, - $ignoreVariant = false - ) { - $count = ''; - $basketApi = GeneralUtility::makeInstance(BasketApi::class); - $basketExt = $basketApi->getBasketExt(); - $uid = $row['uid']; - - if (isset($basketExt[$uid])) { - $subArr = $basketExt[$uid]; - - if ( - $ignoreVariant && - is_array($subArr) - ) { - $count = 0; - foreach ($subArr as $subVariant => $subCount) { - $count += $subCount; - } - } elseif ( - is_array($subArr) && - isset($subArr[$variant]) - ) { - $tmpCount = $subArr[$variant]; - - if ( - $tmpCount > 0 && - ( - $quantityIsFloat || - MathUtility::canBeInterpretedAsInteger($tmpCount) - ) - ) { - $count = $tmpCount; - } - } - } - - return $count; - } - public static function getStoredInfoArray() { - $formerBasket = self::getRecs(); - + $formerBasket = static::getRecs(); $infoArray = []; if (isset($formerBasket) && is_array($formerBasket)) { @@ -401,8 +336,7 @@ public static function getStoredInfoArray() public static function setInfoArray($infoArray): void { - self::$infoArray = $infoArray; - + static::$infoArray = $infoArray; if ( isset($infoArray['billing']) && is_array($infoArray['billing']) @@ -420,7 +354,7 @@ public static function setInfoArray($infoArray): void public static function getInfoArray() { - return self::$infoArray; + return static::$infoArray; } public static function setCountry(&$infoArray, $basketExtra): void @@ -436,29 +370,29 @@ public static function setCountry(&$infoArray, $basketExtra): void !empty($infoArray['billing']['country_code']) ) { $infoArray['billing']['country'] = + $staticInfoApi->getStaticInfoName( + $infoArray['billing']['country_code'], + 'COUNTRIES', + '', + '' + ); + + if (static::needsDeliveryAddresss($basketExtra)) { + $infoArray['delivery']['country'] = $staticInfoApi->getStaticInfoName( - $infoArray['billing']['country_code'], + $infoArray['delivery']['country_code'], 'COUNTRIES', '', '' ); - - if (static::needsDeliveryAddresss($basketExtra)) { - $infoArray['delivery']['country'] = - $staticInfoApi->getStaticInfoName( - $infoArray['delivery']['country_code'], - 'COUNTRIES', - '', - '' - ); } } } - public static function uncheckAgb(&$infoArray, $bProductsPayment): void + public static function uncheckAgb(&$infoArray, $isPaymentActivity): void { if ( - $bProductsPayment && + $isPaymentActivity && isset($_REQUEST['recs']) && is_array($_REQUEST['recs']) && isset($_REQUEST['recs']['personinfo']) && @@ -497,8 +431,7 @@ public static function fixCountries(&$infoArray) if ( !empty($infoArray['billing']['country_code']) && ( - !isset($infoArray['delivery']['zip']) || - $infoArray['delivery']['zip'] == '' || + empty($infoArray['delivery']['zip']) || ( $infoArray['delivery']['zip'] == $infoArray['billing']['zip'] ) @@ -515,49 +448,52 @@ public static function fixCountries(&$infoArray) public static function addLoginData( &$infoArray, $loginUserInfoAddress, - $useStaticInfoCountry + $useStaticInfoCountry, + $feUserRecord ): void { + $context = GeneralUtility::makeInstance(Context::class); + if ( + $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') + ) { + $infoArray['billing']['feusers_uid'] = + $feUserRecord['uid']; + } + if ( - isset($GLOBALS['TSFE']) && - $GLOBALS['TSFE'] instanceof TypoScriptFrontendController && - CompatibilityUtility::isLoggedIn() && + $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && ControlApi::isOverwriteMode($infoArray) ) { $address = ''; - $infoArray['billing']['feusers_uid'] = - $GLOBALS['TSFE']->fe_user->user['uid']; if ( $useStaticInfoCountry && empty($infoArray['billing']['country_code']) ) { $infoArray['billing']['country_code'] = - $GLOBALS['TSFE']->fe_user->user['static_info_country']; + $feUserRecord['static_info_country']; } if ($loginUserInfoAddress) { $address = implode( chr(10), - GeneralUtility::trimExplode( - chr(10), - $GLOBALS['TSFE']->fe_user->user['address'] . chr(10) . - ( - isset($GLOBALS['TSFE']->fe_user->user['house_no']) && - $GLOBALS['TSFE']->fe_user->user['house_no'] != '' ? - $GLOBALS['TSFE']->fe_user->user['house_no'] . chr(10) : - '' - ) . - $GLOBALS['TSFE']->fe_user->user['zip'] . ' ' . $GLOBALS['TSFE']->fe_user->user['city'] . chr(10) . - ( - $useStaticInfoCountry ? - $GLOBALS['TSFE']->fe_user->user['static_info_country'] : - $GLOBALS['TSFE']->fe_user->user['country'] - ), - 1 - ) + GeneralUtility::trimExplode( + chr(10), + $feUserRecord['address'] . chr(10) . + ( + $feUserRecord['house_no'] != '' ? + $feUserRecord['house_no'] . chr(10) : + '' + ) . + $feUserRecord['zip'] . ' ' . $feUserRecord['city'] . chr(10) . + ( + $useStaticInfoCountry ? + $feUserRecord['static_info_country'] : + $feUserRecord['country'] + ) + ) ); } else { - $address = $GLOBALS['TSFE']->fe_user->user['address']; + $address = $feUserRecord['address']; } $infoArray['billing']['address'] = $address; $fields = CustomerApi::getFields() . ',' . CustomerApi::getCreditPointFields(); @@ -565,10 +501,11 @@ public static function addLoginData( $fieldArray = GeneralUtility::trimExplode(',', $fields); foreach ($fieldArray as $k => $field) { if (empty($infoArray['billing'][$field])) { - $infoArray['billing'][$field] = $GLOBALS['TSFE']->fe_user->user[$field]; + $infoArray['billing'][$field] = $feUserRecord[$field]; } } + // neu Anfang $typeArray = ['billing', 'delivery']; foreach ($typeArray as $type) { if ( @@ -605,9 +542,10 @@ public static function addLoginData( } } } - } + } // foreach + // neu Ende - $infoArray['billing']['agb'] ??= $GLOBALS['TSFE']->fe_user->user['agb']; + $infoArray['billing']['agb'] ??= $feUserRecord['agb']; $dateBirth = $infoArray['billing']['date_of_birth']; $tmpPos = strpos($dateBirth, '-'); @@ -618,17 +556,10 @@ public static function addLoginData( $tmpPos == 0 ) { $infoArray['billing']['date_of_birth'] = - date('d-m-Y', $GLOBALS['TSFE']->fe_user->user['date_of_birth']); + date('d-m-Y', $feUserRecord['date_of_birth']); } unset($infoArray['billing']['error']); - } - } - - public static function getTagName($uid, $fieldname) - { - $result = tx_ttproducts_model_control::getBasketVar() . '[' . $uid . '][' . $fieldname . ']'; - - return $result; + } // if isLoggedIn } public static function getAjaxVariantFunction($row, $funcTablename, $theCode) @@ -644,7 +575,7 @@ public static function getAjaxVariantFunction($row, $funcTablename, $theCode) public static function destruct(): void { - self::$bHasBeenInitialised = false; + static::$bHasBeenInitialised = false; } public static function getRoundFormat($type = '') @@ -663,7 +594,7 @@ public static function getRoundFormat($type = '') public static function readControl($key = '') { $result = false; - $ctrlArray = tx_ttproducts_control_session::readSession('ctrl'); + $ctrlArray = SessionHandler::readSession('ctrl'); if (isset($ctrlArray) && is_array($ctrlArray)) { if ($key != '' && isset($ctrlArray[$key])) { @@ -684,6 +615,6 @@ public static function writeControl($valArray): void ) { $valArray = []; } - self::store('ctrl', $valArray); + static::store('ctrl', $valArray); } } diff --git a/control/class.tx_ttproducts_control_command.php b/control/class.tx_ttproducts_control_command.php index ab6b970d0..a668165ec 100644 --- a/control/class.tx_ttproducts_control_command.php +++ b/control/class.tx_ttproducts_control_command.php @@ -36,11 +36,14 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\ExtensionUtility; -use JambageCom\TtProducts\Api\Localization; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\Div2007\Utility\ExtensionUtility; + +use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_control_command { protected static $commandVar = 'cmd'; @@ -52,9 +55,10 @@ public static function getCommandVar() public static function getVariantVars($piVars) { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $result = []; - $paramsTableArray = tx_ttproducts_model_control::getParamsTableArray(); + $paramsTableArray = $parameterApi->getParamsTableArray(); if (isset($piVars) && is_array($piVars)) { foreach ($piVars as $piVar => $v) { if (!isset($paramsTableArray[$piVar])) { @@ -69,6 +73,7 @@ public static function getVariantVars($piVars) public static function doProcessing( $theCode, $conf, + $feUserRecord, $bIsAllowedBE, $bValidUpdateCode, $trackingCode, @@ -79,6 +84,7 @@ public static function doProcessing( $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $bHasBeenOrdered = false; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $pidListObj = GeneralUtility::makeInstance('tx_ttproducts_pid_list'); $pidListObj->applyRecursive($recursive, $pid_list, true); @@ -97,13 +103,13 @@ public static function doProcessing( $falUid = intval($cmdData['fal'] ?? 0); $downloadTable = $tablesObj->get('tt_products_downloads', false); $downloadVar = - tx_ttproducts_model_control::getPiVar( + $parameterApi->getPiVar( $downloadTable->getFuncTablename() ); - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $variantVars = self::getVariantVars($piVars); $orderVar = - tx_ttproducts_model_control::getPiVar( + $parameterApi->getPiVar( 'sys_products_orders' ); $orderUid = 0; @@ -118,7 +124,7 @@ public static function doProcessing( $orderUid = intval($piVars[$orderVar]); } - $feusers_uid = intval($GLOBALS['TSFE']->fe_user->user['uid'] ?? 0); + $feusers_uid = $feUserRecord['uid'] ?? 0; $orderObj = $tablesObj->get('sys_products_orders'); // order $orderObj->getDownloadWhereClauses( $feusers_uid, diff --git a/control/class.tx_ttproducts_control_memo.php b/control/class.tx_ttproducts_control_memo.php index 39ce80fc5..ab8fc0395 100644 --- a/control/class.tx_ttproducts_control_memo.php +++ b/control/class.tx_ttproducts_control_memo.php @@ -1,29 +1,32 @@ 'memoItems', - 'tx_dam' => 'memodam', + 'sys_file' => 'memofile', ]; protected static $memoItemArray = []; protected static $controlVars = [ @@ -100,10 +105,10 @@ public static function bUseSession($conf) return $result; } - public static function process($funcTablename, $piVars, $conf): void + public static function process($feUserRecord, $funcTablename, $piVars, $conf): void { $bMemoChanged = false; - self::loadMemo($funcTablename, $conf); + self::loadMemo($feUserRecord, $funcTablename, $conf); $memoItems = self::getMemoItems($funcTablename); if (!is_array($memoItems)) { @@ -126,16 +131,21 @@ public static function process($funcTablename, $piVars, $conf): void } foreach ($piVars['memo'] as $k => $v) { - if (MathUtility::canBeInterpretedAsInteger($k) && $k != '' && $v) { + if ( + MathUtility::canBeInterpretedAsInteger($k) && $k != '' && $v) { $memoArray['addmemo'][] = intval($k); - } elseif ($k == 'uids') { - $uidArray = explode(',', $v); - foreach ($uidArray as $uid) { - if (MathUtility::canBeInterpretedAsInteger($uid) && $uid != '' && in_array($uid, $memoItems)) { - $memoArray['delmemo'][] = $uid; + } elseif ($k == 'uids') { + $uidArray = explode(',', $v); + foreach ($uidArray as $uid) { + if ( + MathUtility::canBeInterpretedAsInteger($uid) && + $uid != '' && + in_array($uid, $memoItems) + ) { + $memoArray['delmemo'][] = $uid; + } } } - } } } @@ -226,42 +236,32 @@ public static function setMemoItems($funcTablename, $v): void public static function readSessionMemoItems($funcTablename) { - $result = ''; - $session = tx_ttproducts_control_session::readSessionData(); $tableArray = self::getMemoTableFieldArray(); $field = $tableArray[$funcTablename]; - if ( - $field != '' && - is_array($session) && - isset($session[$field]) - ) { - $result = $session[$field]; - } + $result = SessionHandler::readSession($field); return $result; } - public static function readFeUserMemoItems($funcTablename) + public static function readFeUserMemoItems($feUserRecord, $funcTablename) { $result = ''; $feuserField = self::getMemoField($funcTablename, true); - if ($GLOBALS['TSFE']->fe_user->user[$feuserField]) { - $result = explode(',', $GLOBALS['TSFE']->fe_user->user[$feuserField]); + if (!empty($feUserRecord[$feuserField])) { + $result = explode(',', $feUserRecord[$feuserField]); } return $result; } - public static function loadMemo($funcTablename, $conf): void + public static function loadMemo($feUserRecord, $funcTablename, $conf): void { $memoItems = ''; - // $bFeuser = self::bUseFeuser($conf); - // $theField = self::getMemoField($funcTablename, $bFeuser); if (self::bUseFeuser($conf)) { - $memoItems = self::readFeUserMemoItems($funcTablename); + $memoItems = self::readFeUserMemoItems($feUserRecord, $funcTablename); } else { $memoItems = self::readSessionMemoItems($funcTablename); } @@ -280,18 +280,18 @@ public static function saveMemo($funcTablename, $memoItems, $conf): void $fe_user_uid = FrontendUtility::getFrontEndUser('uid'); $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . $fe_user_uid, $fieldsArray); } else { - tx_ttproducts_control_session::writeSessionData($fieldsArray); + SessionHandler::storeSession('feuser', $fieldsArray); } } - public static function copySession2Feuser($params, $pObj, $conf): void + public static function copySession2Feuser($params, $pObj, $conf, $feUserRecord): void { $tableArray = self::getMemoTableFieldArray(); foreach ($tableArray as $funcTablename => $type) { $memoItems = self::readSessionMemoItems($funcTablename); if (!empty($memoItems) && is_array($memoItems)) { - $feuserMemoItems = self::readFeUserMemoItems($funcTablename); + $feuserMemoItems = self::readFeUserMemoItems($feUserRecord, $funcTablename); if (isset($feuserMemoItems) && is_array($feuserMemoItems)) { $memoItems = array_merge($feuserMemoItems, $memoItems); } diff --git a/control/class.tx_ttproducts_control_product.php b/control/class.tx_ttproducts_control_product.php index de20398fe..c7a894ccf 100644 --- a/control/class.tx_ttproducts_control_product.php +++ b/control/class.tx_ttproducts_control_product.php @@ -50,10 +50,11 @@ public static function getPresetVariantArray( $row, $useArticles ) { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $uid = $row['uid']; $funcTablename = $itemTable->getFuncTablename(); - $basketVar = tx_ttproducts_model_control::getBasketVar(); + $basketVar = $parameterApi->getBasketVar(); $presetVariantArray = []; $basketArray = GeneralUtility::_GP($basketVar); @@ -91,7 +92,8 @@ public static function getPresetVariantArray( public static function getActiveArticleNo() { - $result = tx_ttproducts_model_control::getPiVarValue('tt_products_articles'); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $result = $parameterApi->getPiVarValue('tt_products_articles'); return $result; } diff --git a/control/class.tx_ttproducts_control_single.php b/control/class.tx_ttproducts_control_single.php index 1dceb3074..0cd606adc 100644 --- a/control/class.tx_ttproducts_control_single.php +++ b/control/class.tx_ttproducts_control_single.php @@ -40,6 +40,9 @@ * @package TYPO3 * @subpackage tt_products */ + +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_control_single implements SingletonInterface { /** @@ -53,9 +56,10 @@ public function triggerEvents($conf): void !empty($conf['active']) && isset($conf['trigger.']) ) { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $triggerConf = $conf['trigger.']; - $piVars = tx_ttproducts_model_control::getPiVars(); - $piVar = tx_ttproducts_model_control::getPiVar('tt_products'); + $piVars = $parameterApi->getPiVars(); + $piVar = $parameterApi->getPiVar('tt_products'); $uid = $piVars[$piVar] ?? ''; if (CompatibilityUtility::isLoggedIn()) { diff --git a/control/class.tx_ttproducts_javascript.php b/control/class.tx_ttproducts_javascript.php index 215fafb7b..8af723443 100644 --- a/control/class.tx_ttproducts_javascript.php +++ b/control/class.tx_ttproducts_javascript.php @@ -34,13 +34,16 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\FrontendUtility; use TYPO3\CMS\Core\Page\AssetCollector; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; +use JambageCom\Div2007\Utility\FrontendUtility; + +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_javascript implements SingletonInterface { public $ajax; @@ -165,7 +168,8 @@ public function set( $bDirectHTML = false; $code = ''; $bError = false; - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $prefixId = $parameterApi->getPrefixId(); if ( !$this->bCopyrightShown && @@ -412,7 +416,7 @@ public function set( data["' . $prefixId . '"]["' . $catid . '"] = category; '; - $contentPiVar = tx_ttproducts_model_control::getPiVar('tt_content'); + $contentPiVar = $parameterApi->getPiVar('tt_content'); if ($currentRecord != '') { $code .= ' diff --git a/control/class.tx_ttproducts_main.php b/control/class.tx_ttproducts_main.php index fdf99497a..201affbe2 100644 --- a/control/class.tx_ttproducts_main.php +++ b/control/class.tx_ttproducts_main.php @@ -36,6 +36,7 @@ * @package TYPO3 * @subpackage tt_products */ +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; use TYPO3\CMS\Core\SingletonInterface; @@ -56,6 +57,7 @@ use JambageCom\TtProducts\Api\ActivityApi; use JambageCom\TtProducts\Api\BasketApi; use JambageCom\TtProducts\Api\ControlApi; +use JambageCom\TtProducts\Api\CustomerApi; use JambageCom\TtProducts\Api\Localization; use JambageCom\TtProducts\Api\ParameterApi; use JambageCom\TtProducts\Api\PluginApi; @@ -126,15 +128,18 @@ public function setContentObjectRenderer(ContentObjectRenderer $cObj): void public function init( &$conf, &$config, - &$cObj, + ServerRequestInterface $request, + $cObj, $pibaseClass, &$errorCode, $bRunAjax = false ) { $result = true; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $parameterApi->setRequest($request); $this->setSingleFromList(false); $this->tt_product_single = []; - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); if ( ExtensionManagementUtility::isLoaded('party') @@ -294,9 +299,8 @@ public function init( // ************************************* if ($config['displayCurrentRecord']) { - // $config['code']='SINGLE'; $row = $cObj->data; - $this->tt_product_single['product'] = $row['uid']; + $this->tt_product_single['product'] = $row['uid'] ?? 0; } else { $error_detail = ''; $paramArray = ['product', 'article', 'dam', 'fal']; @@ -354,7 +358,8 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $conf = $cnf->getConf(); $config = $cnf->getConfig(); - $piVars = tx_ttproducts_model_control::getPiVars(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $piVars = $parameterApi->getPiVars(); $urlObj = GeneralUtility::makeInstance('tx_ttproducts_url_view'); $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); @@ -429,7 +434,7 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax $basketExt = $basketApi->getBasketExt(); $basketExtra = $basketApi->getBasketExtra(); $basketRecs = tx_ttproducts_control_basket::getRecs(); - $infoArray = \tx_ttproducts_control_basket::getInfoArray(); + $infoArray = tx_ttproducts_control_basket::getInfoArray(); $infoObj->init($infoArray, $conf['pdfInfoFields']); $activityApi = GeneralUtility::makeInstance(ActivityApi::class); $activityApi->init($this->codeArray); @@ -446,8 +451,19 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax ); $itemArray = $basketObj->getItemArray(); - $basketObj->calculate($itemArray); // get the calculated arrays + $tax = ''; + $basketObj->calculate( + $itemArray, + $basketExt, + $basketExtra, + $basketRecs, + $tax, + true, + false + ); // get the calculated arrays $basketObj->setItemArray($itemArray); + $feUserRecord = CustomerApi::getFeUserRecord(); + $basketObj->calculateSums($feUserRecord); $voucher = $tablesObj->get('voucher'); if (is_object($voucher) && $voucher->isEnabled()) { @@ -455,14 +471,16 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax $voucher->doProcessing($recs); } - $basketObj->calculateSums(); - $basketObj->addVoucherSums(); + if (!empty($voucher)) { + $basketObj->addVoucherSums($voucher); + } $templateFile = ''; $templateCode = ''; if (!$errorMessage && !count($errorCode)) { $funcTablename = 'tt_products'; tx_ttproducts_control_memo::process( + $feUserRecord, $funcTablename, $piVars, $conf @@ -547,7 +565,7 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax $hideZero ) { $hideIdArray = GeneralUtility::trimExplode(',', $hideIds); - $piVar = tx_ttproducts_model_control::getPiVar($funcTablename); + $piVar = $parameterApi->getPiVar($funcTablename); if (isset($piVars[$piVar])) { $currentArray = GeneralUtility::trimExplode(',', $piVars[$piVar]); @@ -795,6 +813,7 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax tx_ttproducts_control_command::doProcessing( $theCode, $conf, + $feUserRecord, $bIsAllowed, $bValidUpdateCode, $trackingCode, @@ -860,7 +879,7 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax ); $tableInfoArray = ['SINGLECAT' => 'tt_products_cat', 'SINGLEDAMCAT' => 'tx_dam_cat', 'SINGLEAD' => 'address']; $funcTablename = $tableInfoArray[$theCode]; - $uid = $piVars[tx_ttproducts_model_control::getPivar($funcTablename)]; + $uid = $piVars[$parameterApi->getPivar($funcTablename)]; if ($uid) { $contentTmp = $catView->printView( @@ -868,6 +887,7 @@ public function run(&$cObj, $pibaseClass, &$errorCode, $content = '', $bRunAjax $funcTablename, $uid, $theCode, + $feUserRecord, $errorCode, $config['templateSuffix'] ); @@ -1304,9 +1324,11 @@ public function products_display( $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $conf = $cnf->getConf(); $config = $cnf->getConfig(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $feUserRecord = CustomerApi::getFeUserRecord(); $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $bSingleFromList = false; - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); if ( ( @@ -1365,6 +1387,7 @@ public function products_display( $content = $this->singleView->printView( $templateCode, $errorCode, + $feUserRecord, $this->pageAsCategory, $config['templateSuffix'] ); @@ -1401,7 +1424,6 @@ public function products_display( $funcTablename = 'tt_products'; } $allowedItems = FlexformUtility::get(PluginApi::getFlexform(), 'productSelection'); - $bAllPages = false; $templateArea = $templateArea . $config['templateSuffix']; $content = $listView->printView( @@ -1414,6 +1436,7 @@ public function products_display( $errorCode, $templateArea, $this->pageAsCategory, + $feUserRecord, $basketExtra, $basketRecs, [] diff --git a/eid/class.tx_ttproducts_ajax.php b/eid/class.tx_ttproducts_ajax.php index b8da0eea0..4fea0773f 100644 --- a/eid/class.tx_ttproducts_ajax.php +++ b/eid/class.tx_ttproducts_ajax.php @@ -36,12 +36,13 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\FrontendUtility; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\Div2007\Utility\FrontendUtility; + class tx_ttproducts_ajax implements SingletonInterface { public $taxajax; // xajax object @@ -61,6 +62,11 @@ public function init() return $result; } + public function getTaxajax() + { + return $this->taxajax; + } + public function setConf($conf): void { $this->conf = $conf; diff --git a/eid/class.tx_ttproducts_db.php b/eid/class.tx_ttproducts_db.php index 483c72341..2667aa4dc 100644 --- a/eid/class.tx_ttproducts_db.php +++ b/eid/class.tx_ttproducts_db.php @@ -1,8 +1,11 @@ conf = $conf; - if (isset($ajax) && is_object($ajax)) { - $this->ajax = $ajax; + if (isset($ajaxObj) && is_object($ajaxObj)) { + $this->ajax = $ajaxObj; + $taxajax = $this->ajax->getTaxajax(); - $ajax->taxajax->registerFunction([TT_PRODUCTS_EXT . '_fetchRow', $this, 'fetchRow']); - $ajax->taxajax->registerFunction([TT_PRODUCTS_EXT . '_commands', $this, 'commands']); - $ajax->taxajax->registerFunction([TT_PRODUCTS_EXT . '_showArticle', $this, 'showArticle']); + $taxajax->registerFunction([TT_PRODUCTS_EXT . '_fetchRow', $this, 'fetchRow']); + $taxajax->registerFunction([TT_PRODUCTS_EXT . '_commands', $this, 'commands']); + $taxajax->registerFunction([TT_PRODUCTS_EXT . '_showArticle', $this, 'showArticle']); } if ( @@ -78,35 +96,41 @@ public function init(&$conf, &$config, $ajax, $pObj, $cObj, &$errorCode): bool ) { $this->cObj = $cObj; } else { - $this->cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer'); // Local cObj. - $this->cObj->start([]); + $this->cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); // Local cObj. } - $controlCreatorObj = GeneralUtility::makeInstance('tx_ttproducts_control_creator'); + $controlCreatorObj = GeneralUtility::makeInstance(Creator::class); + + // TODO: $recs befüllen. if ( - ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface && + ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface + && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() ) { \tx_ttproducts_control_basket::storeNewRecs($conf['transmissionSecurity']); $recs = tx_ttproducts_control_basket::getStoredRecs(); } - if (empty($recs)) { $recs = []; } + $result = $controlCreatorObj->init( $conf, $config, $pObj, $this->cObj, - $ajax, + $ajaxObj, $errorCode, $recs ); + if (!$result) { return false; } + + $this->fileRepository = $controlCreatorObj->getFileRepository(); + $modelCreatorObj = GeneralUtility::makeInstance('tx_ttproducts_model_creator'); $modelCreatorObj->init($conf, $config, $this->cObj); @@ -129,6 +153,8 @@ public function fetchRow($data) $variantArray = []; $theCode = 'ALL'; $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); + $languageObj = GeneralUtility::makeInstance(Localization::class); + $roundFormat = tx_ttproducts_control_basket::getRoundFormat(); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $basketApi = GeneralUtility::makeInstance(BasketApi::class); @@ -136,6 +162,7 @@ public function fetchRow($data) $basketExtra = $basketApi->getBasketExtra(); $basketRecs = tx_ttproducts_control_basket::getRecs(); $funcTablename = tx_ttproducts_control_basket::getFuncTablename(); + $useFal = true; // price $priceObj = GeneralUtility::makeInstance('tx_ttproducts_field_price'); @@ -151,12 +178,14 @@ public function fetchRow($data) // We put our incomming data to the regular piVars $itemTable = $tablesObj->get('tt_products', false); $externalRowArray = []; - $variantSeparator = $itemTable->variant->getSplitSeparator(); + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + $editVariantApi = GeneralUtility::makeInstance(EditVariantApi::class); + $variantSeparator = $variantApi->getSplitSeparator(); if (is_array($data)) { $validEditVariant = true; - $useArticles = $itemTable->variant->getUseArticles(); - $variantFieldArray = $itemTable->variant->getSelectableFieldArray(); + $useArticles = $cnfObj->getUseArticles(); + $variantFieldArray = $variantApi->getSelectableFieldArray(); foreach ($data as $k => $dataRow) { if ($k == 'view') { @@ -179,7 +208,7 @@ public function fetchRow($data) foreach ($dataRow as $field => $v) { $field = str_replace('-', '_', $field); - if (isset($row[$field])) { + if (isset($row[$field]) && strlen($row[$field])) { if ($field != 'uid') { $variantArray[] = $field; $variantValues = @@ -192,13 +221,14 @@ public function fetchRow($data) $theValue = $variantValues[$v]; $rowArray[$table][$field] = $theValue; } - } elseif (strpos($field, 'edit_') === 0) { + } elseif (str_starts_with($field, 'edit_')) { $rowArray[$table][$field] = $v; } } $modifiedRow = $rowArray[$table]; - $editConfig = $itemTable->editVariant->getValidConfig($modifiedRow); - $editVariantFieldArray = $itemTable->editVariant->getFieldArray(); + $editConfig = $editVariantApi->getValidConfig($modifiedRow); + $editVariantFieldArray = $editVariantApi->getFieldArray(); + if ( isset($editVariantFieldArray) && is_array($editVariantFieldArray) ) { @@ -213,14 +243,15 @@ public function fetchRow($data) $row[$field] = $storeRowArray[$table][$uid][$field] = $rowArray[$table][$field]; } } - if (count($storeRowArray)) { + + if (is_array($storeRowArray) && count($storeRowArray)) { $this->ajax->setStoredRecs($storeRowArray); } } if ($editConfig && is_array($editConfig)) { $validEditVariant = - $itemTable->editVariant->checkValid( + $editVariantApi->checkValid( $editConfig, $modifiedRow ); @@ -240,7 +271,6 @@ public function fetchRow($data) $storeRowArray[$table][$uid][$field] = $rowArray[$table][$field]; } } - tx_ttproducts_control_basket::setStoredVariantRecs($storeRowArray); $allVariants = @@ -249,29 +279,50 @@ public function fetchRow($data) $row, $modifiedRow ); - $currRow = $basketObj->getItemRow( $row, $allVariants, $useArticles, $funcTablename, + [], true ); - - $basketExt1 = tx_ttproducts_control_basket::generatedBasketExtFromRow($currRow, '1'); + $basketExt1 = tx_ttproducts_control_basket::generatedBasketExtFromRow( + $currRow, + '1' + ); + $taxInfoArray = []; + $tax = 0.0; $itemArray = - $basketObj->getItemArrayFromRow( - $currRow, - $basketExt1, - $basketExtra, - $basketRecs, - $funcTablename, - $externalRowArray - ); + $basketObj->getItemArrayFromRow( + $tax, + $taxInfoArray, + $currRow, + $basketExt1, + $basketExtra, + $basketRecs, + $funcTablename, + 'useExt', + $externalRowArray + ); + $basketObj->setMaxTax($modifiedRow['tax']); - $basketObj->calculate($itemArray); // get the calculated arrays + $recalculateItems = true; + $calculatedArray = []; + $basketObj->calculate( + $itemArray, + $calculatedArray, + $basketExt1, + $basketExtra, + $basketRecs, + $funcTablename, + $useArticles, + $tax, + $roundFormat, + $recalculateItems + ); // get the calculated arrays $modifiedRow = $basketObj->getMergedRowFromItemArray( @@ -281,30 +332,6 @@ public function fetchRow($data) $totalDiscountField = FieldInterface::DISCOUNT; $itemTable->getTotalDiscount($modifiedRow); - $priceTaxArray = []; - $taxInfoArray = []; - - $priceTaxArray = $priceObj->getPriceTaxArray( - $taxInfoArray, - $this->conf['discountPriceMode'] ?? '', - $basketExtra, - tx_ttproducts_control_basket::getRecs(), - 'price', - tx_ttproducts_control_basket::getRoundFormat(), - tx_ttproducts_control_basket::getRoundFormat('discount'), - $modifiedRow, - $totalDiscountField, - false, - false - ); - - $field = 'price'; - foreach ($priceTaxArray as $priceKey => $priceValue) { - $displayTax = - $priceViewObj->convertKey($priceKey, $field); - $displaySuffixId = str_replace('_', '', strtolower($displayTax)); - $modifiedRow[$displaySuffixId] = $priceValue; - } if ($useArticles == 1) { $rowArticle = @@ -320,6 +347,37 @@ public function fetchRow($data) ); } + if ( + !$useFal && + isset($rowArticle) && + is_array($rowArticle) + ) { + if ( + isset($rowArticle['image']) && + !$rowArticle['image'] && + isset($rowArray[$table]['image']) + ) { + $rowArticle['image'] = $rowArray[$table]['image']; + $modifiedRow['image'] = $rowArticle['image']; + } + + $articleConf = + $cnfObj->getTableConf('tt_products_articles', $theCode); + + if ( + isset($articleConf['fieldIndex.']) && is_array($articleConf['fieldIndex.']) && + isset($articleConf['fieldIndex.']['image.']) && is_array($articleConf['fieldIndex.']['image.']) + ) { + $prodImageArray = + GeneralUtility::trimExplode(',', $rowArray[$table]['image']); + $artImageArray = GeneralUtility::trimExplode(',', $rowArticle['image']); + $tmpDestArray = $prodImageArray; + foreach ($articleConf['fieldIndex.']['image.'] as $kImage => $vImage) { + $tmpDestArray[$vImage - 1] = $artImageArray[$kImage - 1]; + } + $modifiedRow['image'] = implode(',', $tmpDestArray); + } + } $itemTable->getTableObj()->substituteMarkerArray( $modifiedRow ); @@ -346,7 +404,8 @@ public function fetchRow($data) protected function generateErrorResponse($uid, $editErrorArray) { - $bUseXHTML = HtmlUtility::useXHTML(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $useXHTML = HtmlUtility::useXHTML(); // Instantiate the tx_xajax_response object $objResponse = new tx_taxajax_response($this->ajax->taxajax->getCharEncoding(), true); @@ -354,14 +413,11 @@ protected function generateErrorResponse($uid, $editErrorArray) $editVariant = key($editErrorArray); $errorText = current($editErrorArray); $fieldname = str_replace('edit_', '', $editVariant); - - $errorId = tx_ttproducts_model_control::getBasketInputErrorIdPrefix() . '-' . $uid; + $errorId = $parameterApi->getBasketInputErrorIdPrefix() . '-' . $uid; $objResponse->addAssign($errorId, 'innerHTML', $errorText); - $basketIntoId = tx_ttproducts_model_control::getBasketIntoIdPrefix() . '-' . $uid; - - $disabledText = ($bUseXHTML ? 'disabled' : ''); + $basketIntoId = $parameterApi->getBasketIntoIdPrefix() . '-' . $uid; + $disabledText = ($useXHTML ? 'disabled' : ''); $objResponse->addPrepend($basketIntoId, 'disabled', $disabledText); - $result = $objResponse->getXML(); // return the XML response generated by the tx_taxajax_response object @@ -377,28 +433,29 @@ protected function generateResponse( $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $config = $cnfObj->getConfig(); $conf = $cnfObj->getConf(); - $bUseXHTML = HtmlUtility::useXHTML(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $useXHTML = HtmlUtility::useXHTML(); + $useFal = true; + $basketApi = GeneralUtility::makeInstance(BasketApi::class); $theCode = strtoupper($view); + $languageObj = GeneralUtility::makeInstance(Localization::class); $imageObj = GeneralUtility::makeInstance('tx_ttproducts_field_image'); $imageViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_image_view'); - $languageObj = GeneralUtility::makeInstance(Localization::class); - $imageObj->init($this->cObj); + $imageObj->init($this->fileRepository); $imageViewObj->init($imageObj); $priceObj = GeneralUtility::makeInstance('tx_ttproducts_field_price'); // price $priceViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_price_view'); - $priceFieldArray = $priceViewObj->getConvertedPriceFieldArray('price'); $tableObjArray = []; $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); // Instantiate the tx_xajax_response object - $objResponse = new tx_taxajax_response($this->ajax->taxajax->getCharEncoding(), true); - + $objResponse = new tx_taxajax_response($this->ajax->getTaxajax()->getCharEncoding(), true); $articleTcaColumns = $GLOBALS['TCA']['tt_products_articles']['columns']; foreach ($rowArray as $funcTablename => $row) { // tt-products-list-1-size @@ -425,8 +482,8 @@ protected function generateResponse( $categoryFuncTablename = 'tt_products_cat'; $categoryTableView = $tablesObj->get($categoryFuncTablename, true); $categoryTable = $categoryTableView->getModelObj(); - $piVars = tx_ttproducts_model_control::getPiVars(); - $categoryPivar = tx_ttproducts_model_control::getPiVar($categoryFuncTablename); + $piVars = $parameterApi->getPiVars(); + $categoryPivar = $parameterApi->getPiVar($categoryFuncTablename); $currentCat = $categoryTable->getParamDefault( @@ -452,9 +509,9 @@ protected function generateResponse( $jsTableNamesId = str_replace('_', '-', $funcTablename) . $suffix; $uid = $row['uid']; - $errorId = tx_ttproducts_model_control::getBasketInputErrorIdPrefix() . '-' . $uid; + $errorId = $parameterApi->getBasketInputErrorIdPrefix() . '-' . $uid; $objResponse->addAssign($errorId, 'innerHTML', ''); - $basketIntoId = tx_ttproducts_model_control::getBasketIntoIdPrefix() . '-' . $uid; + $basketIntoId = $parameterApi->getBasketIntoIdPrefix() . '-' . $uid; $objResponse->addClear($basketIntoId, 'disabled'); $markerKey = $itemTableView->getMarkerKey(''); @@ -504,8 +561,6 @@ protected function generateResponse( $tmp = ''; $fieldViewObj = $itemTableView->getObj($class); $linkWrap = false; - $basketApi = GeneralUtility::makeInstance(BasketApi::class); - $basketExtra = $basketApi->getBasketExtra(); $modifiedValue = $fieldViewObj->getRowMarkerArray( $funcTablename, @@ -517,7 +572,7 @@ protected function generateResponse( $tmpArray, $theCode, '', - $basketExtra, + $basketApi->getBasketExtra(), tx_ttproducts_control_basket::getRecs(), $bSkip, true, @@ -536,10 +591,14 @@ protected function generateResponse( if (!in_array($field, $variantArray)) { if (($position = strpos($field, '_uid')) !== false) { + if (!$useFal) { + continue 2; + } $fieldId = substr($field, 0, $position); } else { if ( - in_array($field, ['image', 'smallimage']) + in_array($field, ['image', 'smallimage']) && + $useFal ) { continue 2; } @@ -562,6 +621,7 @@ protected function generateResponse( $imageRow['uid'] = $rowArticle['uid']; $imageRow['pid'] = $rowArticle['pid']; } + $imageRenderObj = 'image'; if ($theCode == 'LIST' || $theCode == 'SEARCH') { $imageRenderObj = 'listImage'; @@ -576,17 +636,15 @@ protected function generateResponse( } } elseif ( $theCode == 'SINGLE' && - strpos($field, 'smallimage') !== false + str_contains($field, 'smallimage') ) { $imageRenderObj = 'smallImage'; } - $imageArray = $imageObj->getFileArray( $imageTablename, $imageRow, - $field, - false + $field ); if ( @@ -607,8 +665,6 @@ protected function generateResponse( $theCode ); $specialConf = []; - $tmpArray = []; - $imgCodeArray = $imageViewObj->getCodeMarkerArray( 'tt_products_articles', 'ARTICLE_IMAGE', @@ -617,13 +673,14 @@ protected function generateResponse( $imageArray, $fieldMarkerArray, $dirname, - $mediaNum, $imageRenderObj, $linkWrap, $markerArray, $theImgDAM, - $specialConf + $specialConf, + $mediaNum ); + $v = $imgCodeArray; } else { $v = ''; @@ -632,8 +689,7 @@ protected function generateResponse( break; case 'inStock': - $basketIntoPrefix = tx_ttproducts_model_control::getBasketIntoIdPrefix(); - + $basketIntoPrefix = $parameterApi->getBasketIntoIdPrefix(); if ($v > 0) { $objResponse->addClear( $basketIntoPrefix . '-' . $uid, @@ -671,18 +727,23 @@ protected function generateResponse( $markerArray = []; $theMarkerArray = []; $newRow = $itemTableView->modifyFieldObject( + $theMarkerArray, $row, $modifiedRow, $tableconf, $markerPrefix, $suffix, $fieldMarkerArray, - $markerArray, - $theMarkerArray + $markerArray ); foreach ($newRow as $field => $v) { - $tagId = $jsTableNamesId . '-' . $view . '-' . $uid . '-' . $field; + $tagId = ControlApi::getTagId( + $jsTableNamesId, + $view, + $uid, + $field + ); if (is_array($v)) { reset($v); @@ -708,12 +769,12 @@ protected function generateResponse( public function commands($cmd, $param1 = '', $param2 = '', $param3 = '') { - $objResponse = new tx_taxajax_response($this->ajax->taxajax->getCharEncoding()); + $objResponse = new tx_taxajax_response($this->ajax->getTaxAjax()->getCharEncoding()); switch ($cmd) { default: $hookVar = 'ajaxCommands'; - if ($hookVar && isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT][$hookVar]) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT][$hookVar])) { + if ($hookVar && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT][$hookVar])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT][$hookVar] as $classRef) { $hookObj = GeneralUtility::makeInstance($classRef); if (method_exists($hookObj, 'init')) { @@ -767,7 +828,7 @@ public function showArticle($data) $result = ''; $pibaseObj = GeneralUtility::makeInstance('tx_ttproducts_pi1_base'); $mainObj = GeneralUtility::makeInstance('tx_ttproducts_main'); - + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $pibaseObj->setContentObjectRenderer($this->cObj); if ( @@ -777,25 +838,24 @@ public function showArticle($data) is_array($data[$pibaseObj->prefixId]) ) { foreach ($data[$pibaseObj->prefixId] as $k => $v) { - tx_ttproducts_model_control::setAndVar($k, $v); + $parameterApi->setAndVar($k, $v); } } - $this->ajax->conf = $data['conf']; - $objResponse = new tx_taxajax_response($this->ajax->taxajax->getCharEncoding()); + $this->ajax->setConf($data['conf']); + $objResponse = new tx_taxajax_response($this->ajax->getTaxAjax()->getCharEncoding()); $content = ''; $bDoProcessing = $mainObj->init( - $content, $cnfObj->getConf(), $cnfObj->getConfig(), + $this->getRequest(), $this->cObj, 'tx_ttproducts_pi1_base', $errorCode, true ); - if ( isset($contentRow) && is_array($contentRow) && @@ -823,7 +883,6 @@ public function showArticle($data) $objResponse->addAssign($tagId, 'innerHTML', $content); $result = $objResponse->getXML(); - // return the XML response generated by the tx_taxajax_response object return $result; } @@ -835,9 +894,10 @@ public function showList($data) $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $pibaseObj = GeneralUtility::makeInstance('tx_ttproducts_pi1_base'); $mainObj = GeneralUtility::makeInstance('tx_ttproducts_main'); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); - $piVars = tx_ttproducts_model_control::getPiVars(); - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $piVars = $parameterApi->getPiVars(); + $prefixId = $parameterApi->getPrefixId(); if (isset($piVars) && is_array($piVars)) { if ( @@ -859,8 +919,8 @@ public function showList($data) // We put our incomming data to the regular piVars $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $parameterApi->setPiVars($piVars); - // We put our incomming data to the regular piVars - tx_ttproducts_model_control::setPiVars($piVars); + // $pibaseObj->piVars = $piVars; + $pibaseObj->setContentObjectRenderer($this->cObj); // Instantiate the tx_xajax_response object @@ -868,9 +928,9 @@ public function showList($data) $bDoProcessing = $mainObj->init( - $content, $cnfObj->getConf(), $cnfObj->getConfig(), + $this->getRequest(), $this->cObj, 'tx_ttproducts_pi1_base', $errorCode, @@ -914,7 +974,7 @@ public function showList($data) public function destruct(): void { - $controlCreatorObj = GeneralUtility::makeInstance('tx_ttproducts_control_creator'); + $controlCreatorObj = GeneralUtility::makeInstance(Creator::class); $controlCreatorObj->destruct(); $modelCreatorObj = GeneralUtility::makeInstance('tx_ttproducts_model_creator'); @@ -923,4 +983,9 @@ public function destruct(): void $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $tablesObj->destruct(); } + + private function getRequest(): ServerRequestInterface + { + return $GLOBALS['TYPO3_REQUEST']; + } } diff --git a/ext_localconf.php b/ext_localconf.php index f827e84e8..0b4764272 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -9,6 +9,10 @@ define('TT_PRODUCTS_EXT', 'tt_products'); } + if (!defined('TT_PRODUCTS_SESSION')) { + define('TT_PRODUCTS_SESSION', 'TX_TTPRODUCTS'); + } + if (!defined('PATH_BE_TTPRODUCTS')) { define('PATH_BE_TTPRODUCTS', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey)); } diff --git a/lib/class.tx_ttproducts_billdelivery.php b/lib/class.tx_ttproducts_billdelivery.php index 52c1a3bf6..b9a4fd464 100644 --- a/lib/class.tx_ttproducts_billdelivery.php +++ b/lib/class.tx_ttproducts_billdelivery.php @@ -43,6 +43,7 @@ use JambageCom\TtProducts\Api\BasketApi; use JambageCom\TtProducts\Api\PaymentShippingHandling; +use JambageCom\TtProducts\View\Bill; class tx_ttproducts_billdelivery implements SingletonInterface { @@ -99,10 +100,11 @@ public function generateBill( $orderArray, $basketExtra, $basketRecs, + $feUserRecord, $type, $generationConf ) { - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $infoViewObj = GeneralUtility::makeInstance('tx_ttproducts_info_view'); $productRowArray = []; // Todo: make this a parameter @@ -147,17 +149,17 @@ public function generateBill( str_replace('_', '-', strtolower($orderArray['bill_no'])) . '-' . $orderArray['tracking_code'], 'pdf' ); - $className = 'tx_ttproducts_pdf_view'; + $className = Bill::class; if ( ExtensionManagementUtility::isLoaded('fpdf') // use FPDF ) { $className = 'tx_ttproducts_fpdf_view'; } - $pdfViewObj = GeneralUtility::makeInstance($className); - $result = $pdfViewObj->generate( + $billViewObj = GeneralUtility::makeInstance($className); + $result = $billViewObj->generate( $cObj, - $basketView, + $basketViewObj, $infoViewObj, $templateCode, $mainMarkerArray, @@ -167,17 +169,19 @@ public function generateBill( $productRowArray, $basketExtra, $basketRecs, + $feUserRecord, $typeCode, $generationConf, $absFileName ); } elseif ($generationType == 'html') { $subpart = $typeCode . '_TEMPLATE'; - $content = $basketView->getView( + $content = $basketViewObj->getView( $errorCode, $templateCode, $typeCode, $infoViewObj, + $feUserRecord, false, true, $calculatedArray, @@ -237,14 +241,14 @@ public function getInformation( $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $conf = $cnfObj->getConf(); - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $productRowArray = []; // Todo: make this a parameter $globalMarkerArray = $markerObj->getGlobalMarkerArray(); $orderObj = $tablesObj->get('sys_products_orders'); $infoObj = GeneralUtility::makeInstance('tx_ttproducts_info'); $infoViewObj = GeneralUtility::makeInstance('tx_ttproducts_info_view'); - // $paymentshippingObj = GeneralUtility::makeInstance('tx_ttproducts_paymentshipping'); + $feUserRecord = CustomerApi::getFeUserRecord(); // initialize order data. $orderData = $orderObj->getOrderData($orderRow); @@ -262,9 +266,10 @@ public function getInformation( $basketRec = BasketApi::getBasketRec($orderRow); $basketExtra = PaymentShippingHandling::getBasketExtras( + $conf, $tablesObj, $basketRec, - $conf + $feUserRecord ); if ($type == 'bill') { @@ -279,11 +284,12 @@ public function getInformation( $orderArray['uid'] = $orderRow['uid']; $orderArray['crdate'] = $orderRow['crdate']; - $content = $basketView->getView( + $content = $basketViewObj->getView( $errorCode, $templateCode, $theCode, $infoViewObj, + $feUserRecord, false, false, $calculatedArray, diff --git a/lib/class.tx_ttproducts_creditpoints_div.php b/lib/class.tx_ttproducts_creditpoints_div.php index 15f36a0c5..5403c3489 100644 --- a/lib/class.tx_ttproducts_creditpoints_div.php +++ b/lib/class.tx_ttproducts_creditpoints_div.php @@ -1,29 +1,32 @@ fe_user) && - is_array($GLOBALS['TSFE']->fe_user->user) - ) { - $result = $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints']; - } + $result = $feUserRecord['tt_products_creditpoints'] ?? 0; return $result; } @@ -73,7 +68,7 @@ public static function getPriceFactor($conf) return $pricefactor; } - public static function getUsedCreditpoints($recs) + public static function getUsedCreditpoints($feUserRecord, $recs) { $creditpoints = 0; $creditpointsObj = GeneralUtility::makeInstance('tx_ttproducts_field_creditpoints'); @@ -91,7 +86,7 @@ public static function getUsedCreditpoints($recs) $creditpoints = $recs['tt_products']['creditpoints']; } - $userCreditpoints = tx_ttproducts_creditpoints_div::getCreditPointsFeuser(); + $userCreditpoints = self::getCreditPointsFeuser($feUserRecord); if ($creditpoints > $userCreditpoints) { $creditpoints = $userCreditpoints; @@ -149,20 +144,20 @@ public static function getCreditPoints($amount, $creditpointsConf) public static function addCreditPoints($username, $creditpoints): void { if ($username) { - $uid_voucher = ''; + $uidFeuser = ''; // get the "old" creditpoints for the user - $res1 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, tt_products_creditpoints', 'fe_users', 'username=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($username, 'tt_products_creditpoints')); + $res1 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, tt_products_creditpoints', 'fe_users', 'username=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($username, 'fe_users')); if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1)) { $ttproductscreditpoints = $row['tt_products_creditpoints']; - $uid_voucher = $row['uid']; + $uidFeuser = $row['uid']; } - if ($uid_voucher) { + if ($uidFeuser) { $fieldsArrayFeUserCredit = []; $fieldsArrayFeUserCredit['tt_products_creditpoints'] = $ttproductscreditpoints + $creditpoints; $GLOBALS['TYPO3_DB']->exec_UPDATEquery( 'fe_users', - 'uid=' . intval($uid_voucher), + 'uid=' . intval($uidFeuser), $fieldsArrayFeUserCredit ); } diff --git a/lib/class.tx_ttproducts_gifts_div.php b/lib/class.tx_ttproducts_gifts_div.php index 41f72ce2e..b21a0e09f 100644 --- a/lib/class.tx_ttproducts_gifts_div.php +++ b/lib/class.tx_ttproducts_gifts_div.php @@ -231,7 +231,7 @@ public static function deleteGiftNumber($giftnumber): void if ($count == 1) { unset($basketExt['gift']); } - tx_ttproducts_control_basket::storeBasketExt($basketExt); + $basketApi->storeBasketExt($basketExt); } } diff --git a/lib/class.tx_ttproducts_tracking.php b/lib/class.tx_ttproducts_tracking.php index 1ccd2f5de..79427b38b 100644 --- a/lib/class.tx_ttproducts_tracking.php +++ b/lib/class.tx_ttproducts_tracking.php @@ -199,13 +199,12 @@ public function getTrackingInformation( $orderObj = $tablesObj->get('sys_products_orders'); $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); $languageObj = GeneralUtility::makeInstance(Localization::class); - $basketView = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); + $basketViewObj = GeneralUtility::makeInstance('tx_ttproducts_basket_view'); $infoObj = GeneralUtility::makeInstance('tx_ttproducts_info'); $infoViewObj = GeneralUtility::makeInstance('tx_ttproducts_info_view'); - // $paymentshippingObj = GeneralUtility::makeInstance('tx_ttproducts_paymentshipping'); $theTable = 'sys_products_orders'; $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $orderData = $orderObj->getOrderData($orderRow); $statusCodeArray = []; @@ -222,12 +221,14 @@ public function getTrackingInformation( is_array($orderRow) && $orderRow['uid'] ) { + $feUserRecord = CustomerApi::getFeUserRecord(); $basketRec = BasketApi::getBasketRec($orderRow); $basketExtra = PaymentShippingHandling::getBasketExtras( + $conf, $tablesObj, $basketRec, - $this->conf + $feUserRecord ); $statusCodeArray = $this->getStatusCodeArray(); @@ -282,9 +283,10 @@ public function getTrackingInformation( $basketRec = BasketApi::getBasketRec($orderRow); $basketExtra = PaymentShippingHandling::getBasketExtras( + $this->conf, $tablesObj, $basketRec, - $this->conf + $feUserRecord ); $whereGift = $this->conf['whereGift']; @@ -723,11 +725,12 @@ public function getTrackingInformation( $customerEmail = $orderRow['email']; $globalMarkerArray['###CUSTOMER_RECIPIENTS_EMAIL###'] = $customerEmail; $markerArray['###ORDER_HTML_OUTPUT###'] = - $basketView->getView( + $basketViewObj->getView( $errorCode, $templateCode, 'TRACKING', $infoViewObj, + $feUserRecord, false, false, $calculatedArray, diff --git a/model/class.tx_ttproducts_basket.php b/model/class.tx_ttproducts_basket.php index 29067d4c2..1e4b4121c 100644 --- a/model/class.tx_ttproducts_basket.php +++ b/model/class.tx_ttproducts_basket.php @@ -119,7 +119,7 @@ public function init( $viewTableObj = $tablesObj->get($funcTablename); $basketExt = $basketApi->getBasketExt(); - $basketExtRaw = tx_ttproducts_control_basket::getBasketExtRaw(); + $basketExtRaw = $parameterApi->getBasketExtRaw(); $basketInputConf = $cnfObj->getBasketConf('view', 'input'); if (isset($basketInputConf) && is_array($basketInputConf)) { @@ -356,9 +356,9 @@ public function init( if ($bStoreBasket) { if (is_array($basketExt) && count($basketExt)) { - tx_ttproducts_control_basket::storeBasketExt($basketExt); + $basketApi->storeBasketExt($basketExt); } else { - tx_ttproducts_control_basket::storeBasketExt([]); + $basketApi->storeBasketExt([]); } } } @@ -674,7 +674,7 @@ public function removeGift($giftnumber, $uid, $variant): void } } - tx_ttproducts_control_basket::storeBasketExt($basketExt); + $basketApi->storeBasketExt($basketExt); } public function getMaxCount($quantity, $uid = 0) @@ -881,15 +881,18 @@ public function getQuantityArray($uidArray, &$rowArray) } public function getItem(// ToDo: Den Preis aus dem Download und der PDF Datei berücksichtigen + $mergePrices, $basketExt, $basketExtra, $basketRecs, - $row, // must come from table tt_products + array $row, // This comes from the table tt_products, however the price can be have been modified by article rows already $fetchMode, + &$taxInfoArray = [], $funcTablename = '', - $externalRowArray = [], // Download - $bEnableTaxZero = false + $externalRowArray = [], // für Download + $enableTaxZero = false ) { + $basketApi = GeneralUtility::makeInstance(BasketApi::class); $calculationField = FieldInterface::PRICE_CALCULATED; $pricetablesCalculator = GeneralUtility::makeInstance('tx_ttproducts_pricetablescalc'); @@ -951,7 +954,7 @@ public function getItem(// ToDo: Den Preis aus dem Download und der PDF Datei be !empty($externalRowArray) ) { $newPrice = $priceRow['price']; - $priceIsModified = BasketApi::getRecordvariantAndPriceFromRows( + $priceIsModified = $basketApi->getRecordvariantAndPriceFromRows( $recordVariant, $newPrice, $externalUidArray, @@ -980,8 +983,9 @@ public function getItem(// ToDo: Den Preis aus dem Download und der PDF Datei be } $count = - tx_ttproducts_control_basket::getBasketCount( + $basketApi->getBasketCount( $row, + $basketExt, $variant, $this->conf['quantityIsFloat'] ); @@ -1026,13 +1030,13 @@ public function getItem(// ToDo: Den Preis aus dem Download und der PDF Datei be } $parentProductCount = - tx_ttproducts_control_basket::getBasketCount( + $basketApi->getBasketCount( $row, + $basketExt, $variant, $this->conf['quantityIsFloat'], true ); - foreach ($articleRowArray as $articleRow) { if ( is_object($graduatedPriceObj) && @@ -1107,8 +1111,9 @@ public function getItem(// ToDo: Den Preis aus dem Download und der PDF Datei be $discountRoundFormat, $priceRow, $totalDiscountField, - $bEnableTaxZero + $enableTaxZero ); + $price2TaxArray = $priceObj->getPriceTaxArray( $taxInfoArray, $this->conf['discountPriceMode'] ?? '', @@ -1119,7 +1124,7 @@ public function getItem(// ToDo: Den Preis aus dem Download und der PDF Datei be $discountRoundFormat, $priceRow, $totalDiscountField, - $bEnableTaxZero + $enableTaxZero ); $priceTaxArray = array_merge($priceTaxArray, $price2TaxArray); @@ -1184,11 +1189,14 @@ public function getItemRow( $bextVarLine, $useArticles, $funcTablename, + $basketExt = [], $mergeAttributeFields = true ) { $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $viewTableObj = $tablesObj->get($funcTablename); $variantSeparator = $viewTableObj->getVariant()->getSplitSeparator(); + $basketApi = GeneralUtility::makeInstance(BasketApi::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $uid = $row['uid']; $calculationField = FieldInterface::PRICE_CALCULATED; @@ -1257,7 +1265,7 @@ public function getItemRow( foreach ($variantArray as $variant) { $parts = explode('=', $variant); if (isset($parts) && is_array($parts) && count($parts) == 2) { - $funcTablename = tx_ttproducts_model_control::getParamsTable($parts['0']); + $funcTablename = $parameterApi->getParamsTable($parts['0']); if ($funcTablename !== false) { $localTableObj = $tablesObj->get($funcTablename); $recordRow = $localTableObj->get(intval($parts['1'])); @@ -1341,15 +1349,19 @@ public function getItemRow( if ($mergeAttributeFields) { $pricetablesCalculator = GeneralUtility::makeInstance('tx_ttproducts_pricetablescalc'); + $count = - tx_ttproducts_control_basket::getBasketCount( + $basketApi->getBasketCount( $currRow, + $basketExt, $bextVarLine, $this->conf['quantityIsFloat'] ); + $parentProductCount = - tx_ttproducts_control_basket::getBasketCount( + $basketApi->getBasketCount( $currRow, + $basketExt, $bextVarLine, $this->conf['quantityIsFloat'], true @@ -1411,6 +1423,7 @@ public function create( $itemTableConf = $cnfObj->getTableConf($funcTablename, $theCode); $viewTableObj = $tablesObj->get($funcTablename, false); $orderBy = $viewTableObj->getTableObj()->transformOrderby($itemTableConf['orderBy']); + $mergePrices = true; $calculObj = GeneralUtility::makeInstance('tx_ttproducts_basket_calculate'); $calculatedArray = [ 'count' => 0, @@ -1463,7 +1476,8 @@ public function create( $row, $bextVarLine, $useArticles, - $funcTablename + $funcTablename, + $basketExt, ); $productsArray[$prodCount] = $currRow; $prodCount++; @@ -1488,7 +1502,7 @@ public function create( $uidArray = []; $categoryQuantity = []; $categoryArray = []; - $bEnableTaxZero = true; // Die Produkte im Warenkorb werden sofort umgerechnet, damit sie die korrigierten Steuern und Preise enthalten. Hier ist die Steuer 0 erlaubt und darf später nicht mehr durch TAXpercentage überschrieben werden. + $enableTaxZero = true; // Die Produkte im Warenkorb werden sofort umgerechnet, damit sie die korrigierten Steuern und Preise enthalten. Hier ist die Steuer 0 erlaubt und darf später nicht mehr durch TAXpercentage überschrieben werden. foreach ($productsArray as $k1 => $row) { $uid = $row['uid']; @@ -1543,6 +1557,7 @@ public function create( $newItem = $this->getItem( + $mergePrices, $basketExt, $basketExtra, $basketRecs, @@ -1550,7 +1565,7 @@ public function create( 'useExt', $funcTablename, $externalRowArray, // new Download - $bEnableTaxZero + $enableTaxZero ); $count = $newItem['count']; @@ -1592,38 +1607,42 @@ public function getMaxTax() return $this->maxTax; } - // get a virtual basket public function getItemArrayFromRow( - $row, + &$tax, // neu + &$taxInfoArray, // neu + array $row, $basketExt, $basketExtra, $basketRecs, $funcTablename, - $externalRowArray = [], // Download - $bEnableTaxZero = false + $fetchMode = 'useExt', + $externalRowArray = [], + $enableTaxZero = false ) { $prodFuncTablename = 'tt_products'; $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $viewTableObj = $tablesObj->get($prodFuncTablename); - $result = false; if (isset($row) && is_array($row)) { $itemArray = []; $newItem = - $this->getItem( - $basketExt, - $basketExtra, - $basketRecs, - $row, - 'useExt', - $funcTablename, - $externalRowArray, // Download - $bEnableTaxZero - ); + $this->getItem( + true, // $mergePrices + $basketExt, + $basketExtra, + $basketRecs, + $row, + $fetchMode, + $taxInfoArray, + $funcTablename, + $externalRowArray, + $enableTaxZero + ); if (!empty($newItem)) { + $tax = $newItem['tax']; $count = $newItem['count']; $weight = $newItem['weight']; $itemArray[$row[$viewTableObj->fieldArray['itemnumber']]][] = $newItem; @@ -1673,29 +1692,44 @@ public function getMergedRowFromItemArray(array $itemArray, $basketExtra) return $row; } - public function calculate(&$itemArray): void - { + public function calculate( + &$itemArray, + $basketExt, + $basketExtra, + $basketRecs, + $tax, // neu + $storeCalculation = true, // neu + $recalculateItems = false + ): void { $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $useArticles = $cnfObj->getUseArticles(); - $basketApi = GeneralUtility::makeInstance(BasketApi::class); $calculObj = GeneralUtility::makeInstance('tx_ttproducts_basket_calculate'); + // Die Berechnungen müssen ein 2. Mal gemacht werden, weil es diverse Staffelpreis Rechennmodelle gibt. + $calculatedArray = []; $calculObj->calculate( - $basketApi->getBasketExt(), - $basketApi->getBasketExtra(), - tx_ttproducts_control_basket::getRecs(), + $itemArray, + $calculatedArray, + $basketExt, + $basketExtra, + $basketRecs, tx_ttproducts_control_basket::getFuncTablename(), $useArticles, - $this->getMaxTax(), + doubleval($tax) > $this->getMaxTax() ? doubleval($tax) : $this->getMaxTax(), tx_ttproducts_control_basket::getRoundFormat(), - $itemArray + $recalculateItems ); + + if ($storeCalculation) { + $calculObj->setCalculatedArray($calculatedArray); + } } - public function calculateSums(): void + public function calculateSums($feUserRecord): void { $getShopCountryCode = ''; + $recs = tx_ttproducts_control_basket::getRecs(); $pricefactor = tx_ttproducts_creditpoints_div::getPriceFactor($this->conf); - $creditpoints = tx_ttproducts_creditpoints_div::getUsedCreditpoints($this->recs); + $creditpoints = tx_ttproducts_creditpoints_div::getUsedCreditpoints($feUserRecord, $recs); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $staticTaxObj = $tablesObj->get('static_taxes', false); if ( @@ -1706,7 +1740,9 @@ public function calculateSums(): void } $calculObj = GeneralUtility::makeInstance('tx_ttproducts_basket_calculate'); + $calculatedArray = $calculObj->getCalculatedArray(); $calculObj->calculateSums( + $calculatedArray, tx_ttproducts_control_basket::getRoundFormat(), $pricefactor, $creditpoints, diff --git a/model/class.tx_ttproducts_basket_calculate.php b/model/class.tx_ttproducts_basket_calculate.php index e9ced975b..237a24bc8 100644 --- a/model/class.tx_ttproducts_basket_calculate.php +++ b/model/class.tx_ttproducts_basket_calculate.php @@ -118,55 +118,56 @@ public static function getGoodsTotalTax( return $goodsTotalTax; } - public function clear($taxMode = 1): void + public function clear(&$calculatedArray, $taxMode = 1): void { - $this->calculatedArray = $this->getBaseCalculatedArray(); - $this->calculatedArray['priceTax'] = []; - $this->calculatedArray['priceNoTax'] = []; - $this->calculatedArray['price0Tax'] = []; - $this->calculatedArray['price0NoTax'] = []; - $this->calculatedArray['price2Tax'] = []; - $this->calculatedArray['price2NoTax'] = []; - $this->calculatedArray['deposittax'] = []; - $this->calculatedArray['depositnotax'] = []; - $this->calculatedArray['payment'] = []; - $this->calculatedArray['shipping'] = []; - $this->calculatedArray['handling'] = - [ - '0' => [], - ]; - - $this->calculatedArray['priceTax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['priceNoTax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['price0Tax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['price0NoTax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['price2Tax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['price2NoTax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'] = []; - $this->calculatedArray['deposittax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['depositnotax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['noDiscountPriceTax']['goodstotal']['ALL'] = 0; - $this->calculatedArray['noDiscountPriceNoTax']['goodstotal']['ALL'] = 0; + $baseCalculatedArray = $this->getBaseCalculatedArray(); + $calculatedArray = array_merge($calculatedArray, $baseCalculatedArray); + $calculatedArray['priceTax'] = []; + $calculatedArray['priceNoTax'] = []; + $calculatedArray['price0Tax'] = []; + $calculatedArray['price0NoTax'] = []; + $calculatedArray['price2Tax'] = []; + $calculatedArray['price2NoTax'] = []; + $calculatedArray['deposittax'] = []; + $calculatedArray['depositnotax'] = []; + $calculatedArray['payment'] = []; + $calculatedArray['shipping'] = []; + $calculatedArray['handling'] = + [ + '0' => [], + ]; + + $calculatedArray['priceTax']['goodstotal']['ALL'] = 0; + $calculatedArray['priceNoTax']['goodstotal']['ALL'] = 0; + $calculatedArray['price0Tax']['goodstotal']['ALL'] = 0; + $calculatedArray['price0NoTax']['goodstotal']['ALL'] = 0; + $calculatedArray['price2Tax']['goodstotal']['ALL'] = 0; + $calculatedArray['price2NoTax']['goodstotal']['ALL'] = 0; + $calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'] = []; + $calculatedArray['deposittax']['goodstotal']['ALL'] = 0; + $calculatedArray['depositnotax']['goodstotal']['ALL'] = 0; + $calculatedArray['noDiscountPriceTax']['goodstotal']['ALL'] = 0; + $calculatedArray['noDiscountPriceNoTax']['goodstotal']['ALL'] = 0; if ($taxMode == '1') { - $this->calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'] = []; - $this->calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'] = []; - $this->calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'] = []; - $this->calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'] = []; - $this->calculatedArray['depositnotax']['goodssametaxtotal']['ALL'] = []; + $calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'] = []; + $calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'] = []; + $calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'] = []; + $calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'] = []; + $calculatedArray['depositnotax']['goodssametaxtotal']['ALL'] = []; } - $this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'] = []; - $this->calculatedArray['price2NoTax']['sametaxtotal']['ALL'] = []; - $this->calculatedArray['price0NoTax']['sametaxtotal']['ALL'] = []; - $this->calculatedArray['categoryPriceNoTax']['sametaxtotal']['ALL'] = []; - $this->calculatedArray['depositnotax']['sametaxtotal']['ALL'] = []; - - $this->calculatedArray['shipping']['priceTax'] = 0; - $this->calculatedArray['shipping']['priceNoTax'] = 0; - $this->calculatedArray['payment']['priceTax'] = 0; - $this->calculatedArray['payment']['priceNoTax'] = 0; - $this->calculatedArray['handling']['0']['priceTax'] = 0; - $this->calculatedArray['handling']['0']['priceNoTax'] = 0; + $calculatedArray['priceNoTax']['sametaxtotal']['ALL'] = []; + $calculatedArray['price2NoTax']['sametaxtotal']['ALL'] = []; + $calculatedArray['price0NoTax']['sametaxtotal']['ALL'] = []; + $calculatedArray['categoryPriceNoTax']['sametaxtotal']['ALL'] = []; + $calculatedArray['depositnotax']['sametaxtotal']['ALL'] = []; + + $calculatedArray['shipping']['priceTax'] = 0; + $calculatedArray['shipping']['priceNoTax'] = 0; + $calculatedArray['payment']['priceTax'] = 0; + $calculatedArray['payment']['priceNoTax'] = 0; + $calculatedArray['handling']['0']['priceTax'] = 0; + $calculatedArray['handling']['0']['priceNoTax'] = 0; } /** @@ -179,14 +180,15 @@ public function clear($taxMode = 1): void * ... which holds the total amount, the final list of products and the price of payment and shipping!! */ public function calculate( + &$itemArray, + &$calculatedArray, // neu $basketExt, $basketExtra, - $basketRecs, + $basketRecs, // neu $funcTablename, $useArticles, $maxTax, - $roundFormat, // Todo: remove unused format - &$itemArray + $roundFormat, ): void { $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); // $paymentshippingObj = GeneralUtility::makeInstance('tx_ttproducts_paymentshipping'); @@ -204,7 +206,7 @@ public function calculate( $iso3Seller = PaymentApi::getStoreIso3('DEU'); $iso3Buyer = CustomerApi::getBillingIso3('DEU'); - $this->clear($conf['TAXmode']); + $this->clear($calculatedArray, $conf['TAXmode']); if (tx_ttproducts_static_tax::isInstalled()) { $shippingTax = @@ -393,16 +395,16 @@ public function calculate( $itemArray[$sort][$k1]['total2NoTax'] = $itemArray[$sort][$k1]['price2NoTax'] * $count; $totalDepositNoTax = ($itemArray[$sort][$k1]['depositnotax'] ?? 0) * $count; - $this->calculatedArray['price0NoTax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['total0NoTax']; - $this->calculatedArray['priceNoTax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['totalNoTax']; - if (!isset($this->calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$row['category']])) { - $this->calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$row['category']] = 0; + $calculatedArray['price0NoTax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['total0NoTax']; + $calculatedArray['priceNoTax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['totalNoTax']; + if (!isset($calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$row['category']])) { + $calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$row['category']] = 0; } - $this->calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$row['category']] += $itemArray[$sort][$k1]['totalNoTax']; - $this->calculatedArray['price2NoTax']['goodstotal']['ALL'] += $price2NoTax * $count; - $this->calculatedArray['depositnotax']['goodstotal']['ALL'] += $totalDepositNoTax; + $calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$row['category']] += $itemArray[$sort][$k1]['totalNoTax']; + $calculatedArray['price2NoTax']['goodstotal']['ALL'] += $price2NoTax * $count; + $calculatedArray['depositnotax']['goodstotal']['ALL'] += $totalDepositNoTax; - $this->calculatedArray['noDiscountPriceTax']['goodstotal']['ALL'] += + $calculatedArray['noDiscountPriceTax']['goodstotal']['ALL'] += $priceObj->getPrice( $basketExtra, $basketRecs, @@ -412,7 +414,7 @@ public function calculate( $conf['TAXincluded'], $bEnableTaxZero ); - $this->calculatedArray['noDiscountPriceNoTax']['goodstotal']['ALL'] += + $calculatedArray['noDiscountPriceNoTax']['goodstotal']['ALL'] += $priceObj->getPrice( $basketExtra, $basketRecs, @@ -447,41 +449,41 @@ public function calculate( false, $bEnableTaxZero ); - if (!isset($this->calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'][$taxstr])) { - $this->calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'][$taxstr] = 0; + if (!isset($calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'][$taxstr])) { + $calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'][$taxstr] = 0; } - $this->calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'][$taxstr] += $itemArray[$sort][$k1]['totalNoTax']; - if (!isset($this->calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'][$taxstr])) { - $this->calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'][$taxstr] = 0; + $calculatedArray['priceNoTax']['goodssametaxtotal']['ALL'][$taxstr] += $itemArray[$sort][$k1]['totalNoTax']; + if (!isset($calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'][$taxstr])) { + $calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'][$taxstr] = 0; } - $this->calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'][$taxstr] += $itemArray[$sort][$k1]['total2NoTax']; - if (!isset($this->calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'][$taxstr][$row['category']])) { - $this->calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'][$taxstr][$row['category']] = 0; + $calculatedArray['price2NoTax']['goodssametaxtotal']['ALL'][$taxstr] += $itemArray[$sort][$k1]['total2NoTax']; + if (!isset($calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'][$taxstr][$row['category']])) { + $calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'][$taxstr][$row['category']] = 0; } - $this->calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'][$taxstr][$row['category']] += $itemArray[$sort][$k1]['totalNoTax']; - if (!isset($this->calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'][$taxstr])) { - $this->calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'][$taxstr] = 0; + $calculatedArray['categoryPriceNoTax']['goodssametaxtotal']['ALL'][$taxstr][$row['category']] += $itemArray[$sort][$k1]['totalNoTax']; + if (!isset($calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'][$taxstr])) { + $calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'][$taxstr] = 0; } - $this->calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'][$taxstr] += $itemArray[$sort][$k1]['total0NoTax']; + $calculatedArray['price0NoTax']['goodssametaxtotal']['ALL'][$taxstr] += $itemArray[$sort][$k1]['total0NoTax']; - if (!isset($this->calculatedArray['depositnotax']['goodssametaxtotal']['ALL'][$taxstr])) { - $this->calculatedArray['depositnotax']['goodssametaxtotal']['ALL'][$taxstr] = 0; + if (!isset($calculatedArray['depositnotax']['goodssametaxtotal']['ALL'][$taxstr])) { + $calculatedArray['depositnotax']['goodssametaxtotal']['ALL'][$taxstr] = 0; } - $this->calculatedArray['depositnotax']['goodssametaxtotal']['ALL'][$taxstr] += $totalDepositNoTax; + $calculatedArray['depositnotax']['goodssametaxtotal']['ALL'][$taxstr] += $totalDepositNoTax; if (!empty($taxInfo)) { foreach ($taxInfo as $countryCode => $countryRows) { foreach ($countryRows as $k => $taxRow) { $countryTax = strval($taxRow['tx_rate']); - if (!isset($this->calculatedArray['priceNoTax']['goodssametaxtotal'][$countryCode][$countryTax])) { - $this->calculatedArray['priceNoTax']['goodssametaxtotal'][$countryCode][$countryTax] = 0; + if (!isset($calculatedArray['priceNoTax']['goodssametaxtotal'][$countryCode][$countryTax])) { + $calculatedArray['priceNoTax']['goodssametaxtotal'][$countryCode][$countryTax] = 0; } - $this->calculatedArray['priceNoTax']['goodssametaxtotal'][$countryCode][$countryTax] += $itemArray[$sort][$k1]['totalNoTax']; - if (!isset($this->calculatedArray['priceNoTax']['goodstotal'][$countryCode])) { - $this->calculatedArray['priceNoTax']['goodstotal'][$countryCode] = 0; + $calculatedArray['priceNoTax']['goodssametaxtotal'][$countryCode][$countryTax] += $itemArray[$sort][$k1]['totalNoTax']; + if (!isset($calculatedArray['priceNoTax']['goodstotal'][$countryCode])) { + $calculatedArray['priceNoTax']['goodstotal'][$countryCode] = 0; } - $this->calculatedArray['priceNoTax']['goodstotal'][$countryCode] += $itemArray[$sort][$k1]['totalNoTax']; + $calculatedArray['priceNoTax']['goodstotal'][$countryCode] += $itemArray[$sort][$k1]['totalNoTax']; } } } @@ -491,19 +493,19 @@ public function calculate( $totalDepositTax = $itemArray[$sort][$k1]['deposittax'] * $count; // Fills this array with the product records. Reason: Sorting them by category (based on the page, they reside on) - $this->calculatedArray['priceTax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['totalTax']; - $this->calculatedArray['price0Tax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['total0Tax']; - $this->calculatedArray['priceTax']['goodsdeposittotal']['ALL'] += $itemArray[$sort][$k1]['totalDepositTax']; + $calculatedArray['priceTax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['totalTax']; + $calculatedArray['price0Tax']['goodstotal']['ALL'] += $itemArray[$sort][$k1]['total0Tax']; + $calculatedArray['priceTax']['goodsdeposittotal']['ALL'] += $itemArray[$sort][$k1]['totalDepositTax']; - if (!isset($this->calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$row['category']])) { - $this->calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$row['category']] = 0; + if (!isset($calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$row['category']])) { + $calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$row['category']] = 0; } - $this->calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$row['category']] += $itemArray[$sort][$k1]['totalTax']; + $calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$row['category']] += $itemArray[$sort][$k1]['totalTax']; - $this->calculatedArray['price2Tax']['goodstotal']['ALL'] += $price2Tax * $count; + $calculatedArray['price2Tax']['goodstotal']['ALL'] += $price2Tax * $count; $value = $row['handling'] ?? 0; - $this->calculatedArray['handling']['0']['priceTax'] += + $calculatedArray['handling']['0']['priceTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -515,7 +517,7 @@ public function calculate( true ); $value = $row['shipping'] ?? 0; - $this->calculatedArray['shipping']['priceTax'] += + $calculatedArray['shipping']['priceTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -529,7 +531,7 @@ public function calculate( $value = $row['shipping2'] ?? 0; if ($count > 1) { - $this->calculatedArray['shipping']['priceTax'] += + $calculatedArray['shipping']['priceTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -544,7 +546,7 @@ public function calculate( } $value = $row['handling'] ?? 0; - $this->calculatedArray['handling']['0']['priceNoTax'] += + $calculatedArray['handling']['0']['priceNoTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -557,7 +559,7 @@ public function calculate( ); $value = $row['shipping'] ?? 0; - $this->calculatedArray['shipping']['priceNoTax'] += + $calculatedArray['shipping']['priceNoTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -571,7 +573,7 @@ public function calculate( $value = $row['shipping2'] ?? 0; if ($count > 1) { - $this->calculatedArray['shipping']['priceNoTax'] += + $calculatedArray['shipping']['priceNoTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -587,24 +589,24 @@ public function calculate( } // foreach ($itemArray PaymentShippingHandling::getScriptPrices( - $this->calculatedArray, + $calculatedArray, $itemArray, $basketExtra, 'payment' ); PaymentShippingHandling::getScriptPrices( - $this->calculatedArray, + $calculatedArray, $itemArray, $basketExtra, 'shipping' ); PaymentShippingHandling::getScriptPrices( - $this->calculatedArray, + $calculatedArray, $itemArray, $basketExtra, 'handling' ); - $this->calculatedArray['maxtax']['goodstotal']['ALL'] = $maxTax; + $calculatedArray['maxtax']['goodstotal']['ALL'] = $maxTax; $taxRow = []; foreach ($itemArray as $sort => $actItemArray) { @@ -614,7 +616,7 @@ public function calculate( $value = floatval($this->conf['bulkilyAddition']) * $basketExt[$row['uid']][$viewTableObj->getVariant()->getVariantFromRow($row)]; $tax = ($bulkilyFeeTax != 0 ? $bulkilyFeeTax : $shippingTax); $taxRow['tax'] = floatval($tax); - $this->calculatedArray['shipping']['priceTax'] += + $calculatedArray['shipping']['priceTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -625,7 +627,7 @@ public function calculate( $conf['TAXincluded'], false ); - $this->calculatedArray['shipping']['priceNoTax'] += + $calculatedArray['shipping']['priceNoTax'] += $priceObj->getModePrice( $basketExtra, $basketRecs, @@ -651,7 +653,7 @@ public function calculate( $taxRow = []; foreach ($controlCalcArray as $keyTax => $keyNoTax) { - foreach ($this->calculatedArray[$keyNoTax]['goodssametaxtotal'] as $countryIndex => $taxArray) { + foreach ($calculatedArray[$keyNoTax]['goodssametaxtotal'] as $countryIndex => $taxArray) { $priceTax = 0; foreach ($taxArray as $tax => $value) { @@ -668,12 +670,12 @@ public function calculate( ); $priceTax += $newPriceTax; - $this->calculatedArray[$keyNoTax]['sametaxtotal'][$countryIndex][$tax] = $value; - $this->calculatedArray[$keyTax]['sametaxtotal'][$countryIndex][$tax] = $newPriceTax; - $this->calculatedArray[$keyTax]['goodssametaxtotal'][$countryIndex][$tax] = $newPriceTax; + $calculatedArray[$keyNoTax]['sametaxtotal'][$countryIndex][$tax] = $value; + $calculatedArray[$keyTax]['sametaxtotal'][$countryIndex][$tax] = $newPriceTax; + $calculatedArray[$keyTax]['goodssametaxtotal'][$countryIndex][$tax] = $newPriceTax; } - $this->calculatedArray[$keyTax]['goodstotal'][$countryIndex] = $priceTax; + $calculatedArray[$keyTax]['goodstotal'][$countryIndex] = $priceTax; } } @@ -681,7 +683,7 @@ public function calculate( foreach ($controlCatCalcCatArray as $keyTax => $keyNoTax) { $priceTaxArray = []; $priceTax = 0; - foreach ($this->calculatedArray[$keyNoTax]['goodssametaxtotal']['ALL'] as $tax => $catArray) { + foreach ($calculatedArray[$keyNoTax]['goodssametaxtotal']['ALL'] as $tax => $catArray) { $taxRow['tax'] = floatval($tax); if (is_array($catArray)) { foreach ($catArray as $cat => $value) { @@ -697,30 +699,30 @@ public function calculate( true ); $priceTax += $newPriceTax; - $this->calculatedArray[$keyNoTax]['sametaxtotal']['ALL'][$cat][$tax] = $value; - $this->calculatedArray[$keyTax]['sametaxtotal']['ALL'][$cat][$tax] = $newPriceTax; + $calculatedArray[$keyNoTax]['sametaxtotal']['ALL'][$cat][$tax] = $value; + $calculatedArray[$keyTax]['sametaxtotal']['ALL'][$cat][$tax] = $newPriceTax; } } } - $this->calculatedArray[$keyTax]['goodstotal']['ALL'] = $priceTaxArray; + $calculatedArray[$keyTax]['goodstotal']['ALL'] = $priceTaxArray; } - $this->calculatedArray['handling']['0']['priceTax'] = + $calculatedArray['handling']['0']['priceTax'] = $priceObj->getModePrice( $basketExtra, $basketRecs, $conf['TAXmode'], - $this->calculatedArray['handling']['0']['priceNoTax'], + $calculatedArray['handling']['0']['priceNoTax'], $shippingRow, true, false, true ); - $this->calculatedArray['shipping']['priceTax'] = + $calculatedArray['shipping']['priceTax'] = $priceObj->getModePrice( $basketExtra, $basketRecs, $conf['TAXmode'], - $this->calculatedArray['shipping']['priceNoTax'], + $calculatedArray['shipping']['priceNoTax'], $shippingRow, true, false, @@ -742,13 +744,12 @@ public function calculate( $conf, $iso3Seller, $iso3Buyer, - $this->calculatedArray['count'] ?? 0, - $this->calculatedArray['priceTax']['goodstotal']['ALL'], - $this->calculatedArray, + $calculatedArray['count'] ?? 0, + $calculatedArray['priceTax']['goodstotal']['ALL'], + $calculatedArray, $itemArray ); - // payment must be dealt with at the latest because the payment gateway must know about all other costs // Shipping must be at the end in order to use the calculated values from before PaymentShippingHandling::getPaymentShippingData( @@ -757,35 +758,36 @@ public function calculate( $conf, $iso3Seller, $iso3Buyer, - $this->calculatedArray['count'] ?? 0, - $this->calculatedArray['priceTax']['goodstotal']['ALL'], + $calculatedArray['count'] ?? 0, + $calculatedArray['priceTax']['goodstotal']['ALL'], $shippingRow, $paymentRow, $itemArray, - $this->calculatedArray, - $this->calculatedArray['shipping']['priceTax'], - $this->calculatedArray['shipping']['priceNoTax'], - $this->calculatedArray['payment']['priceTax'], - $this->calculatedArray['payment']['priceNoTax'] + $calculatedArray, + $calculatedArray['shipping']['priceTax'], + $calculatedArray['shipping']['priceNoTax'], + $calculatedArray['payment']['priceTax'], + $calculatedArray['payment']['priceNoTax'] ); if ($shippingTax) { - if (!isset($this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($shippingTax, 2))])) { - $this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($shippingTax, 2))] = 0; + if (!isset($calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($shippingTax, 2))])) { + $calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($shippingTax, 2))] = 0; } - $this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($shippingTax, 2))] += $this->calculatedArray['shipping']['priceNoTax']; + $calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($shippingTax, 2))] += $calculatedArray['shipping']['priceNoTax']; } if ($paymentTax) { - if (!isset($this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($paymentTax, 2))])) { - $this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($paymentTax, 2))] = 0; + if (!isset($calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($paymentTax, 2))])) { + $calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($paymentTax, 2))] = 0; } - $this->calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($paymentTax, 2))] += $this->calculatedArray['payment']['priceNoTax']; + $calculatedArray['priceNoTax']['sametaxtotal']['ALL'][strval(number_format($paymentTax, 2))] += $calculatedArray['payment']['priceNoTax']; } } // calculate // This calculates the total for everything in the basket public function calculateSums( + &$calculatedArray, $roundFormat, $pricefactor, $creditpoints, @@ -794,7 +796,6 @@ public function calculateSums( $creditpointsObj = GeneralUtility::makeInstance('tx_ttproducts_field_creditpoints'); // Todo: consider the $roundFormat parameter .XXXXXXXXXX - $calculatedArray = $this->getCalculatedArray(); $baseCountryArray = [ 'ALL', diff --git a/model/class.tx_ttproducts_info.php b/model/class.tx_ttproducts_info.php index 47c1f9c3e..e721c4ba9 100644 --- a/model/class.tx_ttproducts_info.php +++ b/model/class.tx_ttproducts_info.php @@ -3,30 +3,30 @@ declare(strict_types=1); /*************************************************************** -* Copyright notice -* -* (c) 2020 Franz Holzinger (franz@ttproducts.de) -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* A copy is found in the textfile GPL.txt and important notices to the license -* from the author is found in LICENSE.txt distributed with these scripts. -* -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ + * Copyright notice + * + * (c) 2020 Franz Holzinger (franz@ttproducts.de) + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * A copy is found in the textfile GPL.txt and important notices to the license + * from the author is found in LICENSE.txt distributed with these scripts. + * + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ /** * Part of the tt_products (Shop System) extension. * @@ -59,6 +59,7 @@ class tx_ttproducts_info implements SingletonInterface public function init(array $infoArray, $pdfInfoFields = ''): bool { $this->setInfoArray($infoArray); + $this->setPdfInfoFields($pdfInfoFields); return true; } @@ -98,7 +99,6 @@ public function checkRequired( ) { $result = ''; $infoArray = $this->getInfoArray(); - if ( $type == 'billing' || tx_ttproducts_control_basket::needsDeliveryAddresss($basketExtra) @@ -170,8 +170,8 @@ public function checkAllowed($basketExtra) if (is_object($countryObj)) { $type = ( !tx_ttproducts_control_basket::needsDeliveryAddresss($basketExtra) ? - 'billing' : - 'delivery' + 'billing' : + 'delivery' ); $row = $countryObj->isoGet($infoArray[$type]['country_code'] ?? '', $where); if (!$row) { @@ -275,7 +275,7 @@ public function mapPersonIntoDelivery( ( empty($infoArray['delivery']['address']) && empty($infoArray['delivery']['email']) - || + || $overwrite ) && $needsDeliveryAddress @@ -295,7 +295,7 @@ public function mapPersonIntoDelivery( $infoArray['delivery'][$fName] == '0' && !$hasAddress ) || in_array($fName, ['country', 'country_code', 'zone']) - ) + ) // FHO neu: jetzt auch country_code ) { $infoArray['delivery'][$fName] = $infoArray['billing'][$fName]; } @@ -311,7 +311,7 @@ public function mapPersonIntoDelivery( unset($infoArray['delivery']['salutation']); if ( count($infoArray['delivery']) < 3 && - !isset($infoArray['delivery']['email']) + !isset($infoArray['delivery']['email']) // KORR Neu FHO ) { unset($infoArray['delivery']); } @@ -345,14 +345,14 @@ public function getCustomerEmail() $conf['orderEmail_toDelivery'] && $infoArray['delivery']['email'] || !$infoArray['billing']['email'] ) ? - $infoArray['delivery']['email'] : - $infoArray['billing']['email'] + $infoArray['delivery']['email'] : + $infoArray['billing']['email'] ); // former: deliveryInfo return $result; } - public function getFromArray($customerEmail, $useLoginEmail) + public function getFromArray($customerEmail, $useLoginEmail, $feUserRecord) { $infoArray = $this->getInfoArray(); $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); @@ -380,26 +380,25 @@ public function getFromArray($customerEmail, $useLoginEmail) ]; } + if ( $useLoginEmail != '' && $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && - isset($GLOBALS['TSFE']->fe_user) && - isset($GLOBALS['TSFE']->fe_user->user) && - !empty($GLOBALS['TSFE']->fe_user->user['username']) + !empty($feUserRecord['username']) ) { - $name = $GLOBALS['TSFE']->fe_user->user['name']; + $name = $feUserRecord['name']; if ( - isset($GLOBALS['TSFE']->fe_user->user['first_name']) && - isset($GLOBALS['TSFE']->fe_user->user['last_name']) + isset($feUserRecord['first_name']) && + isset($feUserRecord['last_name']) ) { - $name = $GLOBALS['TSFE']->fe_user->user['first_name'] . ' '; - if (!empty($GLOBALS['TSFE']->fe_user->user['middle_name'])) { - $name .= $GLOBALS['TSFE']->fe_user->user['middle_name'] . ' '; + $name = $feUserRecord['first_name'] . ' '; + if (!empty($feUserRecord['middle_name'])) { + $name .= $feUserRecord['middle_name'] . ' '; } - $name .= $GLOBALS['TSFE']->fe_user->user['last_name']; + $name .= $feUserRecord['last_name']; } $resultArray['login'] = [ - 'email' => $GLOBALS['TSFE']->fe_user->user['email'], + 'email' => $feUserRecord['email'], 'name' => $name, ]; } @@ -432,11 +431,10 @@ public function isNewUser($type) // billing or delivery break; } elseif ( $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && - isset($GLOBALS['TSFE']->fe_user) && - isset($GLOBALS['TSFE']->fe_user->user) && - is_array($GLOBALS['TSFE']->fe_user->user) && - $GLOBALS['TSFE']->fe_user->user['username'] != '' && - $infoArray[$type][$fName] != $GLOBALS['TSFE']->fe_user->user[$fName] + isset($feUserRecord) && + is_array($feUserRecord) && + $feUserRecord['username'] != '' && + $infoArray[$type][$fName] != $feUserRecord[$fName] ) { break; } diff --git a/model/class.tx_ttproducts_model_control.php b/model/class.tx_ttproducts_model_control.php deleted file mode 100644 index 128b75095..000000000 --- a/model/class.tx_ttproducts_model_control.php +++ /dev/null @@ -1,659 +0,0 @@ - - * - * @maintainer Franz Holzinger - * - * @package TYPO3 - * @subpackage tt_products - */ -use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -class tx_ttproducts_model_control -{ - public static $controlVar = 'ctrl'; - - public static $paramsTableArray = [ - 'a' => 'address', - 'article' => 'tt_products_articles', - 'cat' => 'tt_products_cat', - 'content' => 'tt_content', - 'dam' => 'tx_dam', - 'damcat' => 'tx_dam_cat', - 'dl' => 'tt_products_downloads', - 'fal' => 'sys_file_reference', - 'fg' => 'fegroup', - 'o' => 'sys_products_orders', - 'oa' => 'orderaddress', - 'pid' => 'pages', - 'product' => 'tt_products', - ]; - - public static $pointerParamsCodeArray = [ - 'pointer' => 'CATLIST', - 'pp' => 'LIST', - ]; - - public static $basketVar = 'ttp_basket'; - public static $searchboxVar = 'searchbox'; - private static string $basketParamVar = 'basket'; - private static string $orderViewVar = 'orderview'; - private static $prefixId = 'tt_products'; - private static $piVars = []; - private static array $piVarsDefault = []; - private static array $andVars = []; - private static string $basketIntoIdPrefix = 'basket-into-id'; - private static string $basketInputErrorIdPrefix = 'basket-input-error-id'; - - public static function determineRegExpDelimiter($delimiter) - { - $regexpDelimiter = $delimiter; - if ($delimiter == ';') { - // $regexpDelimiter = '[.semicolon.]'; - // Leads to MYSQL ERROR: - // Got error 'POSIX collating elements are not supported at offset 46' from regexp - - $regexpDelimiter = ';'; - } - switch ($delimiter) { - case ';': - // $regexpDelimiter = '[.semicolon.]'; - // Leads to MYSQL ERROR: - // Got error 'POSIX collating elements are not supported at offset 46' from regexp - break; - case '\n': - $regexpDelimiter = '[\n]'; - break; - } - - return $regexpDelimiter; - } - - public static function getBasketIntoIdPrefix() - { - return self::$basketIntoIdPrefix; - } - - public static function getBasketInputErrorIdPrefix() - { - return self::$basketInputErrorIdPrefix; - } - - /** - * If internal TypoScript property "_DEFAULT_PI_VARS." is set then it will merge the current $this->piVars array onto these default values. - * Store the internal TypoScript property "_DEFAULT_PI_VARS." if set. - */ - public static function setPiVarDefaults($piVarsDefault): void - { - if ( - isset($piVarsDefault) && - is_array($piVarsDefault) - ) { - self::$piVarsDefault = $piVarsDefault; - } - } - - public static function getPiVarDefaults() - { - return self::$piVarsDefault; - } - - public static function setPrefixId($prefixId): void - { - self::$prefixId = $prefixId; - } - - public static function getPrefixId() - { - return self::$prefixId; - } - - public static function setPiVars($value): void - { - self::$piVars = $value; - } - - // if a default value is set then it will merge the current self::$piVars array onto these default values. - public static function getPiVars() - { - $result = self::$piVars; - - return $result; - } - - public static function getPiVar($funcTablename) - { - $paramsTableArray = self::getParamsTableArray(); - $result = array_search($funcTablename, $paramsTableArray); - - return $result; - } - - public static function setAndVar($k, $v): void - { - if (isset(self::$andVars[$k])) { - self::$andVars[$k] .= ',' . $v; - } else { - self::$andVars[$k] = $v; - } - } - - public static function getAndVar($k) - { - $result = false; - - if (isset(self::$andVars[$k])) { - $result = self::$andVars[$k]; - } - - return $result; - } - - public static function getPiVarValue($funcTablename) - { - $piVars = self::getPiVars(); - $piVar = self::getPiVar($funcTablename); - $result = false; - - if ( - isset($piVars) && - is_array($piVars) && - isset($piVars[$piVar]) - ) { - $result = $piVars[$piVar]; - } - - return $result; - } - - public static function getParamsTableArray() - { - return self::$paramsTableArray; - } - - public static function getParamsTable($piVar) - { - $result = false; - - if (isset(self::$paramsTableArray[$piVar])) { - $result = self::$paramsTableArray[$piVar]; - } - - return $result; - } - - public static function getPointerPiVar($theCode) - { - $pointerParamsTableArray = self::getPointerParamsCodeArray(); - $rc = array_search($theCode, $pointerParamsTableArray); - - return $rc; - } - - public static function getPointerParamsCodeArray() - { - return self::$pointerParamsCodeArray; - } - - public static function getBasketVar() - { - return self::$basketVar; - } - - public static function getBasketParamVar() - { - return self::$basketParamVar; - } - - public static function getSearchboxVar() - { - return self::$searchboxVar; - } - - public static function getControlVar() - { - return self::$controlVar; - } - - public static function getOrderViewVar() - { - return self::$orderViewVar; - } - - public static function getControlArray() - { - $piVars = self::getPiVars(); - - $allValueArray = []; - $resultArray = []; - $controlVar = self::getControlVar(); - - if (isset($piVars[$controlVar]) && is_array($piVars[$controlVar])) { - $resultArray = $piVars[$controlVar]; - } - - return $resultArray; - } - - public static function getTableConfArrays( - $cObj, - array $functableArray, - $theCode, - array &$tableConfArray, - array &$viewConfArray - ): void { - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - - foreach ($functableArray as $ft) { - if ($ft != '') { - $tableObj = $tablesObj->get($ft, 0); - if (is_object($tableObj)) { - $tableConfArray[$ft] = $tableObj->getTableConf($theCode); - if (isset($tableConfArray[$ft]['view.'])) { - $viewConfArray[$ft] = $tableConfArray[$ft]['view.']; - } - } - } - } - - if (isset($viewConfArray) && is_array($viewConfArray)) { - $controlArray = self::getControlArray(); - $typeArray = ['sortSelect', 'filterSelect', 'filterInput']; - $typeSelectArray = ['sortSelect', 'filterSelect']; - - foreach ($viewConfArray as $ftname => $funcViewConfArray) { - foreach ($typeArray as $type) { - if (isset($controlArray[$type]) && is_array($controlArray[$type])) { - if (in_array($type, $typeSelectArray)) { - $fitArray = []; - foreach ($controlArray[$type] as $k => $v) { - if ($v != '') { - $valueArray = $funcViewConfArray[$type . '.'][$k . '.']['valueArray.']; - $bFitValueArray = []; - foreach ($valueArray as $valueConf) { - if ( - isset($valueConf['field']) && - $valueConf['value'] == $v && - !$bFitValueArray[$v] - ) { - $fitArray[] = [ - 'delimiter' => $valueConf['delimiter'], - 'field' => $valueConf['field'], - 'key' => $valueConf['key'], - 'key.' => $valueConf['key.'], - ]; - $bFitValueArray[$v] = true; - } - } - } - } - - switch ($type) { - case 'sortSelect': - if (is_array($fitArray) && count($fitArray)) { - $fieldArray = []; - foreach ($fitArray as $fitRow) { - $fieldArray[] = $fitRow['field']; - } - $tableConfArray[$ftname]['orderBy'] = implode(',', $fieldArray); - } - break; - case 'filterSelect': - foreach ($fitArray as $fitRow) { - $field = $fitRow['field']; - if ($field != '' && isset($fitRow['key'])) { - if (isset($tableConfArray[$ftname]['filter.']['where.']['field.'][$field])) { - $preFilter = '(' . $tableConfArray[$ftname]['filter.']['where.']['field.'][$field] . ') AND ('; - } else { - $preFilter = ''; - } - - if (isset($fitRow['key.'])) { - $key = $cObj->stdWrap($fitRow['key'], $fitRow['key.']); - } else { - $key = $fitRow['key']; - } - - $tableConfArray[$ftname]['filter.']['where.']['field.'][$field] = $preFilter . $key . ($preFilter != '' ? ')' : ''); - - if (!empty($fitRow['delimiter'])) { - $tableConfArray[$ftname]['filter.']['delimiter.']['field.'][$field] = $fitRow['delimiter']; - } - } - } - break; - } - } elseif ($type == 'filterInput') { - foreach ($controlArray[$type] as $k => $v) { - if ($v != '') { - $fitRow = $funcViewConfArray[$type . '.'][$k . '.']; - $field = $fitRow['field']; - $tableConfArray[$ftname]['filter.']['where.']['field.'][$field] = $v; - if (!empty($fitRow['delimiter'])) { - $tableConfArray[$ftname]['filter.']['delimiter.']['field.'][$field] = $fitRow['delimiter']; - } - } - } - } - } - } - } - } - } - - public static function getTableVars( - $searchFunctablename, - &$searchTablename, - &$searchAlias, - &$tableAliasArray, - &$bUseSearchboxArray, - &$enableFieldArray - ): void { - if ($searchFunctablename != '') { - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - - $tableObj = $tablesObj->get($searchFunctablename, false); - $searchTablename = $tableObj->getTablename(); - $searchAlias = $tableObj->getAlias(); - - if ($searchTablename != '' && $searchAlias != '') { - $tableAliasArray[$searchTablename] = $searchAlias; - $bUseSearchboxArray[$searchFunctablename] = true; - } - $enableFieldArray = $tableObj->getTableObj()->getEnableFieldArray(); - } - } - - public static function getWhereByFields( - $tablename, - $alias, - $aliasPostfix, - $fields, - $sword, - $delimiter - ) { - $rc = false; - $fieldArray = GeneralUtility::trimExplode(',', $fields); - if (isset($fieldArray) && is_array($fieldArray)) { - $rcArray = []; - $regexpDelimiter = self::determineRegExpDelimiter($delimiter); - - foreach ($fieldArray as $field) { - $rcArray[] = - $alias . $aliasPostfix . '.' . $field . ' REGEXP ' . - $GLOBALS['TYPO3_DB']->fullQuoteStr( - '^([[:print:]]*[' . $regexpDelimiter . '])*(' . $sword . ')([[:print:]]*[[:blank:]]*)*([' . $regexpDelimiter . '][[:print:]]*)*$', - $tablename - ); - } - $rc = implode(' OR ', $rcArray); - } - - return $rc; - } - - public static function getSearchInfo( - $cObj, - array $searchVars, - $funcTablename, - $tablename, - &$searchboxWhere, - &$bUseSearchboxArray, - &$sqlTableArray, - &$sqlTableIndex, - &$latest - ): void { - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); - - $paramsTableArray = self::getParamsTableArray(); - $searchParamArray = []; - $searchFieldArray = []; - $tableAliasArray = []; - $enableFieldArray = []; - if (isset($searchVars['latest'])) { - $latest = $searchVars['latest']; - } - - $aliasPostfix = ''; - if ($sqlTableIndex) { - $aliasPostfix = ($sqlTableIndex + 1); - } - - if (isset($searchVars['uid'])) { - $contentObj = $tablesObj->get('tt_content', false); - $contentRow = $contentObj->get($searchVars['uid']); - - if ( - isset($contentRow['pi_flexform']) && - $contentRow['pi_flexform'] != '' - ) { - $contentRow['pi_flexform'] = GeneralUtility::xml2array($contentRow['pi_flexform']); - $searchObj = GeneralUtility::makeInstance('tx_ttproducts_control_search'); // fetch and store it as persistent object - $controlConfig = $searchObj->getControlConfig($cObj, $cnf->conf, $contentRow); - - self::getTableVars( - $controlConfig['local_table'], - $searchTablename, - $searchAlias, - $tableAliasArray, - $bUseSearchboxArray, - $enableFieldArray - ); - - $delimiter = ''; - $searchboxWhere = - self::getWhereByFields( - $searchTablename, - $searchAlias, - $aliasPostfix, - $controlConfig['fields'], - $searchVars['sword'], - $delimiter - ); - } - } - - $tmpArray = []; - $tmpArray[0] = ( - is_array($searchVars['local']) ? - key($searchVars['local']) : - $searchVars['local'] - ); - if (is_array($searchVars['local'])) { - $tmpArray[0] = key($searchVars['local']); - $localParam = current($searchVars['local']); - if (is_array($localParam)) { - $tmpArray[1] = key($localParam); - } else { - $tmpArray[1] = $localParam; - } - } else { - $tmpArray[0] = $searchVars['local']; - } - $searchParamArray['local'] = $tmpArray[0]; - $searchParamArray['foreign'] = $searchVars['foreign']; - $searchFieldArray['local'] = $tmpArray[1]; - $searchFieldArray['foreign'] = ''; - - if (self::getPiVar($funcTablename) == $searchParamArray['local']) { - $sqlTableArray['from'] = []; - $sqlTableArray['join'] = []; - $sqlTableArray['local'] = []; - $sqlTableArray['where'] = []; - - $loopArray = ['local', 'foreign']; - $bUseSearchboxCat = false; - $theTable = $cnf->getTableName($paramsTableArray[$searchParamArray['local']]); - - foreach ($loopArray as $position) { - $positionSearchVars = []; - $foundKey = 0; - - if ($position == 'local' && isset($keyFieldArray[$searchFieldArray['local']]) && ExtensionManagementUtility::isLoaded('searchbox')) { // Todo - require_once PATH_BE_searchbox . 'model/class.tx_searchbox_model.php'; - $modelObj = GeneralUtility::makeInstance('tx_searchbox_model'); - - $fullKeyFieldArray = $modelObj->getKeyFieldArray($tablename, '', '-', $searchFieldArray['local'], '1', $tmpCount); - } elseif (isset($fullKeyFieldArray)) { - unset($fullKeyFieldArray); - } - - foreach ($searchVars as $k => $v) { - $searchKey = $k; - $searchValue = $v; - if (is_array($v)) { - $tmpK = key($v); - $tmpArray = current($v); - $searchKey .= '|' . $tmpK; - if (is_array($tmpArray)) { - $tmpK = key($tmpArray); - $tmpArray = current($tmpArray); - $searchKey .= '|' . $tmpK; - } - $searchValue = $tmpArray; - } - - if ($searchKey == $positionSearchVars[$position] || (is_array($searchParamArray[$position]) && key($searchParamArray[$position]) == $k || !is_array($searchParamArray[$position]) && $searchParamArray[$position] == $k)) { - if (substr($searchValue, 0, 1) == '\'' && substr($searchValue, -1) == '\'') { - $searchValue = substr($searchValue, 1, strlen($searchValue) - 2); - } - if (isset($fullKeyFieldArray) && is_array($fullKeyFieldArray)) { - $tmpArray = GeneralUtility::trimExplode('|', $searchKey); - - if ($tmpArray[1] == $searchFieldArray[$position] && isset($fullKeyFieldArray[$searchValue])) { - $searchValue = $fullKeyFieldArray[$searchValue]; - } - } - $positionSearchVars[$searchKey] = $searchValue; - if (!$foundKey) { - $foundKey = $k; - } - } - } - - if (isset($searchVars[$position]) && isset($positionSearchVars) && is_array($positionSearchVars) && count($positionSearchVars) && $searchVars[$foundKey] != 'all') { - $positionSearchKey = key($positionSearchVars); - $positionSearchValue = current($positionSearchVars); - $partArray = GeneralUtility::trimExplode('|', $positionSearchKey); - $delimiter = ($partArray[2] ?: ''); - $searchTablename = ''; - $searchParam = $partArray[0]; - $searchField = $partArray[1]; - self::getTableVars( - $paramsTableArray[$searchParam], - $searchTablename, - $searchAlias, - $tableAliasArray, - $bUseSearchboxArray, - $enableFieldArray - ); - - if ($searchTablename != '') { - $field = ($searchField != '' && isset($GLOBALS['TCA'][$searchTablename]['columns'][$searchField]) ? $searchField : 'title'); - $configArray = $GLOBALS['TCA'][$searchTablename]['columns'][$field]['config']; - - if (isset($configArray) && is_array($configArray) || in_array($field, $enableFieldArray)) { - if ($configArray['eval'] == 'date') { - $searchboxWhere = 'YEAR(' . $searchAlias . $aliasPostfix . '.' . $field . ')=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($positionSearchValue, $searchTablename); - } else { - if ($delimiter != '') { - if ($searchVars['query'] == 'IN') { - $valueArray = []; - $tmpParamArray = GeneralUtility::trimExplode(',', $positionSearchValue); - foreach ($tmpParamArray as $param => $v) { - if ($v != '') { - $valueArray[] = $GLOBALS['TYPO3_DB']->fullQuoteStr($v, $searchTablename); - } - } - $searchboxWhereArray = []; - foreach ($valueArray as $v) { - $searchboxWhereArray[] = $searchAlias . $aliasPostfix . '.' . $field . ' REGEXP ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('.*[' . $delimiter . ']*' . $positionSearchValue . '[' . $delimiter . ']*.*', $searchTablename); - } - $searchboxWhere = implode(' OR ', $searchboxWhereArray); - // TODO - } else { - $searchboxWhere = - self::getWhereByFields( - $searchTablename, - $searchAlias, - $aliasPostfix, - $field, - $positionSearchValue, - $delimiter - ); - } - } else { - if ($searchVars['query'] == 'IN') { - $valueArray = []; - $tmpParamArray = GeneralUtility::trimExplode(',', $positionSearchValue); - foreach ($tmpParamArray as $param => $v) { - if ($v != '') { - $valueArray[] = $v; - } - } - $searchboxWhereArray = []; - foreach ($valueArray as $v) { - $searchboxWhereArray[] = $searchAlias . $aliasPostfix . '.' . $field . ' LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($v . '%', $searchTablename); - } - $searchboxWhere = '(' . implode(' OR ', $searchboxWhereArray) . ')'; - } else { - $searchboxWhere = $searchAlias . $aliasPostfix . '.' . $field . ' LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($positionSearchValue . '%', $searchTablename); - } - } - } - $newSqlTableArray = []; - if ($position == 'foreign') { - $foreignTableInfo = $tablesObj->getForeignTableInfo($theTable, $searchFieldArray['local']); - $foreignTableInfo['table_field'] = $searchFieldArray['local']; - $tablesObj->prepareSQL($foreignTableInfo, $tableAliasArray, $aliasPostfix, $newSqlTableArray); - } - $sqlTableArray[$position][$sqlTableIndex] = $cnf->getTableName($paramsTableArray[$searchParam]); - if (!empty($foreignTableInfo['where'])) { - $sqlTableArray['where'][$sqlTableIndex] = $foreignTableInfo['where']; - } - if (isset($newSqlTableArray) && is_array($newSqlTableArray)) { - foreach ($sqlTableArray as $k => $tmpArray) { - if (isset($newSqlTableArray[$k])) { - $sqlTableArray[$k][$sqlTableIndex] = $newSqlTableArray[$k]; - } - } - } - $sqlTableIndex++; - } - } - } - } - } - } -} diff --git a/model/class.tx_ttproducts_order.php b/model/class.tx_ttproducts_order.php index b4301d832..e3f03d488 100644 --- a/model/class.tx_ttproducts_order.php +++ b/model/class.tx_ttproducts_order.php @@ -36,7 +36,7 @@ * @package TYPO3 * @subpackage tt_products */ - +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Crypto\Random; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; @@ -300,6 +300,7 @@ public function putRecord( $orderArray, $itemArray, $calculatedArray, + $feUserRecord, $cardUid, $accountUid, $email_notify, @@ -322,6 +323,7 @@ public function putRecord( $billingInfo = $infoArray['billing']; $deliveryInfo = $infoArray['delivery']; $feusers_uid = 0; + $context = GeneralUtility::makeInstance(Context::class); if (is_array($billingInfo) && isset($billingInfo['feusers_uid'])) { $feusers_uid = $billingInfo['feusers_uid']; } @@ -465,13 +467,11 @@ public function putRecord( } if ($status == 1 && !empty($this->conf['creditpoints.']) && $usedCreditpoints) { - // Added Els: update fe_user with amount of creditpoints (= exisitng amount - used_creditpoints - spended_creditpoints + saved_creditpoints $fieldsArrayFeUsers['tt_products_creditpoints'] = - floatval( - $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] - - $usedCreditpoints - // + GeneralUtility::_GP('creditpoints_saved') - ); + floatval( + tx_ttproducts_creditpoints_div::getCreditPointsFeuser($feUserRecord) - + $usedCreditpoints + ); if ($fieldsArrayFeUsers['tt_products_creditpoints'] < 0) { $fieldsArrayFeUsers['tt_products_creditpoints'] = 0; } @@ -516,13 +516,13 @@ public function putRecord( } if ( - CompatibilityUtility::isLoggedIn() && - $GLOBALS['TSFE']->fe_user->user['uid'] && + $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && + $feUserRecord['uid'] && count($fieldsArrayFeUsers) ) { $GLOBALS['TYPO3_DB']->exec_UPDATEquery( 'fe_users', - 'uid=' . intval($GLOBALS['TSFE']->fe_user->user['uid']), + 'uid=' . intval($feUserRecord['uid']), $fieldsArrayFeUsers ); } @@ -633,6 +633,7 @@ public function createMM( $orderTablename = 'sys_products_orders'; $falFieldname = 'fal_uid'; $variantSeparator = '---'; + $basketApi = GeneralUtility::makeInstance(BasketApi::class); if ($this->conf['useArticles'] != 2) { $productTable = $tablesObj->get('tt_products', false); @@ -707,7 +708,7 @@ public function createMM( ) { $newTitleArray = []; $externalRowArray = $extArray['records']; - BasketApi::getRecordvariantAndPriceFromRows( + $basketApi->getRecordvariantAndPriceFromRows( $falVariants, $dummyPrice, $externalUidArray, @@ -841,6 +842,7 @@ public function putData( $orderHTML, $status, $basketExtra, + $feUserRecord, $calculatedArray, tx_ttproducts_info $infoObj, $giftcode, @@ -858,7 +860,7 @@ public function putData( $status == 1 && $voucherObj->isEnabled() ) { - $voucherObj->delete(); + $voucherObj->delete($feUserRecord); } // get credit card info @@ -897,6 +899,7 @@ public function putData( $orderArray, $itemArray, $calculatedArray, + $feUserRecord, $cardUid, $accountUid, $this->conf['email_notify_default'] ?? '', // Email notification is set here. Default email address is delivery email contact diff --git a/model/class.tx_ttproducts_orderaddress.php b/model/class.tx_ttproducts_orderaddress.php index 8727ef294..e4dd99c54 100644 --- a/model/class.tx_ttproducts_orderaddress.php +++ b/model/class.tx_ttproducts_orderaddress.php @@ -1,29 +1,32 @@ bConditionRecord = false; + $this->bConditionRecord = false; // neu + $context = GeneralUtility::makeInstance(Context::class); if (isset($this->conf['conf.'][$funcTablename . '.']['ALL.']['fe_users.']['date_of_birth.']['period.']['y'])) { $year = $this->conf['conf.'][$funcTablename . '.']['ALL.']['fe_users.']['date_of_birth.']['period.']['y']; @@ -133,8 +137,10 @@ public function setCondition($row, $funcTablename): void if ($infoArray['billing']['date_of_birth']) { $timeTemp = $infoArray['billing']['date_of_birth']; $bAge = true; - } elseif (!empty($GLOBALS['TSFE']->fe_user->user['username'])) { - $timeTemp = date('d-m-Y', $GLOBALS['TSFE']->fe_user->user['date_of_birth']); + } elseif ( + !empty($feUserRecord['username']) + ) { + $timeTemp = date('d-m-Y', $feUserRecord['date_of_birth']); $bAge = true; } else { $bAge = false; @@ -156,7 +162,6 @@ public function setCondition($row, $funcTablename): void } $whereConf = $this->conf['conf.'][$funcTablename . '.']['ALL.']['fe_users.']['where'] ?? ''; - if (!empty($whereConf)) { $whereArray = GeneralUtility::trimExplode('IN', $whereConf); $pos1 = strpos($whereArray[1], '('); @@ -187,21 +192,6 @@ public function getConditionRecord(): bool return $this->bConditionRecord; } - public function getCreditpoints() - { - $rc = false; - if ( - CompatibilityUtility::isLoggedIn() && - isset($GLOBALS['TSFE']->fe_user->user) && - is_array( - $GLOBALS['TSFE']->fe_user->user - )) { - $rc = $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints']; - } - - return $rc; - } - public function getPid() { $result = $this->conf['PIDuserFolder']; diff --git a/model/class.tx_ttproducts_product.php b/model/class.tx_ttproducts_product.php index 5bd5a7b75..8a5d59415 100644 --- a/model/class.tx_ttproducts_product.php +++ b/model/class.tx_ttproducts_product.php @@ -36,14 +36,18 @@ * @package TYPO3 * @subpackage tt_products */ +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; + use JambageCom\Div2007\Utility\ExtensionUtility; use JambageCom\Div2007\Utility\FlexformUtility; use JambageCom\Div2007\Utility\SystemCategoryUtility; use JambageCom\Div2007\Utility\TableUtility; + +use JambageCom\TtProducts\Api\ParameterApi; use JambageCom\TtProducts\Model\Field\FieldInterface; -use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\MathUtility; + class tx_ttproducts_product extends tx_ttproducts_article_base { @@ -271,11 +275,12 @@ public function getArticleRow( $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $fieldArray = $this->variant->getSelectableFieldArray(); $useArticles = $cnfObj->getUseArticles(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $articleNo = false; $articleRow = []; $variantSeparator = $this->getVariant()->getSeparator(); - $regexpDelimiter = tx_ttproducts_model_control::determineRegExpDelimiter($variantSeparator); + $regexpDelimiter = $parameterApi->determineRegExpDelimiter($variantSeparator); if ($bUsePreset) { $presetVariantArray = diff --git a/model/class.tx_ttproducts_static_tax.php b/model/class.tx_ttproducts_static_tax.php index 877bd0926..615b90510 100644 --- a/model/class.tx_ttproducts_static_tax.php +++ b/model/class.tx_ttproducts_static_tax.php @@ -1,29 +1,32 @@ =')) { - $result = self::$isInstalled = true; + if (version_compare($sittVersion, '0.3.2', '>=')) { + $result = static::$isInstalled = true; } } } @@ -153,7 +162,7 @@ public static function isInstalled() public function isValid() { - $result = self::isInstalled() && !$this->needsInit() && $this->getUidStore(); + $result = static::isInstalled() && !$this->needsInit() && $this->getUidStore(); return $result; } @@ -180,7 +189,7 @@ public function setShopCountryCode($setShopCountryCode): void public function setStoreData($uidStore): void { - if (self::isInstalled() && $uidStore > 0) { + if (static::isInstalled() && $uidStore > 0) { $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $orderAdressObj = $tablesObj->get('address', false); $storeRow = $orderAdressObj->get($uidStore); @@ -188,6 +197,7 @@ public function setStoreData($uidStore): void if (!empty($storeRow)) { $staticInfoCountryField = $orderAdressObj->getField('static_info_country'); + if ( !isset($storeRow[$staticInfoCountryField]) && isset($storeRow['country']) @@ -214,11 +224,11 @@ public function setStoreData($uidStore): void $zoneField = $orderAdressObj->getField('zone'); if ($tableconf['zoneReference'] == 'uid') { $zoneArray = - $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - 'zn_code', - 'static_country_zones', - 'uid=' . intval($storeRow[$zoneField]) - ); + $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + 'zn_code', + 'static_country_zones', + 'uid=' . intval($storeRow[$zoneField]) + ); if (isset($zoneArray) && is_array($zoneArray) && isset($zoneArray[0])) { $theZoneCode = $zoneArray[0]['zn_code']; } @@ -239,13 +249,16 @@ public function setStoreData($uidStore): void } } /* $allTaxesArray = []; - $this->getStaticTax($row,$tax,$allTaxesArray); // call it to set the member variables*/ + * $this->getStaticTax($row,$tax,$allTaxesArray); // call it to set the member variables*/ } } protected function didValuesChange(array $countryArray) { - if ( + $result = false; + if (!is_array($countryArray['shipping'])) { + // nothing + } elseif ( is_array($this->countryArray['shipping']) && count($this->countryArray['shipping']) ) { @@ -255,7 +268,7 @@ protected function didValuesChange(array $countryArray) ) > 0 ); } else { - $result = (is_array($countryArray['shipping']) && (count($countryArray['shipping']) > 0)); + $result = (count($countryArray['shipping']) > 0); } return $result; @@ -312,7 +325,7 @@ public function storeValues($countryArray): void public function getCategoryArray($uidArray) { $result = []; - $pageRepository = CompatibilityUtility::getPageRepository(); + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); $isValid = true; foreach ($uidArray as $uid) { @@ -327,12 +340,11 @@ public function getCategoryArray($uidArray) $uids = implode(',', $uidArray); $where = 'uid_local IN (' . $uids . ')' . $pageRepository->enableFields('tt_products_products_mm_tax_categories'); $rowArray = - $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - 'tt_products_products_mm_tax_categories', - $where - ); - + $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + '*', + 'tt_products_products_mm_tax_categories', + $where + ); if ( is_array($rowArray) && !empty($rowArray) @@ -349,7 +361,7 @@ public function getCategoryArray($uidArray) public function getTaxInfo( &$taxInfoArray, &$shopCountryArray, - $tax, + &$tax, array $uidArray, array $basketRecs ): bool { @@ -360,6 +372,7 @@ public function getTaxInfo( } $countryArray = $this->countryArray; + if ( !isset($countryArray['shop']) || $countryArray['shop']['country_code'] == '' @@ -400,80 +413,82 @@ public function getTaxInfo( $zoneCode = ''; $taxInfoArray = - TaxApi::fetchCountryTaxes( - $countryCode, - $zoneCode, - $staticInfoApi, - $tax, - $categoryArray, - -1, - $countryArray['shop']['country_code'], - $countryArray['shop']['zone'], - $countryArray['shipping']['country_code'], - $countryArray['shipping']['zone'], - $countryArray['billing']['country_code'], - $countryArray['billing']['zone'], - 0, - true - ); + TaxApi::fetchCountryTaxes( + $countryCode, + $zoneCode, + $staticInfoApi, + $tax, // neu + $categoryArray, + -1, + $countryArray['shop']['country_code'], + $countryArray['shop']['zone'], + $countryArray['shipping']['country_code'], + $countryArray['shipping']['zone'], + $countryArray['billing']['country_code'], + $countryArray['billing']['zone'], + 0, + true + ); $shopCountryArray = $countryArray['shop']; + if ( + isset($taxInfoArray[$countryCode]) && + count($taxInfoArray[$countryCode]) == 1 + ) { + $tax = $taxInfoArray[$countryCode][0]['tx_rate']; + } + return true; } public static function setNeed4StaticTax($value): void { - self::$need4StaticTax = $value; + static::$need4StaticTax = $value; } public static function getNeed4StaticTax() { - return self::$need4StaticTax; + return static::$need4StaticTax; } public static function need4StaticTax( array $row ) { - if (self::getNeed4StaticTax()) { + if (static::getNeed4StaticTax()) { return true; } $result = false; - if ( - isset($row['ext']) && - is_array($row['ext']) - ) { - $extArray = $row['ext']; - } + $extArray = $row['ext'] ?? []; if ( - self::isInstalled() && + static::isInstalled() && isset($extArray['records']) && is_array($extArray['records']) && isset($extArray['records']['tt_products_downloads']) && isset($extArray['records']['sys_file_reference']) ) { $result = true; - self::setNeed4StaticTax(true); + static::setNeed4StaticTax(true); } return $result; } public function getStaticTax( - $basketRecs, - array $row, &$tax, - &$taxInfoArray + &$taxInfoArray, + $basketRecs, + array $row ): void { $extArray = []; $categoryArray = []; - + $feUserRecord = CustomerApi::getFeUserRecord(); if ( !empty($row) && $this->getUidStore() && - self::isInstalled() + static::isInstalled() ) { if ( isset($basketRecs) && @@ -483,6 +498,19 @@ public function getStaticTax( $deliveryInfo = $basketRecs['delivery']; $personInfo = $basketRecs['personinfo']; } + + if ( + ( + !isset($deliveryInfo) || + !isset($deliveryInfo['country_code']) + ) && + is_array($feUserRecord) && + !empty($feUserRecord['static_info_country']) + ) { + $deliveryInfo = $feUserRecord; + $deliveryInfo['country_code'] = $feUserRecord['static_info_country']; + } + $taxId = 0; if (isset($row['tax_id'])) { $taxId = intval($row['tax_id']); @@ -492,12 +520,7 @@ public function getStaticTax( $taxCatId = intval($row['taxcat_id']); } - if ( - isset($row['ext']) && - is_array($row['ext']) - ) { - $extArray = $row['ext']; - } + $extArray = $row['ext'] ?? []; if ( isset($extArray['records']) && @@ -515,7 +538,8 @@ public function getStaticTax( ( $taxId > 0 || $taxCatId > 0 || - is_array($categoryArray) && count($categoryArray) + count($categoryArray) || + $deliveryInfo['country_code'] != $this->countryArray['shop']['country_code'] ) ) { $uid = $row['uid']; @@ -525,6 +549,7 @@ public function getStaticTax( } else { $staticInfoApi = GeneralUtility::makeInstance(OldStaticInfoTablesApi::class); } + $countryArray = $this->countryArray; if (isset($personInfo) && is_array($personInfo)) { @@ -553,34 +578,41 @@ public function getStaticTax( $zoneCode = ''; $taxInfoArray = - TaxApi::fetchCountryTaxes( - $countryCode, - $zoneCode, - $staticInfoApi, - 0.0, - $categoryArray, - $taxId, - $countryArray['shop']['country_code'], - $countryArray['shop']['zone'], - $countryArray['shipping']['country_code'], - $countryArray['shipping']['zone'], - $countryArray['billing']['country_code'], - $countryArray['billing']['zone'], - 0, - true - ); - + TaxApi::fetchCountryTaxes( + $countryCode, + $zoneCode, + $staticInfoApi, + 0.0, // neu + $categoryArray, + $taxId, + $countryArray['shop']['country_code'], + $countryArray['shop']['zone'], + $countryArray['shipping']['country_code'], + $countryArray['shipping']['zone'], + $countryArray['billing']['country_code'], + $countryArray['billing']['zone'], + 0, + true + ); $this->storeValues( $countryArray ); - if (empty($categoryArray) && $taxId) { + $tax = null; + + if ( + isset($taxInfoArray) && + is_array($taxInfoArray) && + !empty($taxInfoArray) && + empty($categoryArray) && + $taxId + ) { $this->setAllTaxesArray( $taxInfoArray, $taxId ); + $tax = 0.0; } - $tax = 0.0; if ( isset($taxInfoArray) && @@ -594,21 +626,24 @@ public function getStaticTax( $tax = $taxRow['tx_rate']; } else { // calculate together many taxes and use them as one single tax. (Canada) $priceOne = - TaxApi::applyConsumerTaxes( - $taxInfoArray, - doubleval(1) - ); + TaxApi::applyConsumerTaxes( + $taxInfoArray, + doubleval(1) + ); if ($priceOne !== false) { $tax = ($priceOne - 1) * 100; } } } - if (empty($categoryArray)) { + + if (empty($categoryArray) && isset($tax)) { $this->setTax($tax, $taxId); } } else { $tax = $this->getTaxArray($taxId); } + } else { + $tax = null; // keine Steuer mit 0 direkt ´verwenden! } } } diff --git a/model/class.tx_ttproducts_voucher.php b/model/class.tx_ttproducts_voucher.php index 206f94283..ed64e5ba8 100644 --- a/model/class.tx_ttproducts_voucher.php +++ b/model/class.tx_ttproducts_voucher.php @@ -1,29 +1,32 @@ setAmountType($amountType); $this->setUsedVoucherCodeArray($usedVoucherCodeArray); + + $combinable = true; + foreach ($usedVoucherCodeArray as $codeRow) { + if ( + isset($codeRow) && is_array($codeRow) && + $codeRow['combinable'] == '1' + ) { + $combinable = false; + break; + } + } + $this->setCombinable($combinable); } } - return $result; + return true; // Die Voucher Tabelle muss nicht verwendet werden. Die Subpart Marker müssen ggf. gelöscht werden. } // init - public static function generate(&$voucherCount, &$codeArray, $orderUid, $itemArray, $whereGift) + public static function generate(&$voucherCount, array &$codeArray, $orderUid, $itemArray, $whereGift) { $result = false; - - if (class_exists('tx_voucher_api')) { + $voucherClassname = '\\JambageCom\\Voucher\\Api\\Api'; + if (class_exists($voucherClassname)) { $result = true; foreach ($itemArray as $sort => $actItemArray) { foreach ($actItemArray as $k1 => $actItem) { @@ -96,7 +116,7 @@ public static function generate(&$voucherCount, &$codeArray, $orderUid, $itemArr $voucherRow['amount'] = $actItem['priceTax']; $voucherRow['tax'] = $actItem['tax']; $voucherRow['title'] = $row['title']; - $inserted = tx_voucher_api::insertVoucher($voucherRow); + $inserted = Api::insertVoucher($voucherRow); if ($inserted) { $uid = $voucherRow['uid']; @@ -151,6 +171,7 @@ public function isEnabled() public static function unhideGifts(array &$uidArray, $orderRow, $whereGift) { $result = false; + $uidArray = []; if ($orderRow['gained_voucher'] > 0) { @@ -158,11 +179,11 @@ public static function unhideGifts(array &$uidArray, $orderRow, $whereGift) $where_clause = 'uid_local=' . intval($orderRow['uid']) . ' AND hidden=0 AND deleted=0'; $voucherRelationRows = - $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - 'uid_local,uid_foreign', - $table, - $where_clause - ); + $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + 'uid_local,uid_foreign', + $table, + $where_clause + ); if ( is_array($voucherRelationRows) && @@ -200,6 +221,26 @@ public function setAmount($amount): void $this->amount = $amount; } + public function getPossibleAmount() + { + return $this->possibleAmount; + } + + public function setPossibleAmount($possibleAmount): void + { + $this->possibleAmount = $possibleAmount; + } + + public function getCombinable() + { + return $this->combinable; + } + + public function setCombinable($combinable): void + { + $this->combinable = $combinable; + } + public function getAmountType() { return $this->amountType; @@ -210,6 +251,16 @@ public function setAmountType($amountType): void $this->amountType = $amountType; } + public function getCalculatedArray() + { + return $this->calculatedArray; + } + + public function setCalculatedArray($calculatedArray): void + { + $this->calculatedArray = $calculatedArray; + } + public function getPercentageAmount($amount) { $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); @@ -231,9 +282,27 @@ public function getRebateAmount() return $amount; } + // neu Anfang + public function getRebatePercentage() + { + $result = 0; + $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); + $calculatedArray = $basketObj->getCalculatedArray(); + + if ($calculatedArray['priceTax']['goodstotal']['ALL'] > 0) { + $result = (1 - ($calculatedArray['priceTax']['vouchergoodstotal']['ALL'] / $calculatedArray['priceTax']['goodstotal']['ALL'])) * 100; + } + + return $result; + } + // neu Ende + public function setUsedVoucherCodeArray($usedVoucherCodeArray): void { - if (isset($usedVoucherCodeArray) && is_array($usedVoucherCodeArray)) { + if ( + isset($usedVoucherCodeArray) && + is_array($usedVoucherCodeArray) + ) { $this->usedVoucherCodeArray = $usedVoucherCodeArray; } } @@ -246,8 +315,9 @@ public function getUsedVoucherCodeArray() public function isVoucherCodeUsed($code) { $result = false; + $usedVoucherCodeArray = $this->getUsedVoucherCodeArray(); - foreach ($this->usedVoucherCodeArray as $codeRow) { + foreach ($usedVoucherCodeArray as $codeRow) { if ( isset($codeRow) && is_array($codeRow) && $codeRow['code'] == $code @@ -260,7 +330,7 @@ public function isVoucherCodeUsed($code) return $result; } - public function getVoucherArray($code) + public function getVoucherRow($code) { $result = false; @@ -278,16 +348,77 @@ public function getLastVoucherCodeUsed() { $result = ''; - if (is_array($this->usedVoucherCodeArray) && count($this->usedVoucherCodeArray)) { + if (count($this->usedVoucherCodeArray)) { $lastArray = array_pop($this->usedVoucherCodeArray); - $result = key($lastArray); + if ( + isset($lastArray) && + is_array($lastArray) && + isset($lastArray['code']) + ) { + $result = $lastArray['code']; + } array_push($this->usedVoucherCodeArray, $lastArray); } return $result; } - public function setVoucherCodeUsed($code, $row): void + // neu Anfang + + public function voucherCodeDiscountCombinable( + $calculatedArray + ) { + $result = true; + $combinable = $this->getCombinable(); + + if ( + !$combinable && + ( + $calculatedArray['noDiscountPriceTax']['goodstotal']['ALL'] - $calculatedArray['priceTax']['goodstotal']['ALL'] > -0.1 + ) + ) { + $result = false; + } + + return $result; + } + + public function voucherCodeExceedsLimit( + $amount, + $calculatedArray + ) { + $result = false; + + if ( + doubleval($amount) > $calculatedArray['priceTax']['goodstotal']['ALL'] + ) { + $result = true; + } + + return $result; + } + + public function combinationAllowed($row) + { + $result = false; + $lastVoucherCode = $this->getLastVoucherCodeUsed(); + + if ( + $row['combinable'] == '0' && + $this->getCombinable() || + $row['combinable'] == '1' && + ( + $lastVoucherCode == '' || + $lastVoucherCode == $row['code'] + ) + ) { + $result = true; + } + + return $result; + } + + public function setVoucherCodeUsed($row): void { array_push($this->usedVoucherCodeArray, $row); } @@ -312,44 +443,49 @@ public function getVoucherTableName() return $result; } - public function setValid($bValid = true): void + public function setValid($valid = true): void { - $this->bValid = $bValid; + $this->valid = $valid; } public function getValid() { - return $this->bValid; + return $this->valid; } - public function delete(): void + public function delete($feUserRecord): void { $voucherCode = $this->getLastVoucherCodeUsed(); - $voucherArray = $this->getVoucherArray($voucherCode); + $voucherRow = $this->getVoucherRow($voucherCode); if ( $voucherCode && - isset($voucherArray) && - is_array($voucherArray) + isset($voucherRow) && + is_array($voucherRow) ) { - $row = $voucherArray; - + $row = $voucherRow; $voucherTable = $this->getVoucherTableName(); + $voucherClassname = '\\JambageCom\\Voucher\\Api\\Api'; if ($voucherTable == 'fe_users') { $whereGeneral = ''; $uid_voucher = $row['uid']; - } else { - $row = tx_voucher_api::getRowFromCode($voucherCode, true); + } elseif (class_exists($voucherClassname)) { + $row = + Api::getRowFromCode( + $voucherCode, + true + ); $uid_voucher = $row['fe_users_uid']; - $whereGeneral = '(fe_users_uid="' . ($GLOBALS['TSFE']->fe_user->user['uid'] ?? 0) . '" OR fe_users_uid=0) '; + $whereGeneral = '(fe_users_uid="' . intval($feUserRecord['uid'] ?? 0) . '" OR fe_users_uid=0) '; $whereGeneral .= 'AND code=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($voucherCode, $voucherTable); } if ( $uid_voucher && - isset($GLOBALS['TSFE']->fe_user->user['uid']) && - $GLOBALS['TSFE']->fe_user->user['uid'] == $uid_voucher || + !empty($feUserRecord['uid']) && + $feUserRecord['uid'] == $uid_voucher || + $voucherTable != 'fe_users' && !$row['reusable'] ) { @@ -367,28 +503,43 @@ public function delete(): void } } - public function doProcessing($recs): void + public function doProcessing(array $recs, array $calculatedArray, $feUserRecord): void { $voucherCode = $recs['tt_products']['vouchercode'] ?? ''; $voucherTable = $this->getVoucherTableName(); $this->setVoucherCode($voucherCode); - $cObj = FrontendUtility::getContentObjectRenderer(); + $this->setCalculatedArray($calculatedArray); + $this->setValid(false); + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); if ( $this->isVoucherCodeUsed($voucherCode) || $voucherCode == '' ) { - $this->setValid(true); $lastVoucherCode = $this->getLastVoucherCodeUsed(); - // $row = $this->usedVoucherCodeArray[$lastVoucherCode]; - $row = $this->getVoucherArray($lastVoucherCode); + $row = $this->getVoucherRow($lastVoucherCode); if (isset($row) && is_array($row)) { - $this->setAmount($row['amount']); - $this->setAmountType($row['amount_type']); + if ( + $this->voucherCodeDiscountCombinable( + $calculatedArray + ) && + !$this->voucherCodeExceedsLimit( + $row['amount'], + $calculatedArray + ) + ) { + $this->setValid(true); + $this->setAmount($row['amount']); + $this->setAmountType($row['amount_type']); + } else { + $this->setAmount($row['amount']); + $this->setAmountType($row['amount_type']); + $rebateAmount = $this->getRebateAmount(); + $this->setPossibleAmount($rebateAmount); + $this->setAmount(0); + } } - } else { - $this->setValid(false); } if ( @@ -396,33 +547,31 @@ public function doProcessing($recs): void !$this->isVoucherCodeUsed($voucherCode) && ( $voucherTable != 'fe_users' || - !empty($GLOBALS['TSFE']->fe_user->user['uid']) + !empty($feUserRecord['uid']) ) - ) { $uid_voucher = ''; $voucherfieldArray = []; $whereGeneral = '1=1'; + if ($voucherTable == 'fe_users') { $voucherfieldArray = ['uid', 'tt_products_vouchercode']; - if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { - $whereGeneral = $voucherTable . '.uid=' . intval($GLOBALS['TSFE']->fe_user->user['uid']); + if (isset($feUserRecord['uid'])) { + $whereGeneral = $voucherTable . '.uid=' . intval($feUserRecord['uid']); } else { $whereGeneral = '(fe_users_uid=0)'; } $whereGeneral .= ' AND ' . $voucherTable . '.tt_products_vouchercode=' . $TYPO3_DB->fullQuoteStr($voucherCode, $voucherTable); } else { - $voucherfieldArray = ['starttime', 'endtime', 'title', 'fe_users_uid', 'reusable', 'code', 'amount', 'amount_type', 'note']; - if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { - $whereGeneral = '(fe_users_uid="' . intval($GLOBALS['TSFE']->fe_user->user['uid']) . '" OR fe_users_uid=0)'; + $voucherfieldArray = ['starttime', 'endtime', 'title', 'code', 'fe_users_uid', 'reusable', 'code', 'usecounter', 'combinable', 'amount', 'amount_type', 'tax']; + if (isset($feUserRecord['uid'])) { + $whereGeneral = '(fe_users_uid="' . intval($feUserRecord['uid']) . '" OR fe_users_uid=0)'; } else { $whereGeneral = '(fe_users_uid=0)'; } $whereGeneral .= ' AND code=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($voucherCode, $voucherTable); } - $enableFields = TableUtility::enableFields($voucherTable); - - $where = $whereGeneral . $enableFields; + $where = $whereGeneral . $pageRepository->enableFields($voucherTable); $fields = implode(',', $voucherfieldArray); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $voucherTable, $where); @@ -446,12 +595,13 @@ public function doProcessing($recs): void $row && ( $voucherTable != 'fe_users' || - isset($GLOBALS['TSFE']->fe_user->user['uid']) && - $uid_voucher == $GLOBALS['TSFE']->fe_user->user['uid'] + isset($feUserRecord['uid']) && + $uid_voucher == $feUserRecord['uid'] ) ) { $amount = doubleval($this->getAmount()); $amountType = intval($this->getAmountType()); + $combinable = $this->getCombinable(); if ($amountType == $row['amount_type']) { $amount += $row['amount']; @@ -459,12 +609,29 @@ public function doProcessing($recs): void $amount += $this->getPercentageAmount($row['amount']); } - $this->setAmount($amount); - $this->setVoucherCode($row['code']); - $this->setValid(true); - - $this->setVoucherCodeUsed($voucherCode, $row); - tx_ttproducts_control_session::writeSession('vo', $this->getUsedVoucherCodeArray()); + if ( + $this->voucherCodeDiscountCombinable( + $calculatedArray + ) && + !$this->voucherCodeExceedsLimit( + $amount, + $calculatedArray + ) + ) { + if ($this->combinationAllowed($row)) { + $this->setAmount($amount); + $this->setVoucherCode($row['code']); + $this->setValid(true); + + $this->setVoucherCodeUsed($row); + SessionHandler::storeSession('vo', $this->getUsedVoucherCodeArray()); + } + } else { + $this->setAmount($amount); + $rebateAmount = $this->getRebateAmount(); + $this->setPossibleAmount($rebateAmount); + $this->setAmount(0); + } } } } diff --git a/model/field/class.tx_ttproducts_field_base.php b/model/field/class.tx_ttproducts_field_base.php index 5cad399fc..251f927b0 100644 --- a/model/field/class.tx_ttproducts_field_base.php +++ b/model/field/class.tx_ttproducts_field_base.php @@ -45,7 +45,7 @@ abstract class tx_ttproducts_field_base implements tx_ttproducts_field_int, Sing public $conf; // original configuration public $config; // modified configuration - public function init(): void + public function init(...$args): void { $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $this->conf = $cnf->conf; diff --git a/model/field/class.tx_ttproducts_field_creditpoints.php b/model/field/class.tx_ttproducts_field_creditpoints.php index 863d71875..d84b05183 100644 --- a/model/field/class.tx_ttproducts_field_creditpoints.php +++ b/model/field/class.tx_ttproducts_field_creditpoints.php @@ -1,29 +1,32 @@ get('fe_users', false); - - $feuserCreditpoints = $feuserTable->getCreditpoints(); + $feUserRecord = CustomerApi::getFeUserRecord(); + $feuserCreditpoints = tx_ttproducts_creditpoints_div::getCreditPointsFeuser($feUserRecord); $creditpointsTotal = $this->getBasketTotal() + $addCreditpoints; $missing = $creditpointsTotal - $feuserCreditpoints; $missing = ($missing > 0 ? $missing : 0); @@ -92,11 +96,9 @@ public function getBasketMissingCreditpoints($addCreditpoints, &$missing, &$rema public function getMissingCreditpoints($fieldname, $row, &$missing, &$remaining): void { - $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - $feuserTable = $tablesObj->get('fe_users', false); - + $feUserRecord = CustomerApi::getFeUserRecord(); $creditpointsTotal = $this->getBasketTotal(); - $feuserCreditpoints = $feuserTable->getCreditpoints(); + $feuserCreditpoints = tx_ttproducts_creditpoints_div::getCreditPointsFeuser($feUserRecord); $missing = $creditpointsTotal + $row[$fieldname] - $feuserCreditpoints; $missing = ($missing > 0 ? $missing : 0); $remaining = $feuserCreditpoints - $creditpointsTotal - $row[$fieldname]; @@ -107,21 +109,22 @@ public function getMissingCreditpoints($fieldname, $row, &$missing, &$remaining) public function pay() { $rc = false; - if (CompatibilityUtility::isLoggedIn()) { - // $whereGeneral = '(fe_users_uid="'.$GLOBALS['TSFE']->fe_user->user['uid'].'" OR fe_users_uid=0) '; + $feUserRecord = CustomerApi::getFeUserRecord(); + $context = GeneralUtility::makeInstance(Context::class); + if ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn')) { $creditpointsTotal = $this->getBasketTotal(); if ($creditpointsTotal) { $fieldsArrayFeUsers = []; - $fieldsArrayFeUsers['tt_products_creditpoints'] = $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] - $creditpointsTotal; + $fieldsArrayFeUsers['tt_products_creditpoints'] = $feUserRecord['tt_products_creditpoints'] - $creditpointsTotal; if ($fieldsArrayFeUsers['tt_products_creditpoints'] < 0) { $fieldsArrayFeUsers['tt_products_creditpoints'] = 0; - $rc = $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints']; + $rc = $feUserRecord['tt_products_creditpoints']; } - if ($GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] != $fieldsArrayFeUsers['tt_products_creditpoints']) { - $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] = $fieldsArrayFeUsers['tt_products_creditpoints']; // store it also for the global FE user data - $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . intval($GLOBALS['TSFE']->fe_user->user['uid']), $fieldsArrayFeUsers); + if ($feUserRecord['tt_products_creditpoints'] != $fieldsArrayFeUsers['tt_products_creditpoints']) { + $feUserRecord['tt_products_creditpoints'] = $fieldsArrayFeUsers['tt_products_creditpoints']; // store it also for the global FE user data + $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . intval($feUserRecord['uid']), $fieldsArrayFeUsers); $rc = $creditpointsTotal; } } diff --git a/model/field/class.tx_ttproducts_field_price.php b/model/field/class.tx_ttproducts_field_price.php index a98988c98..0e06a26eb 100644 --- a/model/field/class.tx_ttproducts_field_price.php +++ b/model/field/class.tx_ttproducts_field_price.php @@ -36,11 +36,13 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\CompatibilityUtility; -use JambageCom\TtProducts\Model\Field\FieldInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; +use JambageCom\TtProducts\Api\CustomerApi; +use JambageCom\TtProducts\Api\DiscountApi; +use JambageCom\TtProducts\Model\Field\FieldInterface; + class tx_ttproducts_field_price extends tx_ttproducts_field_base { private bool $bHasBeenInitialised = false; @@ -241,11 +243,13 @@ public function getModePrice( /** reduces price by discount for FE user **/ public static function getDiscountPrice( + &$priceModified, $price, $discount = '' ) { if (floatval($discount) != 0) { $price = $price * (1 - $discount / 100); + $priceModified = true; } return $price; @@ -416,37 +420,55 @@ public static function getSkonto( public static function calculateEndPrice( $price, $row, - $discountField + $discountField, + $taxIncluded, + $bTax, // if the taxed price should be returned + $taxpercentage, + $feUserRecord, ) { + $originalPrice = $price; + $priceModified = false; $calculationField = FieldInterface::PRICE_CALCULATED; $maxDiscount = 0; $discount = 0; - if ($discountField != '' && isset($row[$discountField])) { - $maxDiscount = $row[$discountField]; - } + $discountApi = GeneralUtility::makeInstance(DiscountApi::class); + $discountArray = $discountApi->getFeuserDiscounts($feUserRecord); - if ( - CompatibilityUtility::isLoggedIn() && - isset($GLOBALS['TSFE']->fe_user) && - isset($GLOBALS['TSFE']->fe_user->user) - ) { - $discount = $GLOBALS['TSFE']->fe_user->user['tt_products_discount']; - } - - if ($discount > $maxDiscount) { - $maxDiscount = $discount; + foreach ($discountArray as $discount) { + if ($discount > $maxDiscount) { + $maxDiscount = $discount; + } } - $price = self::getDiscountPrice($price, $maxDiscount); if ( isset($row[$calculationField]) && - floatval($row[$calculationField]) > 0 + MathUtility::canBeInterpretedAsFloat($row[$calculationField]) && + ( + ( + $row[$calculationField] == 0 && + $originalPrice > 0 + ) || + ( + $row[$calculationField] > 0 && + $originalPrice >= 0 + ) + ) ) { - $price = $row[$calculationField]; + if ($originalPrice == 0) { + $calculationDiscount = 100; + } else { + $calculationDiscount = (1 - $row[$calculationField] / $originalPrice) * 100; + } + if ($maxDiscount < $calculationDiscount) { + $price = $row[$calculationField]; + $priceModified = true; + $maxDiscount = 0; + } } - - $result = $price; + $price = static::getDiscountPrice($priceModified,$price, $maxDiscount); + $taxFactor = 1 + $taxpercentage / 100; + $result = static::getPriceTax($price, $bTax, $taxIncluded, $taxFactor); return $result; } @@ -465,8 +487,11 @@ public function getPriceTaxArray( $bEnableTaxZero = false, $notOverwritePriceIfSet = true ) { + $feUserRecord = CustomerApi::getFeUserRecord(); + $internalRow = $row; $priceArray = []; + $taxIncluded = $this->getTaxIncluded(); $bIsZeroTax = false; if ( @@ -488,6 +513,7 @@ public function getPriceTaxArray( } } } else { + $taxpercentage = 0.0; $price0tax = $this->getResellerPrice( $basketExtra, @@ -535,11 +561,27 @@ public function getPriceTaxArray( } $priceArray['taxperc'] = $taxpercentage; + $internalPrice = 0; + $internalTaxIncluded = true; + if ( + !isset($internalRow['oldpricetax']) || + $internalRow['oldpricetax'] == 0 + ) { // keep a previously set old price + $internalPrice = $internalRow['price']; + $internalTaxIncluded = $taxIncluded; + } else { + $internalPrice = $internalRow['oldpricetax']; + } + $internalRow['price'] = - self::calculateEndPrice( + $this->calculateEndPrice( $row['price'], $row, - $discountField + $discountField, + $taxIncluded, + $internalTaxIncluded, + $taxpercentage, + $feUserRecord ); $priceArray['tax'] = @@ -691,13 +733,17 @@ public function getPriceTaxArray( $row[FieldInterface::DISCOUNT] != 0 && $row[FieldInterface::DISCOUNT_DISABLE] == 0 ) { + $priceModified = false; $priceArray['discountbyproductpricetax'] = self::getDiscountPrice( + $priceModified, $priceArray['discountbyproductpricetax'], $row[FieldInterface::DISCOUNT] ); + $priceModified = false; $priceArray['discountbyproductpricenotax'] = self::getDiscountPrice( + $priceModified, $priceArray['discountbyproductpricenotax'], $row[FieldInterface::DISCOUNT] ); @@ -748,11 +794,16 @@ public function getPriceTaxArray( $bEnableTaxZero ); } elseif (strpos($fieldname, 'price') === 0) { + $internalTaxIncluded = $taxIncluded; $internalRow['price'] = - self::calculateEndPrice( + $this->calculateEndPrice( $row['price'], $row, - $discountField + $discountField, + $taxIncluded, + $internalTaxIncluded, + $taxpercentage, + $feUserRecord ); if ($roundFormat != '') { diff --git a/pi1/class.tx_ttproducts_pi1_base.php b/pi1/class.tx_ttproducts_pi1_base.php index 2b60a734c..9a41fb7d4 100644 --- a/pi1/class.tx_ttproducts_pi1_base.php +++ b/pi1/class.tx_ttproducts_pi1_base.php @@ -38,11 +38,14 @@ * @subpackage tt_products * */ +use Psr\Http\Message\ServerRequestInterface; + use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use JambageCom\Div2007\Compatibility\AbstractPlugin; + use JambageCom\TtProducts\Api\ParameterApi; use JambageCom\TtProducts\Api\PluginApi; @@ -71,7 +74,7 @@ public function main($content, $conf) $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $parameterApi->setPrefixId($this->prefixId); PluginApi::init($conf); - tx_ttproducts_model_control::setPrefixId($this->prefixId); + $parameterApi->setPrefixId($this->prefixId); $this->conf = $conf; $config = []; @@ -82,6 +85,7 @@ public function main($content, $conf) $mainObj->init( $conf, $config, + $this->getRequest(), $this->cObj, get_class($this), $errorCode @@ -106,4 +110,9 @@ public function set($bRunAjax): void { $this->bRunAjax = $bRunAjax; } + + private function getRequest(): ServerRequestInterface + { + return $GLOBALS['TYPO3_REQUEST']; + } } diff --git a/pi1/products_comp_calcScript.inc b/pi1/products_comp_calcScript.inc index 9a45b9cbe..d5cb58a5a 100644 --- a/pi1/products_comp_calcScript.inc +++ b/pi1/products_comp_calcScript.inc @@ -19,7 +19,7 @@ TypoScript properties: $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); -$baseAmount = $basketObj->calculatedArray['priceTax']['goodstotal'] + $basketObj->calculatedArray['priceTax']['shipping']; // The fee is calculated from the total of the goods AND shipping +$baseAmount = $basketObj->calculatedArray['priceTax']['goodstotal']['ALL'] + $basketObj->calculatedArray['priceTax']['shipping']; // The fee is calculated from the total of the goods AND shipping $feePercent = doubleval($confScript['feePercent'] ? $confScript['feePercent'] : 5.75); // Fee percent is by default 5.75 % # Calculate conpensating percentage by: 100/(1-pFee/100)-100 = pComp, where pFee is the percentage, eg. Mastercard is taking (5,75%) and pComp will thus be 6.1 % $compPercent = 100/(1-$feePercent/100)-100; // The compensation percentage. diff --git a/pi_int/class.tx_ttproducts_pi_int_base.php b/pi_int/class.tx_ttproducts_pi_int_base.php index 6716952e4..6983e9586 100644 --- a/pi_int/class.tx_ttproducts_pi_int_base.php +++ b/pi_int/class.tx_ttproducts_pi_int_base.php @@ -38,6 +38,7 @@ * @subpackage tt_products * */ +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -72,7 +73,7 @@ public function main($content, $conf) $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $parameterApi->setPrefixId($this->prefixId); PluginApi::init($conf); - tx_ttproducts_model_control::setPrefixId($this->prefixId); + $parameterApi->setPrefixId($this->prefixId); $this->conf = $conf; $config = []; @@ -82,6 +83,7 @@ public function main($content, $conf) $mainObj->init( $conf, $config, + $this->getRequest(), $this->cObj, get_class($this), $errorCode @@ -104,4 +106,9 @@ public function set($bRunAjax): void { $this->bRunAjax = $bRunAjax; } + + private function getRequest(): ServerRequestInterface + { + return $GLOBALS['TYPO3_REQUEST']; + } } diff --git a/pi_search/class.tx_ttproducts_pi_search_base.php b/pi_search/class.tx_ttproducts_pi_search_base.php index 5391dff93..18f40d55f 100644 --- a/pi_search/class.tx_ttproducts_pi_search_base.php +++ b/pi_search/class.tx_ttproducts_pi_search_base.php @@ -38,6 +38,8 @@ * @subpackage tt_products * */ +use Psr\Http\Message\ServerRequestInterface; + use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -67,7 +69,6 @@ public function getContentObjectRenderer(): ContentObjectRenderer */ public function main($content, $conf) { - tx_ttproducts_model_control::setPrefixId($this->prefixId); $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $parameterApi->setPrefixId($this->prefixId); PluginApi::init($conf); @@ -81,6 +82,7 @@ public function main($content, $conf) $mainObj->init( $this->conf, $config, + $this->getRequest(), $this->cObj, get_class($this), $errorCode @@ -103,4 +105,9 @@ public function set($bRunAjax): void { $this->bRunAjax = $bRunAjax; } + + private function getRequest(): ServerRequestInterface + { + return $GLOBALS['TYPO3_REQUEST']; + } } diff --git a/view/class.tx_ttproducts_article_base_view.php b/view/class.tx_ttproducts_article_base_view.php index b95ee9ae6..57165ba9c 100644 --- a/view/class.tx_ttproducts_article_base_view.php +++ b/view/class.tx_ttproducts_article_base_view.php @@ -191,7 +191,6 @@ public function getCurrentPriceMarkerArray( } else { $row = $originalRow; } - $this->getPriceMarkerArray( $basketExtra, $basketRecs, @@ -219,7 +218,6 @@ public function getPriceMarkerArray( $modelObj = $this->getModelObj(); $priceViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_price_view'); $funcTablename = $modelObj->getFuncTablename(); - $mainId = $this->getId($row, $id, $theCode); foreach ($GLOBALS['TCA'][$funcTablename]['columns'] as $field => $fieldTCA) { @@ -239,95 +237,4 @@ public function getPriceMarkerArray( } } } - - /** - * Template marker substitution - * Fills in the markerArray with data for a product. - * - * @param array reference to an item array with all the data of the item - * @param string title of the category - * @param int number of images to be shown - * @param object the image cObj to be used - * @param array information about the parent HTML form - * - * @return array Returns a markerArray ready for substitution with information - * for the tt_producst record, $row - * - * @access private - */ - public function getModelMarkerArray( - $row, - $markerKey, - &$markerArray, - $catTitle, - $imageNum = 0, - $imageRenderObj = 'image', - $tagArray = [], - $forminfoArray = [], - $theCode = '', - $basketExtra = [], - $basketRecs = [], - $id = '', - $prefix = '', - $suffix = '', - $linkWrap = '', - $bHtml = true, - $charset = '', - $hiddenFields = '', - $multiOrderArray = [], - $productRowArray = [], - $bEnableTaxZero = false, - $notOverwritePriceIfSet = true - ) { - $modelObj = $this->getModelObj(); - $imageObj = GeneralUtility::makeInstance('tx_ttproducts_field_image_view'); - $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); - $conf = $cnfObj->getConf(); - - if ($markerKey) { - $marker = $markerKey; - } else { - $marker = $this->getMarker(); - } - - if (!$marker) { - return []; - } - $variantFieldArray = $modelObj->variant->getFieldArray(); - $variantMarkerArray = []; - - $this->getRowMarkerArray( - $modelObj->getFuncTablename(), - $row, - $marker, - $markerArray, - $variantFieldArray, - $variantMarkerArray, - $tagArray, - $theCode, - $basketExtra, - $basketRecs, - $bHtml, - $charset, - $imageNum, - $imageRenderObj, - $id, - $prefix, - $suffix, - $linkWrap, - $bEnableTaxZero - ); - - $this->getPriceMarkerArray( - $basketExtra, - $basketRecs, - $markerArray, - $row, - $markerKey, - $id, - $theCode, - $bEnableTaxZero, - $notOverwritePriceIfSet - ); - } } diff --git a/view/class.tx_ttproducts_basket_view.php b/view/class.tx_ttproducts_basket_view.php index 7284341fb..af805235e 100644 --- a/view/class.tx_ttproducts_basket_view.php +++ b/view/class.tx_ttproducts_basket_view.php @@ -55,9 +55,15 @@ use JambageCom\TtProducts\Api\ActivityApi; use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\BasketItemApi; +use JambageCom\TtProducts\Api\BasketItemViewApi; +use JambageCom\TtProducts\Api\CreditpointsViewApi; +use JambageCom\TtProducts\Api\FeUserMarkerApi; use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; use JambageCom\TtProducts\Api\PaymentShippingHandling; use JambageCom\TtProducts\Model\Field\FieldInterface; +use JambageCom\TtProducts\View\RelatedList; @@ -265,6 +271,7 @@ public function getView( $templateCode, $theCode, $infoViewObj, + $feUserRecord, $bSelectSalutation, $bSelectVariants, $calculatedArray, @@ -282,13 +289,14 @@ public function getView( $basketRecs = [] ) { /* - Very central function in the library. By default it extracts the subpart, ###BASKET_TEMPLATE###, from the $templateCode (if given, else the default $this->templateCode) and substitutes a lot of fields and subparts. Any pre-preparred fields can be set in $mainMarkerArray, which is substituted in the subpart before the item-and-categories part is substituted. */ + $out = ''; + $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); $calculationField = FieldInterface::PRICE_CALCULATED; $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); @@ -303,7 +311,10 @@ public function getView( $basketItemView = GeneralUtility::makeInstance('tx_ttproducts_basketitem_view'); $cObj = FrontendUtility::getContentObjectRenderer(); $taxObj = GeneralUtility::makeInstance('tx_ttproducts_field_tax'); - $piVars = tx_ttproducts_model_control::getPiVars(); + $basketItemViewApi = GeneralUtility::makeInstance(BasketItemViewApi::class, $cnf->getConf()); + $basketItemApi = GeneralUtility::makeInstance(BasketItemApi::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $piVars = $parameterApi->getPiVars(); $articleViewTagArray = []; $checkPriceZero = true; $this->urlObj = GeneralUtility::makeInstance('tx_ttproducts_url_view'); // a copy of it @@ -380,23 +391,15 @@ public function getView( $orderAddressViewObj = $tablesObj->get('fe_users', true); $orderAddressObj = $orderAddressViewObj->getModelObj(); - $orderAddressViewObj->getWrappedSubpartArray( + $feUserMarkerApi = GeneralUtility::makeInstance(FeUserMarkerApi::class); + $feUserMarkerApi->getWrappedSubpartArray( + $orderAddressObj, $viewTagArray, - $useBackPid, + $feUserRecord, $feuserSubpartArray, $feuserWrappedSubpartArray ); - $feUserRow = []; - - if ( - CompatibilityUtility::isLoggedIn() && - isset($GLOBALS['TSFE']->fe_user->user) && - is_array($GLOBALS['TSFE']->fe_user->user) - ) { - $feUserRow = $GLOBALS['TSFE']->fe_user->user; - } - $tmp = []; $feUsersParentArray = []; $feUsersArray = $markerObj->getMarkerFields( @@ -412,7 +415,7 @@ public function getView( $orderAddressViewObj->getItemSubpartArrays( $tempContent, 'fe_users', - $feUserRow, + $feUserRecord, $feuserSubpartArray, $feuserWrappedSubpartArray, $feUsersViewTagArray, @@ -420,7 +423,8 @@ public function getView( $basketExtra ); - $markerArray = []; + $feUserMarkerApi->getGlobalMarkerArray($markerArray, $feUserRecord); + if (isset($mainMarkerArray) && is_array($mainMarkerArray)) { $markerArray = array_merge($markerArray, $mainMarkerArray); } @@ -443,7 +447,7 @@ public function getView( $templateService->substituteMarkerArrayCached( $tempContent, $markerArray, - $feuserSubpartArray // The emptied subparts must be considered before the wrapped subparts are added because TYPO3 does not support nested subparts. + $mainSubpartArray // The emptied subparts must be considered before the wrapped subparts are added because TYPO3 does not support nested subparts. ); $t['basketFrameWork'] = @@ -517,6 +521,12 @@ public function getView( 'PRODUCT_SPECIAL_PREP' => 'special_preparation', 'PRODUCT_ADDITIONAL_SINGLE' => 'additional', 'PRODUCT_LINK_DATASHEET' => 'datasheet']; + $basketItemViewApi->init( + $markerFieldArray, + $t['item'], + $this->useArticles + ); + $parentArray = []; $fieldsArray = $markerObj->getMarkerFields( $t['item'], @@ -605,495 +615,66 @@ public function getView( $sum_pricecreditpoints_total_totunits = 0; $creditpointsGifts = ''; + $basketItemViewApi->init( + $markerFieldArray, + $t['item'], + $this->useArticles + ); + // loop over all items in the basket indexed by sorting text foreach ($itemArray as $sort => $actItemArray) { foreach ($actItemArray as $k1 => $actItem) { - $row = $actItem['rec']; - if (!$row) { // avoid bug with missing row - continue 2; - } - - $extArray = $row['ext']; - $pid = intval($row['pid']); - if (!tx_ttproducts_control_basket::getPidListObj()->getPageArray($pid)) { - // product belongs to another basket - continue 2; - } - $quantity = $itemObj->getQuantity($actItem); - $itemObj->getMinMaxQuantity($actItem, $minQuantity, $maxQuantity); - - if ($minQuantity != '0.00' && $quantity < $minQuantity) { - $quantityArray['minimum'][] = - [ - 'rec' => $row, - 'limitQuantity' => $minQuantity, - 'quantity' => $quantity, - ]; - } - if ($maxQuantity != '0.00' && $quantity > $maxQuantity) { - $quantityArray['maximum'][] = - [ - 'rec' => $row, - 'limitQuantity' => $maxQuantity, - 'quantity' => $quantity, - ]; - } $count++; - $actItem['rec'] = $row; // fix bug with PHP 5.2.1 - $bIsNoMinPrice = $itemTable->hasAdditional($row, 'noMinPrice'); - if (!$bIsNoMinPrice) { - $checkPriceArray['minimum'] = true; - } - - $bIsNoMaxPrice = $itemTable->hasAdditional($row, 'noMaxPrice'); - - if (!$bIsNoMaxPrice) { - $checkPriceArray['maximum'] = true; - } - - $pidcategory = ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'] == 1 ? $pid : ''); - $currentPnew = $pidcategory . '_' . $actItem['rec']['category']; - - // Print Category Title - if ($currentPnew != $currentP) { - if ($itemsOut) { - $out .= - $templateService->substituteSubpart( - $t['itemFrameWork'], - '###ITEM_SINGLE###', - $itemsOut - ); - } - $itemsOut = ''; // Clear the item-code var - $currentP = $currentPnew; - - if (!empty($conf['displayBasketCatHeader'])) { - $markerArray = []; - $pageCatTitle = ''; - if ( - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'] == 1 - ) { - $page = $tablesObj->get('pages'); - $pageTmp = $page->get($pid); - $pageCatTitle = $pageTmp['title'] . '/'; - } - $catTmp = ''; - if ($actItem['rec']['category']) { - $catTmp = $tablesObj->get('tt_products_cat')->get($actItem['rec']['category']); - $catTmp = $catTmp['title'] ?? ''; - } - $catTitle = $pageCatTitle . $catTmp; - $cObj->setCurrentVal($catTitle); - $markerArray['###CATEGORY_TITLE###'] = - $cObj->cObjGetSingle( - $conf['categoryHeader'], - $conf['categoryHeader.'], - 'categoryHeader' - ); - - $categoryQuantity = $basketObj->getCategoryQuantity(); - - // compatible with bill/delivery - $currentCategory = $row['category']; - $markerArray['###CATEGORY_QTY###'] = $categoryQuantity[$currentCategory]; - - $categoryPriceTax = $calculatedArray['categoryPriceTax']['goodstotal']['ALL'][$currentCategory] ?? 0; - $markerArray['###PRICE_GOODS_TAX###'] = $priceViewObj->priceFormat($categoryPriceTax); - $categoryPriceNoTax = $calculatedArray['categoryPriceNoTax']['goodstotal']['ALL'][$currentCategory]; - $markerArray['###PRICE_GOODS_NO_TAX###'] = $priceViewObj->priceFormat($categoryPriceNoTax); - $markerArray['###PRICE_GOODS_ONLY_TAX###'] = $priceViewObj->priceFormat($categoryPriceTax - $categoryPriceNoTax); - - $out .= $templateService->substituteMarkerArray($t['categoryFrameWork'], $markerArray); - } - } - // Fill marker arrays - $wrappedSubpartArray = []; - $subpartArray = []; - $markerArray = []; - - $bInputDisabled = ($row['inStock'] <= 0); - - $basketItemView->getItemMarkerArray( - $funcTablename, - false, - $actItem, - $markerArray, - $viewTagArray, - $hiddenFields, - $theCode, - $bInputDisabled, - $count, - false, - 'UTF-8' - ); - - $basketItemView->getItemMarkerSubpartArrays( - $t['item'], - $itemTable->getFuncTablename(), + $quantity = $basketItemApi->getQuantity($actItem); + $row = $actItem['rec']; + $basketItemApi->addMinMaxQuantities( + $quantityArray, $row, - 'SINGLE', - $viewTagArray, - false, - $productRowArray, - $markerArray, - $subpartArray, - $wrappedSubpartArray + $quantity ); - $catRow = $row['category'] ? $tablesObj->get('tt_products_cat')->get($row['category']) : []; - // $catTitle= $actItem['rec']['category'] ? $this->tt_products_cat->get($actItem['rec']['category']) : ''; - $catTitle = $catRow['title'] ?? ''; - $tmp = []; - - // use the product if no article row has been found - $prodVariantRow = $row; - - if (isset($actItem[$calculationField])) { - $prodVariantRow[$calculationField] = $actItem[$calculationField]; - } - - $prodMarkerRow = $prodVariantRow; - $itemTable->tableObj->substituteMarkerArray($prodMarkerRow); - $bIsGift = tx_ttproducts_gifts_div::isGift($row, $conf['whereGift']); - $itemTableView->getModelMarkerArray( - $prodMarkerRow, - '', - $markerArray, - $catTitle, - 0, - 'basketImage', - $viewTagArray, - $tmp, + $itemOut = $basketItemViewApi->generateItemView( + $hiddenFields, + $checkPriceArray, + $actItem, + $quantity, + $t['item'], $theCode, - $basketExtra, - $basketRecs, - $count, - '', - '', - '', - $bHtml, - 'UTF-8', - '', + $useBackPid, + $notOverwritePriceIfSet, + $feUserRecord, $multiOrderArray, $productRowArray, - true, - $notOverwritePriceIfSet - ); - - if ( - $this->useArticles == 1 || - $this->useArticles == 3 || - $bCopyProduct2Article - ) { - $articleRows = []; - - if (!$bCopyProduct2Article) { - // get the article uid with these colors, sizes and gradings - if ( - is_array($extArray) && - isset($extArray['mergeArticles']) && - is_array($extArray['mergeArticles']) - ) { - $prodVariantRow = $extArray['mergeArticles']; - } elseif ( - isset($extArray[$articleTable->getFuncTablename()]) && - is_array($extArray[$articleTable->getFuncTablename()]) - ) { - $articleExtArray = $extArray[$articleTable->getFuncTablename()]; - foreach ($articleExtArray as $k => $articleData) { - $articleRows[$k] = $articleTable->get($articleData['uid']); - } - } else { - $articleRow = $itemTable->getArticleRow($row, $theCode); - if ($articleRow) { - $articleRows[0] = $articleRow; - } - } - } - - if ( - is_array($articleRows) && - !empty($articleRows) - ) { - $bKeepNotEmpty = (bool) ($conf['keepProductData'] ?? 1); // Auskommentieren nicht möglich wenn mehrere Artikel dem Produkt zugewiesen werden - - if ($this->useArticles == 3) { - $itemTable->fillVariantsFromArticles( - $prodVariantRow - ); - $itemTable->getVariant()->modifyRowFromVariant($prodVariantRow); - } - foreach ($articleRows as $articleRow) { - $itemTable->mergeAttributeFields( - $prodVariantRow, - $articleRow, - $bKeepNotEmpty, - true, - true, - $calculationField, - false - ); - } - } else { - $variant = $itemTable->getVariant()->getVariantFromRow($row); - $itemTable->getVariant()->modifyRowFromVariant( - $prodVariantRow, - $variant - ); - } - // use the fields of the article instead of the product - // - - if ( - isset($extArray) && - isset($extArray['records']) && - is_array($extArray['records']) - ) { - $newTitleArray = []; - $externalRowArray = $extArray['records']; - foreach ($externalRowArray as $tablename => $externalRow) { - $newTitleArray[] = $externalRow['title']; - } - $prodVariantRow['title'] = implode(' | ', $newTitleArray); - } - $prodMarkerRow = $prodVariantRow; - $itemTable->tableObj->substituteMarkerArray($prodMarkerRow); - - $articleViewObj->getModelMarkerArray( - $prodMarkerRow, - '', - $markerArray, - $catTitle, - 0, - 'basketImage', - $articleViewTagArray, - $tmp, - $theCode, - $basketExtra, - $basketRecs, - $count, - '', - '', - '', - $bHtml, - 'UTF-8', - '', - $multiOrderArray, - $productRowArray, - false, // FHO wieder zurück korrigiert, sonst wird bei Artikel Tax=0 nicht die TAXpercentage genommen. - $notOverwritePriceIfSet - ); - - $articleViewObj->getItemMarkerSubpartArrays( - $t['item'], - $articleViewObj->getModelObj()->getFuncTablename(), - $prodVariantRow, - $markerArray, - $subpartArray, - $wrappedSubpartArray, - $articleViewTagArray, - $theCode, - $basketExtra - ); - } - - $itemTableView->getItemMarkerSubpartArrays( - $t['item'], - $itemTableView->getModelObj()->getFuncTablename(), - $prodVariantRow, - $markerArray, - $subpartArray, - $wrappedSubpartArray, - $viewTagArray, - [], - [], - $theCode, $basketExtra, $basketRecs, $count, - $checkPriceZero + $inputEntabled = true, + $bHtml ); - $cObj->setCurrentVal($catTitle); - $markerArray['###CATEGORY_TITLE###'] = - $cObj->cObjGetSingle( - $conf['categoryHeader'], - $conf['categoryHeader.'], - 'categoryHeader' - ); - - $markerArray['###PRICE_TOTAL_TAX###'] = $priceViewObj->priceFormat($actItem['totalTax'] + $actItem['deposittax'] * $quantity); - - $markerArray['###PRICE_TOTAL_NO_TAX###'] = $priceViewObj->priceFormat($actItem['totalNoTax'] + $actItem['depositnotax'] * $quantity); - $markerArray['###PRICE_TOTAL_ONLY_TAX###'] = $priceViewObj->priceFormat($actItem['totalTax'] - $actItem['totalNoTax'] + ($actItem['deposittax'] - $actItem['depositnotax']) * $quantity); - - $markerArray['###PRICE_TOTAL_0_TAX###'] = $priceViewObj->priceFormat($actItem['total0Tax']); - $markerArray['###PRICE_TOTAL_0_NO_TAX###'] = $priceViewObj->priceFormat($actItem['total0NoTax']); - $markerArray['###PRICE_TOTAL_0_ONLY_TAX###'] = $priceViewObj->priceFormat($actItem['total0Tax'] - $actItem['total0NoTax']); - - $pricecredits_total_totunits_no_tax = 0; - $pricecredits_total_totunits_tax = 0; - if ($row['category'] == ($conf['creditsCategory'] ?? -1)) { - // creditpoint system start - $pricecredits_total_totunits_no_tax = $actItem['totalNoTax'] * ($row['unit_factor'] ?? 0); - $pricecredits_total_totunits_tax = $actItem['totalTax'] * ($row['unit_factor'] ?? 0); - } - $markerArray['###PRICE_TOTAL_TOTUNITS_NO_TAX###'] = $priceViewObj->priceFormat($pricecredits_total_totunits_no_tax); - $markerArray['###PRICE_TOTAL_TOTUNITS_TAX###'] = $priceViewObj->priceFormat($pricecredits_total_totunits_tax); - $sum_pricecredits_total_totunits_no_tax += $pricecredits_total_totunits_no_tax; - $sum_price_total_totunits_no_tax += $pricecredits_total_totunits_no_tax; - $sum_pricecreditpoints_total_totunits += $pricecredits_total_totunits_no_tax; - - // creditpoint system end - $page = $tablesObj->get('pages'); - $pid = $page->getPID( - $conf['PIDitemDisplay'], - $conf['PIDitemDisplay.'] ?? '', - $row, - $GLOBALS['TSFE']->rootLine[1] ?? '' - ); - $addQueryString = []; - $addQueryString[$itemTable->type] = intval($row['uid']); - - if ( - is_array($extArray) && is_array($extArray[tx_ttproducts_control_basket::getFuncTablename()]) - ) { - $addQueryString['variants'] = htmlspecialchars($extArray[tx_ttproducts_control_basket::getFuncTablename()][0]['vars']); - } - $isImageProduct = $itemTable->hasAdditional($row, 'isImage'); - $damMarkerArray = []; - $damCategoryMarkerArray = []; - - if ( - ( - $isImageProduct || - $funcTablename == 'tt_products' - ) && - is_array($extArray) && - isset($extArray['tx_dam']) - ) { - reset($extArray['tx_dam']); - $damext = current($extArray['tx_dam']); - $damUid = $damext['uid']; - $damRow = $tablesObj->get('tx_dam')->get($damUid); - $damItem = []; - $damItem['rec'] = $damRow; - $damCategoryArray = - $tablesObj->get('tx_dam_cat')->getCategoryArray($damRow); - if (!empty($damCategoryArray)) { - reset($damCategoryArray); - $damCat = current($damCategoryArray); - } - - $tablesObj->get('tx_dam_cat', true)->getMarkerArray( - $damCategoryMarkerArray, - $tablesObj->get('tx_dam_cat', true)->getMarker(), - $damCat, - $damRow['pid'], - 0, - 'basketImage', - $viewDamCatTagArray, - [], - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'], - 'SINGLE', - 1, - '', - '' - ); - - $tablesObj->get('tx_dam', true)->getModelMarkerArray( - $damRow, - '', - $damMarkerArray, - $damCatRow['title'], - 0, - 'basketImage', - $damViewTagArray, - $tmp, - $theCode, - $basketExtra, - $basketRecs, - $count, - '', - '', - '', - $bHtml, - 'UTF-8', - '', - $multiOrderArray, - $productRowArray, - false, - $notOverwritePriceIfSet - ); - } - $markerArray = array_merge($markerArray, $damMarkerArray, $damCategoryMarkerArray); - - $tempUrl = - FrontendUtility::getTypoLink_URL( - $cObj, - $pid, - $this->urlObj->getLinkParams( - '', - $addQueryString, - true, - $useBackPid, - 0, - '' - ), - '', - [] - ); - - $css_current = ''; - $wrappedSubpartArray['###LINK_ITEM###'] = - [ - '', - '', - ]; - - if (is_object($itemTableView->getVariant())) { - $itemTableView->getVariant()->removeEmptyMarkerSubpartArray( - $markerArray, - $subpartArray, - $wrappedSubpartArray, - $prodVariantRow, - $conf, - $itemTable->hasAdditional($row, 'isSingle'), - !$itemTable->hasAdditional($row, 'noGiftService') + if (empty($itemOut)) { + $count--; + } else { + $basketItemViewApi->generateCategoryView( + $out, + $itemsOut, + $currentP, + $actItem, + $t['itemFrameWork'], + $t['categoryFrameWork'], + $calculatedArray, + $basketObj->getCategoryQuantity() ); + $itemsOut .= $itemOut; } - - $orderAddressViewObj->getModelObj()->setCondition($row, $funcTablename); - $orderAddressViewObj->getWrappedSubpartArray( - $viewTagArray, - $useBackPid, - $subpartArray, - $wrappedSubpartArray - ); - - // workaround for TYPO3 bug #44270 - $tempContent = $templateService->substituteMarkerArrayCached( - $t['item'], - [], - $subpartArray, - $wrappedSubpartArray - ); - - $tempContent = $templateService->substituteMarkerArray( - $tempContent, - $markerArray - ); - - $itemsOut .= $tempContent; } - if ($itemsOut) { $tempContent = - $templateService->substituteSubpart( - $t['itemFrameWork'], - '###ITEM_SINGLE###', - $itemsOut - ); + $templateService->substituteSubpart( + $t['itemFrameWork'], + '###ITEM_SINGLE###', + $itemsOut + ); $out .= $tempContent; $itemsOut = ''; // Clear the item-code var @@ -1257,133 +838,23 @@ public function getView( $taxInclExcl = (isset($taxFromShipping) && is_double($taxFromShipping) && $taxFromShipping == 0 ? 'tax_zero' : 'tax_included'); $markerArray['###TAX_INCL_EXCL###'] = ($taxInclExcl ? $languageObj->getLabel($taxInclExcl) : ''); - $pricefactor = tx_ttproducts_creditpoints_div::getPriceFactor($conf); - - // Added els6: do not execute the redeeming of the gift certificate if template = OVERVIEW - if ($subpartMarker != 'BASKET_OVERVIEW_TEMPLATE') { - // Added Franz: GIFT CERTIFICATE - $markerArray['###GIFT_CERTIFICATE_UNIQUE_NUMBER_NAME###'] = 'recs[tt_products][giftcode]'; // deprecated - $markerArray['###FORM_NAME###'] = 'BasketForm'; - $markerArray['###FORM_NAME_GIFT_CERTIFICATE###'] = 'BasketGiftForm'; - - // Added els5: markerarrays for gift certificates - // Added Els6: routine for redeeming the gift certificate (other way then proposed by Franz - $markerArray['###INSERT_GIFTCODE###'] = 'recs[tt_products][giftcode]'; - $markerArray['###VALUE_GIFTCODE###'] = htmlspecialchars($basketObj->recs['tt_products']['giftcode'] ?? ''); - $cpArray = tx_ttproducts_control_session::readSession('cp'); - - if ( - isset($cpArray['gift']) && - is_array($cpArray['gift']) && - isset($cpArray['gift']['amount']) - ) { - $creditpointsGifts = $cpArray['gift']['amount']; - } - $markerArray['###CREDITPOINTS_GIFTS###'] = htmlspecialchars($creditpointsGifts); - - if (empty($basketObj->recs['tt_products']['giftcode'])) { - $subpartArray['###SUB_GIFTCODE_DISCOUNT###'] = ''; - $subpartArray['###SUB_GIFTCODE_DISCOUNTWRONG###'] = ''; - if ($creditpointsGifts == '') { - $subpartArray['###SUB_GIFTCODE_DISCOUNT_true###'] = ''; - } - } else { - $uniqueId = GeneralUtility::trimExplode('-', $basketObj->recs['tt_products']['giftcode'], true); - $query = 'uid=\'' . intval($uniqueId[0]) . '\' AND crdate=\'' . intval($uniqueId[1]) . '\''; - $giftRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_products_gifts', $query); - $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($giftRes); - $GLOBALS['TYPO3_DB']->sql_free_result($giftRes); - $creditpointsDiscount = intval($creditpointsGifts) * $pricefactor; - $markerArray['###GIFT_DISCOUNT###'] = $creditpointsDiscount; - $markerArray['###VALUE_GIFTCODE_USED###'] = htmlspecialchars($basketObj->recs['tt_products']['giftcode'] ?? ''); - - if ($row && $creditpointsGifts && $pricefactor > 0) { - $subpartArray['###SUB_GIFTCODE_DISCOUNTWRONG###'] = ''; - if ($creditpointsGifts == '') { - $subpartArray['###SUB_GIFTCODE_DISCOUNT_true###'] = ''; - } - } else { - $markerArray['###VALUE_GIFTCODE_USED###'] = '**********'; - if (GeneralUtility::_GP('creditpoints_gifts') == '') { - $subpartArray['###SUB_GIFTCODE_DISCOUNT_true###'] = ''; - } - } - } - } - $amountCreditpoints = ( - CompatibilityUtility::isLoggedIn() - ? $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] : 0 - ) + intval($creditpointsGifts); - $markerArray['###AMOUNT_CREDITPOINTS###'] = $amountCreditpoints; - $autoCreditpointsTotal = (CompatibilityUtility::isLoggedIn() ? $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] : 0); - - $creditpoints = $autoCreditpointsTotal + $sum_pricecreditpoints_total_totunits * tx_ttproducts_creditpoints_div::getCreditPoints($sum_pricecreditpoints_total_totunits, $conf['creditpoints.'] ?? ''); - $markerArray['###AUTOCREDITPOINTS_TOTAL###'] = number_format($autoCreditpointsTotal, 0); - $markerArray['###AUTOCREDITPOINTS_PRICE_TOTAL_TAX###'] = $priceViewObj->priceFormat($autoCreditpointsTotal * $pricefactor); - $remainingCreditpoints = 0; - $creditpointsObj->getBasketMissingCreditpoints(0, $tmp, $remainingCreditpoints); - $markerArray['###AUTOCREDITPOINTS_REMAINING###'] = number_format($remainingCreditpoints, 0); - if (CompatibilityUtility::isLoggedIn()) { - $markerArray['###CREDITPOINTS_AVAILABLE###'] = number_format($GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'], 0); - } else { - $markerArray['###CREDITPOINTS_AVAILABLE###'] = 0; - } - $markerArray['###USERCREDITPOINTS_PRICE_TOTAL_TAX###'] = $priceViewObj->priceFormat(($autoCreditpointsTotal < $amountCreditpoints ? $autoCreditpointsTotal : $amountCreditpoints) * $pricefactor); - - // maximum1 amount of creditpoint to change is amount on account minus amount already spended in the credit-shop - $max1_creditpoints = (CompatibilityUtility::isLoggedIn() ? $GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] : 0) + intval($creditpointsGifts); - // maximum2 amount of creditpoint to change is amount bought multiplied with creditpointfactor - $max2_creditpoints = 0; + if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['creditpoints'])) { + $creditpointsViewApi = GeneralUtility::makeInstance( CreditpointsViewApi::class, $conf); + $amountCreditpoints = + tx_ttproducts_creditpoints_div::getCreditPointsFeuser($feUserRecord); - if ($pricefactor > 0) { - $max2_creditpoints = intval(($calculatedArray['priceTax']['total']['ALL'] - $calculatedArray['priceTax']['vouchertotal']['ALL']) / $pricefactor); - } - // real maximum amount of creditpoint to change is minimum of both maximums - $markerArray['###AMOUNT_CREDITPOINTS_MAX###'] = number_format(min($max1_creditpoints, $max2_creditpoints), 0); - - // if quantity is 0 than - if ($amountCreditpoints == '0') { - $subpartArray['###SUB_CREDITPOINTS_DISCOUNT###'] = ''; - $wrappedSubpartArray['###SUB_CREDITPOINTS_DISCOUNT_EMPTY###'] = ''; - $subpartArray['###SUB_CREDITPOINTS_AMOUNT_EMPTY###'] = ''; - $subpartArray['###SUB_CREDITPOINTS_AMOUNT###'] = ''; - } else { - $wrappedSubpartArray['###SUB_CREDITPOINTS_DISCOUNT###'] = ''; - $subpartArray['###SUB_CREDITPOINTS_DISCOUNT_EMPTY###'] = ''; - $wrappedSubpartArray['###SUB_CREDITPOINTS_AMOUNT_EMPTY###'] = ''; - $wrappedSubpartArray['###SUB_CREDITPOINTS_AMOUNT###'] = ''; - } - $markerArray['###CHANGE_AMOUNT_CREDITPOINTS###'] = 'recs[tt_products][creditpoints]'; - if (empty($basketObj->recs['tt_products']['creditpoints'])) { - $markerArray['###AMOUNT_CREDITPOINTS_QTY###'] = 0; - $subpartArray['###SUB_CREDITPOINTS_DISCOUNT###'] = ''; - // Added Els8: put credit_discount 0 for plain text email - $markerArray['###CREDIT_DISCOUNT###'] = '0.00'; - } else { - // quantity chosen can not be larger than the maximum amount, above calculated - if ($basketObj->recs['tt_products']['creditpoints'] > min($max1_creditpoints, $max2_creditpoints)) { - $basketObj->recs['tt_products']['creditpoints'] = min($max1_creditpoints, $max2_creditpoints); - } - $markerArray['###AMOUNT_CREDITPOINTS_QTY###'] = number_format($basketObj->recs['tt_products']['creditpoints'], 0); - $subpartArray['###SUB_CREDITPOINTS_DISCOUNT_EMPTY###'] = ''; - $markerArray['###CREDIT_DISCOUNT###'] = $priceViewObj->priceFormat($calculatedArray['priceTax']['creditpoints']); + $creditpointsViewApi->getItemMarkerSubpartArrays( + $itemArray, + $markerArray, + $subpartArray, + $wrappedSubpartArray, + $conf, + $priceViewObj, + $calculatedArray, + $amountCreditpoints + ); } - // Added els5: CREDITPOINTS_SPENDED: creditpoint needed, check if user has this amount of creditpoints on his account (winkelwagen.tmpl), only if user has logged in - $markerArray['###CREDITPOINTS_SPENDED###'] = $sum_pricecredits_total_totunits_no_tax; - if ($sum_pricecredits_total_totunits_no_tax <= $amountCreditpoints) { - $subpartArray['###SUB_CREDITPOINTS_SPENDED_EMPTY###'] = ''; - $markerArray['###CREDITPOINTS_SPENDED###'] = $sum_pricecredits_total_totunits_no_tax; - // new saldo: creditpoints - $markerArray['###AMOUNT_CREDITPOINTS###'] = $amountCreditpoints - $markerArray['###CREDITPOINTS_SPENDED###']; - } else { - if (!$markerArray['###FE_USER_UID###']) { - $subpartArray['###SUB_CREDITPOINTS_SPENDED_EMPTY###'] = ''; - } else { - $markerArray['###CREDITPOINTS_SPENDED_ERROR###'] = 'Wijzig de artikelen in de kurkenshop: onvoldoende kurken op uw saldo (' . $amountCreditpoints . ') . '; // TODO - $markerArray['###CREDITPOINTS_SPENDED###'] = ' '; - } - } foreach ($quantityArray as $k => $subQuantityArray) { switch ($k) { @@ -1439,7 +910,6 @@ public function getView( $voucherView->getMarkerArray($markerArray); } - $markerArray['###CREDITPOINTS_SAVED###'] = number_format($creditpoints, 0); $pidagb = intval($conf['PIDagb']); $addQueryString = []; @@ -1449,7 +919,7 @@ public function getView( $addQueryString['type'] = $GLOBALS['TSFE']->type; } - $pointerExcludeArray = array_keys(tx_ttproducts_model_control::getPointerParamsCodeArray()); + $pointerExcludeArray = array_keys($parameterApi->getPointerParamsCodeArray()); $singleExcludeList = $this->urlObj->getSingleExcludeList(implode(',', $pointerExcludeArray)); $tempUrl = FrontendUtility::getTypoLink_URL( @@ -1519,6 +989,7 @@ public function getView( $infoViewObj->getRowMarkerArray( $basketExtra, $markerArray, + $feUserRecord, $bHtml, $bSelectSalutation ); diff --git a/view/class.tx_ttproducts_basketitem_view.php b/view/class.tx_ttproducts_basketitem_view.php index c264dc9e8..8add62d42 100644 --- a/view/class.tx_ttproducts_basketitem_view.php +++ b/view/class.tx_ttproducts_basketitem_view.php @@ -44,6 +44,7 @@ use JambageCom\TtProducts\Api\BasketApi; use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; class tx_ttproducts_basketitem_view implements SingletonInterface @@ -56,8 +57,9 @@ public function getQuantityName( $parentRow, $callFunctableArray // deprecated parameter ) { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); - $basketVar = tx_ttproducts_model_control::getBasketVar(); + $basketVar = $parameterApi->getBasketVar(); $externalQuantity = ''; if ( @@ -70,14 +72,14 @@ public function getQuantityName( is_array($parentRow) && isset($parentRow['uid']) ) { - $piVar = tx_ttproducts_model_control::getPiVar($parentFuncTablename); + $piVar = $parameterApi->getPiVar($parentFuncTablename); if ($piVar !== false) { $externalQuantity = $piVar . '=' . intval($parentRow['uid']) . tx_ttproducts_variant_int::EXTERNAL_QUANTITY_SEPARATOR; } } - $piVar = tx_ttproducts_model_control::getPiVar($funcTablename); + $piVar = $parameterApi->getPiVar($funcTablename); if ($piVar !== false) { $externalQuantity = '[' . $externalQuantity . $piVar . '=' . intval($externalRow['uid']) . ']'; @@ -107,6 +109,7 @@ public function getItemMarkerSubpartArrays( &$wrappedSubpartArray ): void { $productFuncTablename = 'tt_products'; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); if (isset($productRowArray) && is_array($productRowArray)) { foreach ($productRowArray as $productRow) { @@ -143,7 +146,7 @@ public function getItemMarkerSubpartArrays( if (isset($tagArray['LINK_BASKET_' . $upperCmd])) { $addQueryString[$cmd] = $uid; - $basketVar = tx_ttproducts_model_control::getBasketParamVar(); + $basketVar = $parameterApi->getBasketParamVar(); if (isset($row['ext'])) { $extArray = $row['ext']; } @@ -219,9 +222,10 @@ public function getItemMarkerArray( $languageObj = GeneralUtility::makeInstance(Localization::class); $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $itemObj = GeneralUtility::makeInstance('tx_ttproducts_basketitem'); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $conf = $cnfObj->getConf(); - $basketVar = tx_ttproducts_model_control::getBasketVar(); + $basketVar = $parameterApi->getBasketVar(); $viewTableView = $tablesObj->get($productFuncTablename, true); $viewTable = $viewTableView->getModelObj(); $fieldArray = $viewTable->variant->getFieldArray(); @@ -380,8 +384,8 @@ public function getItemMarkerArray( $markerArray['###BASKET_ID###'] = $id; $markerArray['###BASKET_INPUT###'] = ''; - $markerArray['###BASKET_INTO_ID###'] = tx_ttproducts_model_control::getBasketIntoIdPrefix() . '-' . $row['uid']; - $markerArray['###BASKET_INPUT_ERROR_ID###'] = tx_ttproducts_model_control::getBasketInputErrorIdPrefix() . '-' . $row['uid']; + $markerArray['###BASKET_INTO_ID###'] = $parameterApi->getBasketIntoIdPrefix() . '-' . $row['uid']; + $markerArray['###BASKET_INPUT_ERROR_ID###'] = $parameterApi->getBasketInputErrorIdPrefix() . '-' . $row['uid']; $markerArray['###DISABLED###'] = ($bInputDisabled ? ($bUseXHTML ? 'disabled="disabled"' : 'disabled') : ''); @@ -510,7 +514,10 @@ public function getItemMarkerArray( $text = tx_ttproducts_form_div::createSelect( $languageObj, $prodTranslatedRow, - tx_ttproducts_control_basket::getTagName($row['uid'], $field), + $parameterApi->getTagName( + $row['uid'], + $field + ), $selectedKey, false, false, @@ -563,7 +570,7 @@ public function getItemMarkerArray( } $isImageProduct = $viewTable->hasAdditional($row, 'isImage'); - $damParam = tx_ttproducts_model_control::getPiVarValue('tx_dam'); + $damParam = $parameterApi->getPiVarValue('tx_dam'); if ( $funcTablename == 'tt_products' && @@ -577,7 +584,7 @@ public function getItemMarkerArray( $isImageProduct && isset($damParam) ) { - $damUid = tx_ttproducts_model_control::getPiVarValue('tx_dam'); + $damUid = $parameterApi->getPiVarValue('tx_dam'); } if (isset($damUid)) { diff --git a/view/class.tx_ttproducts_cat_view.php b/view/class.tx_ttproducts_cat_view.php index 6ee0a6a1b..8e7d0fd3b 100644 --- a/view/class.tx_ttproducts_cat_view.php +++ b/view/class.tx_ttproducts_cat_view.php @@ -44,6 +44,8 @@ use JambageCom\Div2007\Utility\FrontendUtility; use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\ParameterApi; +use JambageCom\TtProducts\Api\FeUserMarkerApi; class tx_ttproducts_cat_view implements SingletonInterface { @@ -80,6 +82,7 @@ public function printView( $funcTablename, $uid, $theCode, + $feUserRecord, &$error_code, $templateSuffix = '' ) { @@ -92,7 +95,8 @@ public function printView( $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $variantFieldArray = []; - $piVars = tx_ttproducts_model_control::getPiVars(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $piVars = $parameterApi->getPiVars(); $basketApi = GeneralUtility::makeInstance(BasketApi::class); $basketExtra = $basketApi->getBasketExtra(); @@ -143,13 +147,16 @@ public function printView( return ''; } - $viewTagArray = $markerObj->getAllMarkers($itemFrameWork); - $tablesObj->get('fe_users', true)->getWrappedSubpartArray( + $orderAddressObj = $tablesObj->get('fe_users', false); + $feUserMarkerApi = GeneralUtility::makeInstance(FeUserMarkerApi::class); + $feUserMarkerApi->getWrappedSubpartArray( + $orderAddressObj, $viewTagArray, - $useBackPid, + $feUserRecord, $subpartArray, $wrappedSubpartArray ); + $feUserMarkerApi->getGlobalMarkerArray($markerArray, $feUserRecord); $itemFrameWork = $templateService->substituteMarkerArrayCached($itemFrameWork, $markerArray, $subpartArray, $wrappedSubpartArray); $markerFieldArray = []; diff --git a/view/class.tx_ttproducts_catlist_view.php b/view/class.tx_ttproducts_catlist_view.php index f57ebe2ae..610e6b737 100644 --- a/view/class.tx_ttproducts_catlist_view.php +++ b/view/class.tx_ttproducts_catlist_view.php @@ -40,6 +40,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\ParameterApi; class tx_ttproducts_catlist_view extends tx_ttproducts_catlist_view_base @@ -62,6 +63,7 @@ public function getChildsContent( $subCategoryMarkerArray ) { $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $basketApi = GeneralUtility::makeInstance(BasketApi::class); $basketExtra = $basketApi->getBasketExtra(); @@ -82,7 +84,7 @@ public function getChildsContent( $childEnd = $childEndMax = count($childArray) - 1; if ($ctrlArray['bUseBrowser'] && !empty($ctrlArray['limit'])) { - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $childStart = ($piVars['pointer'] ?? 0) * $ctrlArray['limit']; $childEnd = $childStart + $ctrlArray['limit'] - 1; @@ -532,9 +534,10 @@ public function getMarkerArray( $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); $conf = $cnfObj->getConf(); $config = $cnfObj->getConfig(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $css = 'class="w' . $iCount . '"'; $css = ($actCategory == $currentCat ? 'class="act"' : $css); - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $prefixId = $parameterApi->getPrefixId(); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $pageObj = $tablesObj->get('pages'); diff --git a/view/class.tx_ttproducts_catlist_view_base.php b/view/class.tx_ttproducts_catlist_view_base.php index 433b78bd9..0ae40d64b 100644 --- a/view/class.tx_ttproducts_catlist_view_base.php +++ b/view/class.tx_ttproducts_catlist_view_base.php @@ -36,14 +36,16 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Base\BrowserBase; -use JambageCom\TtProducts\Api\Localization; -use JambageCom\TtProducts\Api\ParameterApi; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; +use JambageCom\Div2007\Base\BrowserBase; + +use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; + abstract class tx_ttproducts_catlist_view_base implements SingletonInterface { public $pibaseClass; @@ -267,7 +269,7 @@ public function getBrowserMarkerArray( $pibaseObj = GeneralUtility::makeInstance('' . $this->pibaseClass); $languageObj = GeneralUtility::makeInstance(Localization::class); $tableConfArray = $this->getTableConfArray(); - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $browserConf = []; if ( isset($tableConfArray['view.']) && $tableConfArray['view.']['browser'] == 'div2007' && isset($tableConfArray['view.']['browser.']) @@ -343,13 +345,14 @@ protected function getPrintViewArrays( ) { $pibaseObj = GeneralUtility::makeInstance('' . $this->pibaseClass); $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $rc = true; $mode = ''; $allowedCats = ''; $this->getFrameWork($t, $templateCode, $templateArea . $templateSuffix); $checkExpression = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['templateCheck']; - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); if (!empty($checkExpression)) { $wrongPounds = preg_match_all($checkExpression, $t['listFrameWork'], $matches); @@ -370,8 +373,8 @@ protected function getPrintViewArrays( $functableArray = [$funcTablename]; $tableConfArray = []; $viewConfArray = []; - $searchVars = $piVars[tx_ttproducts_model_control::getSearchboxVar()] ?? ''; - tx_ttproducts_model_control::getTableConfArrays( + $searchVars = $piVars[$parameterApi->getSearchboxVar()] ?? ''; + $parameterApi->getTableConfArrays( $pibaseObj->getContentObjectRenderer(), $functableArray, $theCode, @@ -395,7 +398,7 @@ protected function getPrintViewArrays( $sqlTableIndex = 0; $latest = ''; if (!empty($searchVars)) { - tx_ttproducts_model_control::getSearchInfo( + $parameterApi->getSearchInfo( $this->cObj, $searchVars, $funcTablename, @@ -443,7 +446,7 @@ protected function getPrintViewArrays( $tmp = $templateService->substituteMarkerArrayCached($t['categoryFrameWork'], [], $subpartArray); $htmlParts = GeneralUtility::trimExplode('###CATEGORY_TMP###', $tmp); $rootCat = $categoryTable->getRootCat() ?? ''; - $currentCat = $categoryTable->getParamDefault($theCode, $piVars[tx_ttproducts_model_control::getPiVar($funcTablename)] ?? ''); + $currentCat = $categoryTable->getParamDefault($theCode, $piVars[$parameterApi->getPiVar($funcTablename)] ?? ''); $startCat = $currentCat; if (strpos($theCode, 'SELECT') !== false) { @@ -472,7 +475,7 @@ protected function getPrintViewArrays( foreach ($tableConf['filter.']['where.']['field.'] as $field => $value) { if (trim($value) != '') { $where_clause = - tx_ttproducts_model_control::getWhereByFields( + $parameterApi->getWhereByFields( $tablename, $alias, '', diff --git a/view/class.tx_ttproducts_control_view.php b/view/class.tx_ttproducts_control_view.php index 157e65a23..a102f8fd9 100644 --- a/view/class.tx_ttproducts_control_view.php +++ b/view/class.tx_ttproducts_control_view.php @@ -36,9 +36,11 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\TtProducts\Api\Localization; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_control_view { /** @@ -56,8 +58,9 @@ public function getMarkerArray(&$markerArray, &$allMarkers, $tableConfArray): vo { if (isset($tableConfArray) && is_array($tableConfArray)) { $languageObj = GeneralUtility::makeInstance(Localization::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $allValueArray = []; - $controlArray = tx_ttproducts_model_control::getControlArray(); + $controlArray = $parameterApi->getControlArray(); $separator = ';'; foreach ($tableConfArray as $funcTablename => $tableConf) { @@ -88,7 +91,7 @@ public function getMarkerArray(&$markerArray, &$allMarkers, $tableConfArray): vo $out = tx_ttproducts_form_div::createSelect( $languageObj, $valueArray, - tx_ttproducts_model_control::getPrefixId() . '[' . tx_ttproducts_model_control::getControlVar() . '][' . $keyArray[0] . '][' . $keyArray[1] . ']', + $parameterApi->getPrefixId() . '[' . $parameterApi->getControlVar() . '][' . $keyArray[0] . '][' . $keyArray[1] . ']', $controlArray[$keyArray[0]][$keyArray[1]], true, true, @@ -100,7 +103,7 @@ public function getMarkerArray(&$markerArray, &$allMarkers, $tableConfArray): vo } elseif ($type == 'filterInput') { $out = tx_ttproducts_form_div::createTag( 'input', - tx_ttproducts_model_control::getPrefixId() . '[' . tx_ttproducts_model_control::getControlVar() . '][' . $keyArray[0] . '][' . $keyArray[1] . ']', + $parameterApi->getPrefixId() . '[' . $parameterApi->getControlVar() . '][' . $keyArray[0] . '][' . $keyArray[1] . ']', $controlArray[$keyArray[0]][$keyArray[1]], $attributeArray ); diff --git a/view/class.tx_ttproducts_download_view.php b/view/class.tx_ttproducts_download_view.php index 3240bce26..fe73e9851 100644 --- a/view/class.tx_ttproducts_download_view.php +++ b/view/class.tx_ttproducts_download_view.php @@ -36,14 +36,17 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\FrontendUtility; -use JambageCom\TtProducts\Api\Localization; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; +use JambageCom\Div2007\Utility\FrontendUtility; + +use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_download_view extends tx_ttproducts_article_base_view { public $marker = 'DOWNLOAD'; @@ -84,6 +87,7 @@ public function getDownloadMarkerSubpartArrays( $cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer'); $cObj->start([]); $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $funcTablename = 'tt_products'; $itemTableView = $tablesObj->get($funcTablename, true); @@ -105,7 +109,7 @@ public function getDownloadMarkerSubpartArrays( $languageObj = GeneralUtility::makeInstance(Localization::class); $postVar = tx_ttproducts_control_command::getCommandVar(); - $downloadVar = tx_ttproducts_model_control::getPiVar($this->getModelObj()->getFuncTablename()); + $downloadVar = $parameterApi->getPiVar($this->getModelObj()->getFuncTablename()); $bAddonsEM = ExtensionManagementUtility::isLoaded('addons_em'); tx_ttproducts_control_access::getVariables( $conf, @@ -151,11 +155,11 @@ public function getDownloadMarkerSubpartArrays( $markerSelect = $marker . '_SELECT'; if (is_array($selectValueArray) && count($selectValueArray) && isset($selectValueArray['edit_domain'])) { - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $domainVar = 'domain'; $piVar = $domainVar; - $tagName = tx_ttproducts_model_control::getPrefixId() . '[' . $piVar . '][' . $productUid . '][' . $row['uid'] . ']'; + $tagName = $parameterApi->getPrefixId() . '[' . $piVar . '][' . $productUid . '][' . $row['uid'] . ']'; if ( isset($piVars[$piVar]) && @@ -214,7 +218,7 @@ public function getDownloadMarkerSubpartArrays( $paramArray['tracking'] = $trackingCode; } - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $prefixId = $parameterApi->getPrefixId(); $paramArray[$prefixId . '[' . $downloadVar . ']'] = $row['uid']; if ($selectedDomain != '') { @@ -268,7 +272,7 @@ public function getDownloadMarkerSubpartArrays( } } - $orderPivar = tx_ttproducts_model_control::getPiVar('sys_products_orders'); + $orderPivar = $parameterApi->getPiVar('sys_products_orders'); if ($orderUid) { $paramArray[$prefixId . '[' . $orderPivar . ']'] = $orderUid; diff --git a/view/class.tx_ttproducts_edit_variant_view.php b/view/class.tx_ttproducts_edit_variant_view.php index ba36a79f2..a74b24d29 100644 --- a/view/class.tx_ttproducts_edit_variant_view.php +++ b/view/class.tx_ttproducts_edit_variant_view.php @@ -41,6 +41,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_edit_variant_view implements tx_ttproducts_edit_variant_view_int, SingletonInterface { protected $modelObj; @@ -63,6 +65,7 @@ public function getMarkerArray( $config, &$markerArray ): void { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); if (isset($config) && is_array($config)) { $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $itemTableView = $tablesObj->get($funcTablename, true); @@ -86,7 +89,7 @@ public function getMarkerArray( } if ($bEditable) { - $basketExtRaw = tx_ttproducts_control_basket::getBasketExtRaw(); + $basketExtRaw = $parameterApi->getBasketExtRaw(); if (isset($basketExtRaw) && is_array($basketExtRaw)) { if (isset($basketExtRaw[$uid]) && is_array($basketExtRaw[$uid])) { $value = $basketExtRaw[$uid][$field]; diff --git a/view/class.tx_ttproducts_fal_view.php b/view/class.tx_ttproducts_fal_view.php index c1d609828..cdc5fc4a7 100644 --- a/view/class.tx_ttproducts_fal_view.php +++ b/view/class.tx_ttproducts_fal_view.php @@ -36,7 +36,6 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\FrontendUtility; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Resource\StorageRepository; @@ -44,6 +43,11 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; +use JambageCom\Div2007\Utility\FrontendUtility; + +use JambageCom\TtProducts\Api\ParameterApi; + + class tx_ttproducts_fal_view extends tx_ttproducts_article_base_view { public $marker = 'FAL'; @@ -112,6 +116,7 @@ public function getModelMarkerArray( $productRowArray = [], $bEnableTaxZero = false ): void { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); parent::getModelMarkerArray( $row, $markerParam, @@ -143,9 +148,9 @@ public function getModelMarkerArray( $cObj->start([]); $paramArray = []; $postVar = tx_ttproducts_control_command::getCommandVar(); - $orderPivar = tx_ttproducts_model_control::getPiVar('sys_products_orders'); - $prefixId = tx_ttproducts_model_control::getPrefixId(); - $downloadVar = tx_ttproducts_model_control::getPiVar('tt_products_downloads'); + $orderPivar = $parameterApi->getPiVar('sys_products_orders'); + $prefixId = $parameterApi->getPrefixId(); + $downloadVar = $parameterApi->getPiVar('tt_products_downloads'); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $orderObj = $tablesObj->get('sys_products_orders'); diff --git a/view/class.tx_ttproducts_info_view.php b/view/class.tx_ttproducts_info_view.php index d6c03b034..ab24d4f58 100644 --- a/view/class.tx_ttproducts_info_view.php +++ b/view/class.tx_ttproducts_info_view.php @@ -51,15 +51,13 @@ use JambageCom\TtProducts\Api\ControlApi; use JambageCom\TtProducts\Api\CustomerApi; use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; use JambageCom\TtProducts\Api\PaymentShippingHandling; class tx_ttproducts_info_view implements SingletonInterface { public $conf; public $config; - public $infoArray; // elements: 'billing' and 'delivery' addresses - // contains former basket $personInfo and $deliveryInfo - public $country; // object of the type tx_table_db public $password; // automatically generated random password for a new frontend user public $bHasBeenInitialised = false; @@ -71,13 +69,6 @@ public function init( { $result = true; $this->modelObj = $modelObj; - $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); - - $this->conf = $cnf->getConf(); - $this->config = $cnf->getConfig(); - - $this->infoArray = tx_ttproducts_control_basket::getInfoArray(); - $this->bHasBeenInitialised = true; return $result; @@ -178,22 +169,25 @@ public function getSubpartMarkerArray( public function getRowMarkerArray( $basketExtra, &$markerArray, + $feUserRecord, $bHtml, $bSelectSalutation ): void { + $infoArray = $this->getInfoArray(); $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); $cnf = GeneralUtility::makeInstance('tx_ttproducts_config'); $conf = $cnf->getConf(); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $languageObj = GeneralUtility::makeInstance(Localization::class); $context = GeneralUtility::makeInstance(Context::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $fields = CustomerApi::getFields(); $infoFields = GeneralUtility::trimExplode(',', $fields); // Fields... $orderAddressViewObj = $tablesObj->get('fe_users', true); $orderAddressObj = $orderAddressViewObj->getModelObj(); $selectInfoFields = $orderAddressObj->getSelectInfoFields(); - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); if (version_compare(PHP_VERSION, '8.0.0') >= 0) { $staticInfoApi = GeneralUtility::makeInstance(StaticInfoTablesApi::class); } else { @@ -205,53 +199,40 @@ public function getRowMarkerArray( $fieldMarker = strtoupper($fName); if ($bHtml) { $markerArray['###PERSON_' . $fieldMarker . '###'] = - htmlspecialchars($this->infoArray['billing'][$fName] ?? ''); + htmlspecialchars($infoArray['billing'][$fName] ?? ''); $markerArray['###DELIVERY_' . $fieldMarker . '###'] = - htmlspecialchars($this->infoArray['delivery'][$fName] ?? ''); + htmlspecialchars($infoArray['delivery'][$fName] ?? ''); } else { $markerArray['###PERSON_' . $fieldMarker . '###'] = - $this->infoArray['billing'][$fName] ?? ''; + $infoArray['billing'][$fName] ?? ''; $markerArray['###DELIVERY_' . $fieldMarker . '###'] = - $this->infoArray['delivery'][$fName] ?? ''; + $infoArray['delivery'][$fName] ?? ''; } } } - if (!empty($this->conf['useStaticInfoCountry']) && $staticInfoApi->isActive()) { + if (!empty($conf['useStaticInfoCountry']) && $staticInfoApi->isActive()) { $countryViewObj = $tablesObj->get('static_countries', true); $countryObj = $countryViewObj->getModelObj(); $bReady = false; $whereCountries = $this->getModelObj()->getWhereAllowedCountries($basketExtra); $countryCodeArray = []; - $countryCodeArray['billing'] = ($this->infoArray['billing']['country_code'] ?? $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($GLOBALS['TSFE']->fe_user->user['static_info_country']) ? $GLOBALS['TSFE']->fe_user->user['static_info_country'] : false)); - $countryCodeArray['delivery'] = ($this->infoArray['delivery']['country_code'] ?? ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($GLOBALS['TSFE']->fe_user->user['static_info_country']) ? $GLOBALS['TSFE']->fe_user->user['static_info_country'] : false)); + $countryCodeArray['billing'] = ($infoArray['billing']['country_code'] ?? ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($feUserRecord['static_info_country']) ? $feUserRecord['static_info_country'] : false)); + + $countryCodeArray['delivery'] = ($infoArray['delivery']['country_code'] ?? ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($feUserRecord['static_info_country']) ? $feUserRecord['static_info_country'] : false)); $zoneCodeArray = []; - $zoneCodeArray['billing'] = ( - !empty($this->infoArray['billing']['zone']) ? - $this->infoArray['billing']['zone'] : ( - $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($GLOBALS['TSFE']->fe_user->user['zone']) ? - $GLOBALS['TSFE']->fe_user->user['zone'] : - false - ) - ); - $zoneCodeArray['delivery'] = ( - !empty($this->infoArray['delivery']['zone']) ? - $this->infoArray['delivery']['zone'] : ( - $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($GLOBALS['TSFE']->fe_user->user['zone']) ? - $GLOBALS['TSFE']->fe_user->user['zone'] : - false - ) - ); + $zoneCodeArray['billing'] = (!empty($infoArray['billing']['zone']) ? $infoArray['billing']['zone'] : ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($feUserRecord['zone']) ? $feUserRecord['zone'] : false)); + $zoneCodeArray['delivery'] = (!empty($infoArray['delivery']['zone']) ? $infoArray['delivery']['zone'] : ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn') && !empty($feUserRecord['zone']) ? $feUserRecord['zone'] : false)); if ( $countryCodeArray['billing'] === false && - !empty($this->infoArray['billing']['country']) && - !empty($this->infoArray['delivery']['country']) + !empty($infoArray['billing']['country']) && + !empty($infoArray['delivery']['country']) ) { // nothing to do - $bReady = true; + $isReady = true; } elseif ( ExtensionManagementUtility::isLoaded('static_info_tables') ) { @@ -266,7 +247,7 @@ public function getRowMarkerArray( '', $countryCodeArray['billing'], '', - $this->conf['onChangeCountryAttribute'], + $conf['onChangeCountryAttribute'], 'field_personinfo_country_code', '', $whereCountries, @@ -312,7 +293,7 @@ public function getRowMarkerArray( '', $countryCodeArray['delivery'], '', - $this->conf['onChangeCountryAttribute'], + $conf['onChangeCountryAttribute'], 'field_delivery_country_code', '', $whereCountries, @@ -422,7 +403,7 @@ public function getRowMarkerArray( $orderAddressViewObj->getAddressMarkerArray( 'fe_users', - $this->infoArray['billing'], + $infoArray['billing'], $markerArray, $bSelectSalutation, 'personinfo' @@ -430,26 +411,26 @@ public function getRowMarkerArray( $orderAddressViewObj->getAddressMarkerArray( 'fe_users', - $this->infoArray['delivery'], + $infoArray['delivery'], $markerArray, $bSelectSalutation, 'delivery' ); - $text = $this->infoArray['delivery']['note'] ?? ''; + $text = $infoArray['delivery']['note'] ?? ''; $markerArray['###DELIVERY_NOTE###'] = $text; $markerArray['###DELIVERY_NOTE_DISPLAY###'] = nl2br($text); - $markerArray['###DELIVERY_GIFT_SERVICE###'] = $this->infoArray['delivery']['giftservice'] ?? ''; - $markerArray['###DELIVERY_GIFT_SERVICE_DISPLAY###'] = nl2br($this->infoArray['delivery']['giftservice'] ?? ''); - if (isset($this->infoArray['delivery']['radio1'])) { - $markerArray['###DELIVERY_RADIO1_1###'] = ($this->infoArray['delivery']['radio1'] == '1' ? 'checked ' : ''); - $markerArray['###DELIVERY_RADIO1_2###'] = ($this->infoArray['delivery']['radio1'] == '2' ? 'checked ' : ''); - $markerArray['###DELIVERY_RADIO1_DISPLAY###'] = $this->infoArray['delivery']['radio1']; + $markerArray['###DELIVERY_GIFT_SERVICE###'] = $infoArray['delivery']['giftservice'] ?? ''; + $markerArray['###DELIVERY_GIFT_SERVICE_DISPLAY###'] = nl2br($infoArray['delivery']['giftservice'] ?? ''); + if (isset($infoArray['delivery']['radio1'])) { + $markerArray['###DELIVERY_RADIO1_1###'] = ($infoArray['delivery']['radio1'] == '1' ? 'checked ' : ''); + $markerArray['###DELIVERY_RADIO1_2###'] = ($infoArray['delivery']['radio1'] == '2' ? 'checked ' : ''); + $markerArray['###DELIVERY_RADIO1_DISPLAY###'] = $infoArray['delivery']['radio1']; } // Desired delivery date. - $markerArray['###DELIVERY_DESIRED_DATE###'] = $this->infoArray['delivery']['desired_date'] ?? ''; - $markerArray['###DELIVERY_DESIRED_TIME###'] = $this->infoArray['delivery']['desired_time'] ?? ''; + $markerArray['###DELIVERY_DESIRED_DATE###'] = $infoArray['delivery']['desired_date'] ?? ''; + $markerArray['###DELIVERY_DESIRED_TIME###'] = $infoArray['delivery']['desired_time'] ?? ''; $markerArray['###DELIVERY_STORE_SELECT###'] = ''; $shippingType = PaymentShippingHandling::get( @@ -477,8 +458,8 @@ public function getRowMarkerArray( $orderBy = $tableconf['orderBy']; $uidStoreArray = []; - if (isset($this->conf['UIDstore'])) { - $tmpArray = GeneralUtility::trimExplode(',', $this->conf['UIDstore']); + if (isset($conf['UIDstore'])) { + $tmpArray = GeneralUtility::trimExplode(',', $conf['UIDstore']); foreach ($tmpArray as $value) { if ($value) { $uidStoreArray[] = $value; @@ -487,7 +468,7 @@ public function getRowMarkerArray( } $where_clause = ''; - if ($tablename == 'fe_users' && !empty($this->conf['UIDstoreGroup'])) { + if ($tablename == 'fe_users' && !empty($conf['UIDstoreGroup'])) { $orChecks = []; $memberGroups = GeneralUtility::trimExplode(',', $this->conf['UIDstoreGroup']); foreach ($memberGroups as $value) { @@ -518,7 +499,7 @@ public function getRowMarkerArray( '' ); - $actUidStore = $this->infoArray['delivery']['store']; + $actUidStore = $infoArray['delivery']['store']; $tableFieldArray = [ 'tx_party_addresses' => ['post_code', 'locality', 'remarks'], 'tt_address' => ['zip', 'city', 'name', 'address'], @@ -577,10 +558,10 @@ public function getRowMarkerArray( $markerArray['###FE_USER_TT_PRODUCTS_DISCOUNT###'] = $GLOBALS['TSFE']->fe_user->user['tt_products_discount'] ?? ''; $markerArray['###FE_USER_USERNAME###'] = $GLOBALS['TSFE']->fe_user->user['username'] ?? ''; $markerArray['###FE_USER_UID###'] = $GLOBALS['TSFE']->fe_user->user['uid'] ?? ''; - $bAgb = (isset($this->infoArray['billing']['agb']) && $this->infoArray['billing']['agb'] && (!isset($piVars['agb']) || $piVars['agb'] > 0)); + $bAgb = (isset($infoArray['billing']['agb']) && $infoArray['billing']['agb'] && (!isset($piVars['agb']) || $piVars['agb'] > 0)); $markerArray['###FE_USER_CNUM###'] = $GLOBALS['TSFE']->fe_user->user['cnum'] ?? ''; $markerArray['###PERSON_AGB###'] = 'value="1" ' . ($bAgb ? 'checked="checked"' : ''); - $markerArray['###USERNAME###'] = $this->infoArray['billing']['email'] ?? ''; + $markerArray['###USERNAME###'] = $infoArray['billing']['email'] ?? ''; $markerArray['###PASSWORD###'] = $this->password; $valueArray = $GLOBALS['TCA']['sys_products_orders']['columns']['foundby']['config']['items']; @@ -603,14 +584,14 @@ public function getRowMarkerArray( $languageObj, $valueArray, 'recs[delivery][foundby]', - $this->infoArray['delivery']['foundby'] ?? '', + $infoArray['delivery']['foundby'] ?? '', true, true, [], $foundbyType ); - $foundbyKey = $this->infoArray['delivery']['foundby'] ?? ''; + $foundbyKey = $infoArray['delivery']['foundby'] ?? ''; if (isset($valueArray[$foundbyKey])) { $tmp = $languageObj->splitLabel($valueArray[$foundbyKey][0]); $text = $languageObj->getLabel($tmp); @@ -619,6 +600,6 @@ public function getRowMarkerArray( $markerArray['###DELIVERY_FOUNDBY###'] = $text; $markerArray['###DELIVERY_FOUNDBY_KEY###'] = $foundbyKey; $markerArray['###DELIVERY_FOUNDBY_SELECTOR###'] = $foundbyText; - $markerArray['###DELIVERY_FOUNDBY_OTHERS###'] = $this->infoArray['delivery']['foundby_others'] ?? ''; + $markerArray['###DELIVERY_FOUNDBY_OTHERS###'] = $infoArray['delivery']['foundby_others'] ?? ''; } // getMarkerArray } diff --git a/view/class.tx_ttproducts_list_view.php b/view/class.tx_ttproducts_list_view.php index eb0df21cc..16dc45b37 100644 --- a/view/class.tx_ttproducts_list_view.php +++ b/view/class.tx_ttproducts_list_view.php @@ -40,29 +40,34 @@ use Psr\EventDispatcher\EventDispatcherInterface; +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; -use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; + use JambageCom\Div2007\Base\BrowserBase; -use JambageCom\Div2007\Utility\BrowserUtility; -use JambageCom\Div2007\Utility\CompatibilityUtility; use JambageCom\Div2007\Utility\FlexformUtility; -use JambageCom\Div2007\Utility\FrontendUtility; +use JambageCom\Div2007\Utility\MarkerUtility; use JambageCom\Div2007\Utility\TableUtility; +use JambageCom\Div2007\Utility\BrowserUtility; +use JambageCom\Div2007\Utility\FrontendUtility; use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\ControlApi; +use JambageCom\TtProducts\Api\FeUserMarkerApi; use JambageCom\TtProducts\Api\Localization; use JambageCom\TtProducts\Api\ParameterApi; use JambageCom\TtProducts\Api\PluginApi; +use JambageCom\TtProducts\Api\VariantApi; use JambageCom\TtProducts\Model\Field\FieldInterface; +use JambageCom\TtProducts\View\RelatedList; -class tx_ttproducts_list_view implements SingletonInterface +class tx_ttproducts_list_view { public $pid; // pid where to go public $uidArray; @@ -164,6 +169,7 @@ public function advanceProduct( */ public function getSearchParams(&$queryString): void { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $sword = GeneralUtility::_GP('sword'); if (!isset($sword)) { @@ -175,7 +181,7 @@ public function getSearchParams(&$queryString): void } if (!isset($sword)) { - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $sword = $piVars['sword'] ?? null; } @@ -436,8 +442,9 @@ public function printView( &$error_code, $templateArea, // 'ITEM_LIST_TEMPLATE', $pageAsCategory, - $basketExtra, - $basketRecs, + $feUserRecord = [], + $basketExtra = [], + $basketRecs = [], $mergeRow = [], $calllevel = 0, $callFunctableArray = [], @@ -463,6 +470,11 @@ public function printView( $languageObj = GeneralUtility::makeInstance(Localization::class); $backPid = 0; $templateObj = GeneralUtility::makeInstance('tx_ttproducts_template'); + $variantApi = null; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + if ($funcTablename == 'tt_products') { + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + } $whereCat = ''; $whereProduct = ''; @@ -470,7 +482,7 @@ public function printView( $viewedCodeArray = ['LISTAFFORDABLE', 'LISTVIEWEDITEMS', 'LISTVIEWEDMOST', 'LISTVIEWEDMOSTOTHERS']; $bUseCache = true; - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $prefixId = $parameterApi->getPrefixId(); $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); @@ -494,10 +506,10 @@ public function printView( } $eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class); - $relatedListView = GeneralUtility::makeInstance('tx_ttproducts_relatedlist_view', $eventDispatcher); + $relatedListView = GeneralUtility::makeInstance(RelatedList::class, $eventDispatcher); $relatedListView->init($this->pidListObj->getPidlist(), 0); - $piVars = tx_ttproducts_model_control::getPiVars(); + $piVars = $parameterApi->getPiVars(); $showArticles = false; $globalMarkerArray = $markerObj->getGlobalMarkerArray(); @@ -616,7 +628,7 @@ public function printView( $tableConfArray = []; $viewConfArray = []; $functableArray = [$funcTablename, $categoryFuncTablename]; - tx_ttproducts_model_control::getTableConfArrays( + $parameterApi->getTableConfArrays( $cObj, $functableArray, $theCode, @@ -633,7 +645,7 @@ public function printView( $useArticles = $cnfObj->getUseArticles(); $excludeList = ''; - $pointerParam = tx_ttproducts_model_control::getPointerPiVar('LIST'); + $pointerParam = $parameterApi->getPointerPiVar('LIST'); if ( $itemTable->getType() == 'product' && @@ -678,7 +690,7 @@ public function printView( } $cssConf = $cnfObj->getCSSConf($itemTable->getFuncTablename(), $theCode); - $categoryPivar = tx_ttproducts_model_control::getPiVar($categoryFuncTablename); + $categoryPivar = $parameterApi->getPiVar($categoryFuncTablename); if ($useCategories) { $categoryTableView = $tablesObj->get($categoryFuncTablename, true); @@ -686,11 +698,11 @@ public function printView( $tableConfArray[$categoryFuncTablename] = $categoryTable->getTableConf($theCode); $catTableConf = $categoryTable->getTableConf($theCode); $categoryTable->initCodeConf($theCode, $catTableConf); - $categoryAnd = tx_ttproducts_model_control::getAndVar($categoryPivar); + $categoryAnd = $parameterApi->getAndVar($categoryPivar); } $whereArray = ''; - if (!empty($piVars[tx_ttproducts_model_control::getPiVar($funcTablename)])) { - $whereArray = $piVars[tx_ttproducts_model_control::getPiVar($funcTablename)]; + if (!empty($piVars[$parameterApi->getPiVar($funcTablename)])) { + $whereArray = $piVars[$parameterApi->getPiVar($funcTablename)]; } if (is_array($whereArray)) { @@ -776,8 +788,8 @@ public function printView( } $searchboxWhere = ''; $searchVars = []; - if (isset($piVars[tx_ttproducts_model_control::getSearchboxVar()])) { - $searchVars = $piVars[tx_ttproducts_model_control::getSearchboxVar()]; + if (isset($piVars[$parameterApi->getSearchboxVar()])) { + $searchVars = $piVars[$parameterApi->getSearchboxVar()]; } $bUseSearchboxArray = []; $latest = ''; @@ -789,7 +801,7 @@ public function printView( isset($searchVars['uid']) ) ) { - tx_ttproducts_model_control::getSearchInfo( + $parameterApi->getSearchInfo( $cObj, $searchVars, $funcTablename, @@ -1201,14 +1213,19 @@ public function printView( $useBackPid ); $subpartArray = []; - $viewTagArray = $markerObj->getAllMarkers($t['listFrameWork']); - $tablesObj->get('fe_users', true)->getWrappedSubpartArray( + $viewTagArray = MarkerUtility::getTags($t['listFrameWork']); + $orderAddressObj = $tablesObj->get('fe_users', false); + $feUserMarkerApi = GeneralUtility::makeInstance(FeUserMarkerApi::class); + $feUserMarkerApi->getWrappedSubpartArray( + $orderAddressObj, $viewTagArray, - $useBackPid, + $feUserRecord, $subpartArray, $wrappedSubpartArray ); + $feUserMarkerApi->getGlobalMarkerArray($markerArray, $feUserRecord); + if (is_array($viewConfArray) && count($viewConfArray)) { $controlViewObj = GeneralUtility::makeInstance('tx_ttproducts_control_view'); $controlViewObj->getMarkerArray( @@ -1585,8 +1602,8 @@ public function printView( } if (in_array($theCode, $viewedCodeArray) && $limit > 0) { - if (CompatibilityUtility::isLoggedIn()) { - $feUserId = intval($GLOBALS['TSFE']->fe_user->user['uid']); + if ($context->getPropertyFromAspect('frontend.user', 'isLoggedIn')) { + $feUserId = intval($feUserRecord['uid']); } $whereMM = ''; $productAlias = $itemTable->getAlias(); @@ -1596,7 +1613,7 @@ public function printView( case 'LISTAFFORDABLE': if ($feUserId) { $whereProducts = ' AND ' . $productAlias . '.creditpoints<=' . - $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'], $tablename); + $GLOBALS['TYPO3_DB']->fullQuoteStr($feUserRecord['tt_products_creditpoints'], $tablename); } break; case 'LISTVIEWEDITEMS': @@ -2223,22 +2240,27 @@ public function printView( // fetch new product if articles are listed $prodRow = $tablesObj->get('tt_products')->get($row['uid_product']); + $taxInfoArray = []; $item = $basketObj->getItem( - $basketExt, + $mergePrices = true, + $basketApi->getBasketExt(), $basketExtra, $basketRecs, $prodRow, - 'firstVariant' + 'firstVariant', + $taxInfoArray ); + $tax = $item['tax']; $itemTableViewArray['product']->getModelMarkerArray( $prodRow, $itemTableViewArray['product']->getMarker(), $productMarkerArray, + is_object($variantApi) ? $variantApi->getFieldArray() : [], $catTitle, + $viewProductsTagArray, $config['limitImage'], 'listImage', - $viewProductsTagArray, [], $theCode, $basketExtra, @@ -2290,6 +2312,7 @@ public function printView( false, true ); + $currentArray['product'] = $row['uid_product'] ?? 0; } else { $currentArray['product'] = $row['uid']; @@ -2456,16 +2479,20 @@ public function printView( } $markerArray = []; + $taxInfoArray = []; $item = $basketObj->getItem( - $basketExt, + $mergePrices = true, + $basketApi->getBasketExt(), $basketExtra, $basketRecs, - $prodRow, + $prodRow, // $row neu 'firstVariant', + $taxInfoArray, // neu $itemTable->getFuncTablename(), - $externalRowArray, - $theCode == 'LISTGIFTS' + $externalRowArray, // neu + false ); + $tax = $item['tax']; if (!empty($item)) { $prodRow = $item['rec']; @@ -2549,6 +2576,7 @@ public function printView( $allVariants, $useArticles, $itemTable->getFuncTablename(), + $basketExt, false ); } else { @@ -2557,19 +2585,31 @@ public function printView( $basketExt1 = tx_ttproducts_control_basket::generatedBasketExtFromRow($currRow, '1'); - $basketItemArray = $basketObj->getItemArrayFromRow( + $taxInfoArray = []; + $tax = 0.0; + $virtualItemArray = $basketObj->getItemArrayFromRow( + $tax, + $taxInfoArray, $currRow, $basketExt1, $basketExtra, $basketRecs, $funcTablename, + 'useExt', $externalRowArray, - $theCode == 'LISTGIFTS' + false ); - if (!empty($basketItemArray)) { - $basketObj->calculate($basketItemArray); // get the calculated arrays - $prodVariantRow = $basketObj->getMergedRowFromItemArray($basketItemArray, $basketExtra); + if (!empty($virtualItemArray)) { + $basketObj->calculate( + $virtualItemArray, + $basketExt, + $basketExtra, + $basketRecs, + $tax, + false + ); // get the calculated arrays + $prodVariantRow = $basketObj->getMergedRowFromItemArray($virtualItemArray, $basketExtra); } $currPriceMarkerArray = []; $articleTablename = (is_object($itemTableArray['article']) ? $itemTableArray['article']->getTablename() : ''); @@ -2655,10 +2695,11 @@ public function printView( $row, $itemTableViewArray[$itemTable->getType()]->getMarker(), $markerArray, + is_object($variantApi) ? $variantApi->getFieldArray() : [], $catTitle, + $viewTagArray, $config['limitImage'], $image, - $viewTagArray, [], $theCode, $basketExtra, @@ -2670,9 +2711,13 @@ public function printView( true, 'UTF-8', $hiddenFields, + $parentProductRow, + $parentFuncTablename, + $parentRows, $multiOrderArray, $productRowArray, - $theCode == 'LISTGIFTS' + false, + $notOverwritePriceIfSet ); if ( @@ -2736,14 +2781,16 @@ public function printView( ) { // use the fields of the article instead of the product // + $itemTableView->getModelMarkerArray( $prodVariantRow, // must have the getMergedRowFromItemArray function called before. Otherwise the product will not show the first variant selection at the first start time $itemTableViewArray['article']->getMarker(), $markerArray, + is_object($variantApi) ? $variantApi->getFieldArray() : [], $catTitle, + $articleViewTagArray, $config['limitImage'], $image, - $articleViewTagArray, [], $theCode, $basketExtra, @@ -2755,10 +2802,15 @@ public function printView( true, 'UTF-8', $hiddenFields, + $parentProductRow, // neu für Download + $parentFuncTablename, // neu für Download Object Liste + $parentRows, // neu für Download Object Liste $multiOrderArray, $productRowArray, - $theCode == 'LISTGIFTS' + false, + $notOverwritePriceIfSet // neu ); + $articleViewObj->getItemSubpartArrays( $t['item'], 'tt_products_articles', @@ -3233,7 +3285,8 @@ public function printView( $backPid ); // clickIntoBasket - $markerArray['###AMOUNT_CREDITPOINTS###'] = number_format($GLOBALS['TSFE']->fe_user->user['tt_products_creditpoints'] ?? 0, 0); + $markerArray['###AMOUNT_CREDITPOINTS###'] = number_format($feUserRecord['tt_products_creditpoints'] ?? 0, 0); + $markerArray['###ITEMS_SELECT_COUNT###'] = $productsCount; $javaScriptMarker->getMarkerArray($jsMarkerArray, $markerArray, $cObj); $markerArray = array_merge($jsMarkerArray, $markerArray); diff --git a/view/class.tx_ttproducts_memo_view.php b/view/class.tx_ttproducts_memo_view.php index 43eb07024..95dd22edb 100644 --- a/view/class.tx_ttproducts_memo_view.php +++ b/view/class.tx_ttproducts_memo_view.php @@ -42,6 +42,7 @@ use JambageCom\Div2007\Utility\FrontendUtility; use JambageCom\TtProducts\Api\BasketApi; +use JambageCom\TtProducts\Api\ParameterApi; class tx_ttproducts_memo_view implements SingletonInterface @@ -92,6 +93,7 @@ public function printView( $config = $cnf->getConfig(); $basketApi = GeneralUtility::makeInstance(BasketApi::class); $basketExtra = $basketApi->getBasketExtra(); + $feUserRecord = CustomerApi::getFeUserRecord(); if ( tx_ttproducts_control_memo::bUseFeuser($conf) || @@ -128,6 +130,7 @@ public function printView( '', $errorCode, $templateArea, + $feUserRecord, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][TT_PRODUCTS_EXT]['pageAsCategory'], $basketExtra, tx_ttproducts_control_basket::getRecs(), @@ -177,9 +180,10 @@ public function getFieldMarkerArray( $tagArray, &$bUseCheckBox ): void { + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $fieldKey = 'FIELD_' . $markerKey . '_NAME'; if (isset($tagArray[$fieldKey])) { - $markerArray['###' . $fieldKey . '###'] = tx_ttproducts_model_control::getPrefixId() . '[memo][' . $row['uid'] . ']'; + $markerArray['###' . $fieldKey . '###'] = $parameterApi->getPrefixId() . '[memo][' . $row['uid'] . ']'; } $fieldKey = 'FIELD_' . $markerKey . '_CHECK'; @@ -203,7 +207,8 @@ public function getHiddenFields( $bUseCheckBox ): void { if ($bUseCheckBox) { - $markerArray['###HIDDENFIELDS###'] .= ''; + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $markerArray['###HIDDENFIELDS###'] .= ''; } } } diff --git a/view/class.tx_ttproducts_menucat_view.php b/view/class.tx_ttproducts_menucat_view.php index b56de941f..49f2a082f 100644 --- a/view/class.tx_ttproducts_menucat_view.php +++ b/view/class.tx_ttproducts_menucat_view.php @@ -36,10 +36,12 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\TtProducts\Api\ControlApi; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\TtProducts\Api\ControlApi; +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_menucat_view extends tx_ttproducts_catlist_view_base { protected $htmlTagMain = 'ul'; // main HTML tag @@ -64,8 +66,9 @@ public function printView( $templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); $basketObj = GeneralUtility::makeInstance('tx_ttproducts_basket'); $pibaseObj = GeneralUtility::makeInstance('' . $this->pibaseClass); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $javaScriptMarker = GeneralUtility::makeInstance('tx_ttproducts_javascript_marker'); - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $prefixId = $parameterApi->getPrefixId(); $cObj = ControlApi::getCObj(); parent::getPrintViewArrays( diff --git a/view/class.tx_ttproducts_order_view.php b/view/class.tx_ttproducts_order_view.php index 541420b31..b11bfa5c2 100644 --- a/view/class.tx_ttproducts_order_view.php +++ b/view/class.tx_ttproducts_order_view.php @@ -36,11 +36,14 @@ * @package TYPO3 * @subpackage tt_products */ +use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; +use TYPO3\CMS\Core\Utility\GeneralUtility; + use JambageCom\Div2007\Utility\FrontendUtility; use JambageCom\Div2007\Utility\TableUtility; + use JambageCom\TtProducts\Api\Localization; -use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; -use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\TtProducts\Api\ParameterApi; class tx_ttproducts_order_view extends tx_ttproducts_table_base_view { @@ -76,6 +79,7 @@ protected function init2( if (!$bValidUpdateCode) { $feusers_uid = FrontendUtility::getFrontEndUser('uid'); } + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $funcTablename = $orderObj->getFuncTablename(); @@ -96,8 +100,8 @@ protected function init2( $feuserMarker = $feusersViewObj->getMarker(); $productFunctablename = 'tt_products'; $itemTable = $tablesObj->get($productFunctablename); // order - $piVars = tx_ttproducts_model_control::getPiVars(); - $prefix = tx_ttproducts_model_control::getPrefixId(); + $piVars = $parameterApi->getPiVars(); + $prefix = $parameterApi->getPrefixId(); $pid = $GLOBALS['TSFE']->id; $urlObj = GeneralUtility::makeInstance('tx_ttproducts_url_view'); @@ -340,6 +344,7 @@ public function getProductMarkerSubpartArrays( ); $notOverwritePriceIfSet = false; + $feUserRecord = []; $content = $listView->printView( $templateCode, $theCode, @@ -350,6 +355,7 @@ public function getProductMarkerSubpartArrays( $error_code, $subpartMarker, $pageAsCategory, + $feUserRecord, [], [], [], @@ -422,6 +428,7 @@ public function processFeuserSelect( $tablesObj = GeneralUtility::makeInstance('tx_ttproducts_tables'); $feusersObj = $tablesObj->get('fe_users', false); $languageObj = GeneralUtility::makeInstance(Localization::class); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $result = ''; @@ -440,7 +447,7 @@ public function processFeuserSelect( $valueArray[] = ['value' => $uid, 'label' => $row['uid'] . ' - ' . $row['name'] . ' - ' . $row['city']]; } - $piVar = tx_ttproducts_model_control::getPiVar('orderaddress'); + $piVar = $parameterApi->getPiVar('orderaddress'); $selectedKey = $piVars[$piVar] ?? 0; $type = 'select'; @@ -488,6 +495,7 @@ public function printView( $orderObj = $this->getModelObj(); // order $languageObj = GeneralUtility::makeInstance(Localization::class); $markerObj = GeneralUtility::makeInstance('tx_ttproducts_marker'); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); $feusers_uid = 0; $itemTable = null; $funcTablename = ''; @@ -604,7 +612,7 @@ public function printView( $valueArray[] = [$row['title'], $row['uid']]; } - $piVar = tx_ttproducts_model_control::getPiVar('fegroup'); + $piVar = $parameterApi->getPiVar('fegroup'); $selectedKey = $piVars[$piVar] ?? 0; $type = 'select'; $tagName = $prefix . '[' . $piVar . ']'; @@ -630,7 +638,7 @@ public function printView( $valueArray['0'] = $languageObj->getLabel('orders_view_orders'); $valueArray['1'] = $languageObj->getLabel('orders_view_products'); - $piVar = tx_ttproducts_model_control::getOrderViewVar(); + $piVar = $parameterApi->getOrderViewVar(); $selectedKey = $piVars[$piVar] ?? 0; $type = 'select'; $text = tx_ttproducts_form_div::createSelect( @@ -703,7 +711,7 @@ public function printView( } } - $orderPiVar = tx_ttproducts_model_control::getPiVar('sys_products_orders'); + $orderPiVar = $parameterApi->getPiVar('sys_products_orders'); $fieldPiVarArray = ['crdate' => ['ge', 'le']]; foreach ($fieldPiVarArray as $fieldPiVar => $piVarTypeArray) { @@ -766,7 +774,7 @@ public function printView( $from = $funcTablename . ' ' . $orderAlias . ' LEFT JOIN fe_users ON ' . $orderAlias . '.feusers_uid = fe_users.uid'; $where = 'fe_users.usergroup = ' . $fegroups_uid; } - $whereArray = $piVars[tx_ttproducts_model_control::getPiVar($funcTablename)] ?? ''; + $whereArray = $piVars[$parameterApi->getPiVar($funcTablename)] ?? ''; if (is_array($whereArray)) { foreach ($whereArray as $field => $value) { diff --git a/view/class.tx_ttproducts_pdf_view.php b/view/class.tx_ttproducts_pdf_view.php deleted file mode 100644 index dd53f08e0..000000000 --- a/view/class.tx_ttproducts_pdf_view.php +++ /dev/null @@ -1,264 +0,0 @@ - - * - * @maintainer Franz Holzinger - * - * @package TYPO3 - * @subpackage tt_products - */ -use PhpOffice\PhpWord\Autoloader; -use PhpOffice\PhpWord\IOFactory; -use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Settings; -use TYPO3\CMS\Core\Core\Environment; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -class tx_ttproducts_pdf_view -{ - /** - * generates the bill as a PDF file. - * - * @param string reference to an item array with all the data of the item - * - * @return string / boolean returns the absolute filename of the PDF bill or false - * for the tt_producst record, $row - * - * @access private - */ - public function generate( - $cObj, - $basketView, - $infoViewObj, - $templateCode, - $mainMarkerArray, - $itemArray, - $calculatedArray, - $orderArray, - $productRowArray, - $basketExtra, - $basketRecs, - $typeCode, - $generationConf, - $absFileName - ) { - $result = false; - - $infoArray = $infoViewObj->getInfoArray(); - $priceViewObj = GeneralUtility::makeInstance('tx_ttproducts_field_price_view'); - - if ( - !empty($itemArray) && - !empty($infoArray) && - is_array($generationConf['handleLib.']) - ) { - switch (strtoupper($generationConf['handleLib'])) { - case 'PHPWORD': - $pathsite = Environment::getPublicPath() . '/'; - $itemObj = GeneralUtility::makeInstance('tx_ttproducts_basketitem'); - $path = $pathsite . $generationConf['handleLib.']['path']; - - require_once $path . '/src/PhpWord/Autoloader.php'; - Autoloader::register(); - - $phpWord = new PhpWord(); - $templateFile = $pathsite . $generationConf['handleLib.']['template']; - - if (!file_exists($templateFile)) { - return false; - } - $nameInfo = pathinfo($templateFile); - $document = $phpWord->loadTemplate($templateFile); - $document->setValue('date', date('d.m.Y')); // On section/content - foreach ($infoArray['billing'] as $field => $value) { - $document->setValue('billing_' . $field, $value); - } - - $document->setValue('trackingcode', $orderArray['tracking_code']); - $trackingParts = explode('-', $orderArray['tracking_code']); - $document->setValue('trackingno', $trackingParts['0']); - $document->setValue('billno', $orderArray['bill_no']); // On section/content - $document->setValue('cnum', $infoArray['billing']['cnum']); // On section/content - - $lineCount = 0; - // loop over all items in the basket indexed by sorting text - foreach ($itemArray as $sort => $actItemArray) { - $lineCount += count($actItemArray); - } - $document->cloneRow('article_title', $lineCount); - - $lineCount = 0; - // loop over all items in the basket indexed by sorting text - foreach ($itemArray as $sort => $actItemArray) { - foreach ($actItemArray as $k1 => $actItem) { - $extArray = []; - $lineCount++; - $row = $actItem['rec']; - - if ( - isset($row['ext']) && - is_array($row['ext']) - ) { - $extArray = $row['ext']; - } else { - continue 2; - } - $outputRow = $row; - - if ( - isset($extArray['mergeArticles']) && - is_array($extArray['mergeArticles']) - ) { - $outputRow = $extArray['mergeArticles']; - } - if ( - isset($extArray['records']) && - is_array($extArray['records']) - ) { - $newTitleArray = []; - $externalRowArray = $extArray['records']; - - foreach ($externalRowArray as $tablename => $externalRow) { - $newTitleArray[] = $externalRow['title']; - } - $outputRow['title'] = implode(' | ', $newTitleArray); - } - - foreach ($outputRow as $field => $value) { - if ( - $field != 'ext' && - !strpos($field, '_uid') && - !strpos($field, '_id') && - is_string($value) - ) { - if (strpos($field, 'price') !== false) { - $value = $priceViewObj->priceFormat($value); - } - $document->setValue('article_' . $field . '#' . $lineCount, $value); - } - } - $quantity = $itemObj->getQuantity($actItem); - $document->setValue('count#' . $lineCount, $quantity); - - $document->setValue('price1#' . $lineCount, $priceViewObj->priceFormat($actItem['priceTax'])); - $document->setValue('price1total#' . $lineCount, $priceViewObj->priceFormat($actItem['priceTax'] * $quantity)); - } - } - - $document->setValue('pricenotaxtotal', $priceViewObj->priceFormat($calculatedArray['priceNoTax']['total']['ALL'])); - - if ( - isset($calculatedArray['priceNoTax']) && - is_array($calculatedArray['priceNoTax']) && - isset($calculatedArray['priceNoTax']['sametaxtotal']) && - is_array($calculatedArray['priceNoTax']['sametaxtotal']) && - !empty($calculatedArray['priceNoTax']['sametaxtotal']) - ) { - $lineCount = 0; - foreach ($calculatedArray['priceNoTax']['sametaxtotal'] as $countryCode => $taxRow) { - if ($countryCode == 'ALL' || !is_array($taxRow)) { - continue; - } - $lineCount += count($taxRow); - } - $document->cloneRow('onlytax_line', $lineCount); - - $lineCount = 0; - foreach ($calculatedArray['priceNoTax']['sametaxtotal'] as $countryCode => $taxRow) { - if ($countryCode == 'ALL') { - continue; - } - foreach ($taxRow as $tax => $value) { - $lineCount++; - $document->setValue('onlytax_line#' . $lineCount, ''); - $document->setValue('country#' . $lineCount, $countryCode); - $document->setValue('onlytax#' . $lineCount, $tax . ' %'); - $taxValue = $value * ($tax / 100); - $document->setValue('priceonlytaxtotal#' . $lineCount, $priceViewObj->priceFormat($taxValue)); - } - } - } - - $document->setValue('pricetaxtotal', $priceViewObj->priceFormat($calculatedArray['priceTax']['total']['ALL'])); - $typeArray = ['payment', 'shipping']; - $fieldArray = ['title', 'price']; - foreach ($typeArray as $type) { - foreach ($fieldArray as $field) { - $value = ''; - if ( - isset($basketExtra[$type . '.']) && - isset($basketExtra[$type . '.'][$field]) - ) { - $value = $basketExtra[$type . '.'][$field]; - } - - if ($field == 'price') { - $value = $priceViewObj->priceFormat($value); - } - - $document->setValue($type . '_' . $field, $value); - } - } - $header = $generationConf['handleLib.']['rendererLibrary.']['marks.']['header']; - $headerArray = explode(PHP_EOL, $header); - - foreach ($headerArray as $k => $header) { - $document->setValue('header_' . ($k + 1), $header); - } - - $name = $nameInfo['dirname'] . '/' . $nameInfo['filename'] . '-out.docx'; - $document->saveAs($name); - require_once $path . '/samples/Sample_Footer.php'; - $phpWord = IOFactory::load($name); - - if (is_array($generationConf['handleLib.']['rendererLibrary.'])) { - $pathsite = Environment::getPublicPath() . '/'; - $rendererName = Settings::PDF_RENDERER_DOMPDF; // PDF_RENDERER_MPDF PDF_RENDERER_TCPDF - $rendererLibraryPath = $pathsite . $generationConf['handleLib.']['rendererLibrary.']['path']; - Settings::setPdfRenderer($rendererName, $rendererLibraryPath); - $objWriter = IOFactory::createWriter($phpWord, 'PDF'); - $name = $nameInfo['dirname'] . '/' . $nameInfo['filename'] . '-' . $orderArray['tracking_code'] . '.pdf'; - $objWriter->save($name); - - $result = $name; - } - - break; - default: - break; - } - } - - return $result; - } -} diff --git a/view/class.tx_ttproducts_pdf_view_sample07.php b/view/class.tx_ttproducts_pdf_view_sample07.php deleted file mode 100644 index c8487faef..000000000 --- a/view/class.tx_ttproducts_pdf_view_sample07.php +++ /dev/null @@ -1,199 +0,0 @@ - - * - * @maintainer Franz Holzinger - * - * @package TYPO3 - * @subpackage tt_products - */ -class tx_ttproducts_pdf_view_sample07 -{ - /** - * generates the bill as a PDF file. - * - * @param string reference to an item array with all the data of the item - * - * @return string / boolean returns the absolute filename of the PDF bill or false - * for the tt_producst record, $row - * - * @access private - */ - public function generate( - $cObj, - $basketView, - $infoViewObj, - $templateCode, - $mainMarkerArray, - $itemArray, - $calculatedArray, - $orderArray, - $productRowArray, - $basketExtra, - $basketRecs, - $typeCode, - $generationConf, - $absFileName - ) { - $result = false; - - if (is_array($generationConf['handleLib.'])) { - switch (strtoupper($generationConf['handleLib'])) { - case 'PHPWORD': - $pathsite = Environment::getPublicPath() . '/'; - - $path = $pathsite . $generationConf['handleLib.']['path']; - - require_once $path . '/src/PhpWord/Autoloader.php'; - Autoloader::register(); - - $phpWord = new PhpWord(); - - $document = $phpWord->loadTemplate($path . '/samples/resources/Sample_07_TemplateCloneRow.docx'); - - // Variables on different parts of document - $document->setValue('weekday', date('l')); // On section/content - $document->setValue('time', date('H:i')); // On footer - $document->setValue('serverName', realpath(__DIR__)); // On header - - // Simple table - $document->cloneRow('rowValue', 20); - - $document->setValue('rowValue#1', 'Sun'); - $document->setValue('rowValue#2', 'Mercury'); - $document->setValue('rowValue#3', 'Venus'); - $document->setValue('rowValue#4', 'Earth'); - $document->setValue('rowValue#5', 'Mars'); - $document->setValue('rowValue#6', 'Jupiter'); - $document->setValue('rowValue#7', 'Saturn'); - $document->setValue('rowValue#8', 'Uranus'); - $document->setValue('rowValue#9', 'Neptun'); - $document->setValue('rowValue#10', 'Pluto'); - $document->setValue('rowValue#11', 'Sun'); - $document->setValue('rowValue#12', 'Mercury'); - $document->setValue('rowValue#13', 'Venus'); - $document->setValue('rowValue#14', 'Earth'); - $document->setValue('rowValue#15', 'Mars'); - $document->setValue('rowValue#16', 'Jupiter'); - $document->setValue('rowValue#17', 'Saturn'); - $document->setValue('rowValue#18', 'Uranus'); - $document->setValue('rowValue#19', 'Neptun'); - $document->setValue('rowValue#20', 'Pluto'); - - $document->setValue('rowNumber#1', '1'); - $document->setValue('rowNumber#2', '2'); - $document->setValue('rowNumber#3', '3'); - $document->setValue('rowNumber#4', '4'); - $document->setValue('rowNumber#5', '5'); - $document->setValue('rowNumber#6', '6'); - $document->setValue('rowNumber#7', '7'); - $document->setValue('rowNumber#8', '8'); - $document->setValue('rowNumber#9', '9'); - $document->setValue('rowNumber#10', '10'); - $document->setValue('rowNumber#11', '11'); - $document->setValue('rowNumber#12', '12'); - $document->setValue('rowNumber#13', '13'); - $document->setValue('rowNumber#14', '14'); - $document->setValue('rowNumber#15', '15'); - $document->setValue('rowNumber#16', '16'); - $document->setValue('rowNumber#17', '17'); - $document->setValue('rowNumber#18', '18'); - $document->setValue('rowNumber#19', '19'); - $document->setValue('rowNumber#20', '20'); - - // Table with a spanned cell - $document->cloneRow('userId', 6); - - $document->setValue('userId#1', '1'); - $document->setValue('userFirstName#1', 'James'); - $document->setValue('userName#1', 'Taylor'); - $document->setValue('userPhone#1', '+1 428 889 773'); - - $document->setValue('userId#2', '2'); - $document->setValue('userFirstName#2', 'Robert'); - $document->setValue('userName#2', 'Bell'); - $document->setValue('userPhone#2', '+1 428 889 774'); - - $document->setValue('userId#3', '3'); - $document->setValue('userFirstName#3', 'Michael'); - $document->setValue('userName#3', 'Ray'); - $document->setValue('userPhone#3', '+1 428 889 775'); - - $document->setValue('userId#4', '4'); - $document->setValue('userFirstName#4', 'Sepp'); - $document->setValue('userName#4', 'Joy'); - $document->setValue('userPhone#4', '+1 428 229 775'); - - $document->setValue('userId#5', '5'); - $document->setValue('userFirstName#5', 'Hans'); - $document->setValue('userName#5', 'May'); - $document->setValue('userPhone#5', '+1 425 229 322'); - - $document->setValue('userId#6', '6'); - $document->setValue('userFirstName#6', 'Franz'); - $document->setValue('userName#6', 'Clay'); - $document->setValue('userPhone#6', '+1 428 229 775'); - - $name = 'fileadmin/Sample_07_TemplateCloneRow.docx'; - $document->saveAs($name); - - require_once $path . '/samples/Sample_Footer.php'; - - $pathsite = Environment::getPublicPath() . '/'; - $phpWord = IOFactory::load($pathsite . $name); - - if (is_array($generationConf['handleLib.']['rendererLibrary.'])) { - $rendererName = Settings::PDF_RENDERER_DOMPDF; // PDF_RENDERER_MPDF PDF_RENDERER_TCPDF - $rendererLibraryPath = Environment::getPublicPath() . '/' . $generationConf['handleLib.']['rendererLibrary.']['path']; - Settings::setPdfRenderer($rendererName, $rendererLibraryPath); - $objWriter = IOFactory::createWriter($phpWord, 'PDF'); - $objWriter->save('fileadmin/Sample_07_TemplateCloneRow.pdf'); - - $result = true; - } - - break; - default: - break; - } - } - - return $result; - } -} diff --git a/view/class.tx_ttproducts_product_view.php b/view/class.tx_ttproducts_product_view.php index d7d055719..76bd61034 100644 --- a/view/class.tx_ttproducts_product_view.php +++ b/view/class.tx_ttproducts_product_view.php @@ -189,16 +189,17 @@ public function getItemMarkerSubpartArrays( */ public function getModelMarkerArray( $row, - $markerParam, - &$markerArray, + $markerKey, + array &$markerArray, + $variantFieldArray, $catTitle, + array $tagArray, $imageNum = 0, $imageRenderObj = 'image', - $tagArray = [], - $forminfoArray = [], + array $forminfoArray = [], $theCode = '', - $basketExtra = [], - $basketRecs = [], + array $basketExtra = [], + array $basketRecs = [], $id = '', $prefix = '', $suffix = '', @@ -206,9 +207,12 @@ public function getModelMarkerArray( $bHtml = true, $charset = '', $hiddenFields = '', - $multiOrderArray = [], - $productRowArray = [], - $bEnableTaxZero = false, + array $parentProductRow = [], + $parentFuncTablename = '', + array $parentRows = [], + array $multiOrderArray = [], + array $productRowArray = [], + $enableTaxZero = false, $notOverwritePriceIfSet = true ): void { // Returns a markerArray ready for substitution with information for the tt_producst record, $row @@ -220,12 +224,13 @@ public function getModelMarkerArray( $cObj = FrontendUtility::getContentObjectRenderer(); parent::getModelMarkerArray( $row, - $markerParam, + $markerKey, $markerArray, + $variantFieldArray, // neu $catTitle, + $tagArray, $imageNum, $imageRenderObj, - $tagArray, $forminfoArray, $theCode, $basketExtra, @@ -237,10 +242,13 @@ public function getModelMarkerArray( $bHtml, $charset, $hiddenFields, + $parentProductRow, // neu für Download + $parentFuncTablename, // neu für Download Object Liste + $parentRows, // neu für Download Object Liste $multiOrderArray, $productRowArray, - $bEnableTaxZero, - $notOverwritePriceIfSet + $enableTaxZero, + $notOverwritePriceIfSet // neu ); // Subst. fields @@ -294,7 +302,7 @@ public function getModelMarkerArray( $prefix, $suffix, $linkWrap, - $bEnableTaxZero + $enableTaxZero ); if (is_array($adressMarkerArray)) { $markerArray = array_merge($markerArray, $adressMarkerArray); diff --git a/view/class.tx_ttproducts_search_view.php b/view/class.tx_ttproducts_search_view.php index 6fe510eb0..cce4ffef2 100644 --- a/view/class.tx_ttproducts_search_view.php +++ b/view/class.tx_ttproducts_search_view.php @@ -59,9 +59,6 @@ public function printFirstletter($pibaseObj, &$templateCode, $columns, &$error_c { // local_table - /* $ctrlArray = GeneralUtility::makeInstance('tx_ttproducts_model_control'); - $ctrlArray = tx_ttproducts_model_control::$tableParamsArray;*/ - $searboxViewObj = GeneralUtility::makeInstance('tx_searchbox_view'); $paramArray = [ diff --git a/view/class.tx_ttproducts_single_view.php b/view/class.tx_ttproducts_single_view.php index 7f2ef0f72..13813dda0 100644 --- a/view/class.tx_ttproducts_single_view.php +++ b/view/class.tx_ttproducts_single_view.php @@ -43,16 +43,21 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use JambageCom\Div2007\Utility\FrontendUtility; +use JambageCom\Div2007\Utility\MarkerUtility; use JambageCom\TtProducts\Api\BasketApi; use JambageCom\TtProducts\Api\ControlApi; +use JambageCom\TtProducts\Api\FeUserMarkerApi; use JambageCom\TtProducts\Api\Localization; +use JambageCom\TtProducts\Api\ParameterApi; +use JambageCom\TtProducts\Api\VariantApi; +use JambageCom\TtProducts\View\RelatedList; class tx_ttproducts_single_view implements SingletonInterface { public $conf; public $config; - public $uid; // product id + public $uid = 0; // product id public $type = 'product'; // 'product', 'article' or 'dam' public $variants; // different attributes public $pid; // PID where to go @@ -102,6 +107,7 @@ public function init( public function printView( $templateCode, &$errorCode, + $feUserRecord, $pageAsCategory, $templateSuffix = '' ) { @@ -116,8 +122,14 @@ public function printView( $languageObj = GeneralUtility::makeInstance(Localization::class); $urlObj = GeneralUtility::makeInstance('tx_ttproducts_url_view'); $cObj = ControlApi::getCObj(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $variantApi = null; - $piVars = tx_ttproducts_model_control::getPiVars(); + if ($this->type == 'product' || $this->type == 'article') { + $variantApi = GeneralUtility::makeInstance(VariantApi::class); + } + + $piVars = $parameterApi->getPiVars(); $conf = $cnf->getConf(); $externalRowArray = []; @@ -331,7 +343,7 @@ public function printView( if (isset($viewParamConf['item']) && GeneralUtility::inList($viewParamConf['item'], $categoryPivar)) { // nothing } else { - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $prefixId = $parameterApi->getPrefixId(); $excludeList .= ($excludeList != '' ? ',' : '') . $prefixId . '[' . $categoryPivar . ']'; } } @@ -357,14 +369,19 @@ public function printView( return ''; } - $viewTagArray = $markerObj->getAllMarkers($itemFrameWork); - $tablesObj->get('fe_users', true)->getWrappedSubpartArray( + $viewTagArray = MarkerUtility::getTags($itemFrameWork); + $orderAddressObj = $tablesObj->get('fe_users', false); + $feUserMarkerApi = GeneralUtility::makeInstance(FeUserMarkerApi::class); + $feUserMarkerApi->getWrappedSubpartArray( + $orderAddressObj, $viewTagArray, - $useBackPid, + $feUserRecord, $subpartArray, $wrappedSubpartArray ); + $feUserMarkerApi->getGlobalMarkerArray($markerArray, $feUserRecord); // neu FHO + $itemFrameWork = $templateService->substituteMarkerArrayCached( $itemFrameWork, $markerArray, @@ -766,16 +783,17 @@ public function printView( } $basketRecs = tx_ttproducts_control_basket::getRecs(); - $prodVariantRow = $row; + $itemTableViewArray[$this->type]->getModelMarkerArray( $row, $itemTableViewArray[$this->type]->getMarker(), $markerArray, + is_object($variantApi) ? $variantApi->getFieldArray() : [], $catTitle, + $viewTagArray, $this->config['limitImageSingle'], 'image', - $viewTagArray, $forminfoArray, 'SINGLE', $basketExtra, @@ -787,10 +805,13 @@ public function printView( true, 'UTF-8', '', // $hiddenFields + [], '', [], [], - $bIsGift + [], + $bIsGift, // $enableTaxZero + true // $notOverwritePriceIfSet ); if ($this->type == 'product') { @@ -836,6 +857,7 @@ public function printView( $allVariants, $useArticles, $itemTableArray[$this->type]->getFuncTablename(), + $basketExt, false ); @@ -849,21 +871,34 @@ public function printView( '1' ); } - $itemArray = + $taxInfoArray = []; + $tax = 0.0; + $virtualItemArray = $basketObj->getItemArrayFromRow( + $tax, // neu + $taxInfoArray, // neu $currRow, $basketExt1, $basketExtra, $basketRecs, $funcTablename, + 'useExt', $externalRowArray, $bIsGift ); - $basketObj->calculate($itemArray); // get the calculated arrays + $basketObj->calculate( + $virtualItemArray, + $basketExt, + $basketExtra, + $basketRecs, + $tax, // neu + false // neu + ); // get the calculated arrays + $prodVariantRow = $basketObj->getMergedRowFromItemArray( - $itemArray, + $virtualItemArray, $basketExtra ); @@ -880,10 +915,11 @@ public function printView( $prodVariantRow, $itemTableViewArray['article']->getMarker(), $markerArray, + is_object($variantApi) ? $variantApi->getFieldArray() : [], $catTitle, + $articleViewTagArray, $this->config['limitImageSingle'], 'image', - $articleViewTagArray, [], 'SINGLE', $basketExtra, @@ -895,10 +931,13 @@ public function printView( true, 'UTF-8', '', // $hiddenFields + [], '', [], [], - $bIsGift + [], + $bIsGift, // $enableTaxZero + true // $notOverwritePriceIfSet ); } elseif ($this->type == 'article') { $articleRow = $row; @@ -907,10 +946,11 @@ public function printView( $prodRow, $itemTableViewArray['product']->getMarker(), $markerArray, + is_object($variantApi) ? $variantApi->getFieldArray() : [], $catTitle, + $viewTagArray, $this->config['limitImageSingle'], 'listImage', - $viewTagArray, [], 'SINGLE', $basketExtra, @@ -922,10 +962,13 @@ public function printView( true, 'UTF-8', '', // $hiddenFields + [], '', [], [], - $bIsGift + [], + $bIsGift, // $enableTaxZero + true // $notOverwritePriceIfSet ); } @@ -955,11 +998,13 @@ public function printView( $prodVariantValuesRow = array_merge($prodVariantRow, $variantValuesRow); $item = $basketObj->getItem( + $mergePrices = true, $basketExt, $basketExtra, $basketRecs, - $prodVariantValuesRow, // $prodVariantRow, // $prodRow wiederhergestellt wie früher + $prodVariantValuesRow, // / $prodVariantRow, // $prodRow wiederhergestellt wie früher 'firstVariant', + $taxInfoArray, $funcTablename, $externalRowArray, $bIsGift @@ -1295,7 +1340,7 @@ public function printView( } $eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class); - $relatedListView = GeneralUtility::makeInstance('tx_ttproducts_relatedlist_view', $eventDispatcher); + $relatedListView = GeneralUtility::makeInstance(RelatedList::class, $eventDispatcher); $relatedListView->init( $this->pidListObj->getPidlist(), $this->pidListObj->getRecursive() diff --git a/view/class.tx_ttproducts_table_base_view.php b/view/class.tx_ttproducts_table_base_view.php index 80c96c26d..f31d9d1bf 100644 --- a/view/class.tx_ttproducts_table_base_view.php +++ b/view/class.tx_ttproducts_table_base_view.php @@ -827,4 +827,99 @@ protected function getRowMarkerArrayHooks( } } } + + /** + * Template marker substitution + * Fills in the markerArray with data for a product. + * + * @param array reference to an item array with all the data of the item + * @param string title of the category + * @param int number of images to be shown + * @param array information about the parent HTML form + * + * @return array Returns a markerArray ready for substitution with information + * for the tt_producst record, $row + * + * @access private + */ + public function getModelMarkerArray( + $row, + $markerKey, + array &$markerArray, + $variantFieldArray, // neu + $catTitle, + array $tagArray, + $imageNum = 0, + $imageRenderObj = 'image', + array $forminfoArray = [], + $theCode = '', + array $basketExtra = [], + array $basketRecs = [], + $id = '', + $prefix = '', + $suffix = '', + $linkWrap = '', + $bHtml = true, + $charset = '', + $hiddenFields = '', + array $parentProductRow = [], // neu für Download + $parentFuncTablename = '', // neu für Download Object Liste + array $parentRows = [], // neu für Download Object Liste + array $multiOrderArray = [], + array $productRowArray = [], + $enableTaxZero = false, + $notOverwritePriceIfSet = true // neu + ) { + $modelObj = $this->getModelObj(); + $cnfObj = GeneralUtility::makeInstance('tx_ttproducts_config'); + $conf = $cnfObj->getConf(); + + if ($markerKey) { + $marker = $markerKey; + } else { + $marker = $this->getMarker(); + } + + if (!$marker) { + return []; + } + $variantMarkerArray = []; + + $this->getRowMarkerArray( + $modelObj->getFuncTablename(), + $row, + $marker, + $markerArray, + $variantFieldArray, + $variantMarkerArray, + $tagArray, + $theCode, + $basketExtra, + $basketRecs, + $bHtml, + $charset, + $imageNum, + $imageRenderObj, + $id, + $prefix, + $suffix, + $linkWrap, + $enableTaxZero + ); + $markerArray = array_merge($markerArray, $variantMarkerArray); + + $this->getPriceMarkerArray( + $basketExtra, + $basketRecs, + $markerArray, + $row, + $markerKey, + $id, + $theCode, + $enableTaxZero, + $notOverwritePriceIfSet // neu + ); + + $markerArray['###CUR_SYM###'] = ' ' . ($bHtml ? htmlentities($conf['currencySymbol'], ENT_QUOTES) : $conf['currencySymbol']); + } } diff --git a/view/class.tx_ttproducts_url_view.php b/view/class.tx_ttproducts_url_view.php index d0284ded8..4db39e032 100644 --- a/view/class.tx_ttproducts_url_view.php +++ b/view/class.tx_ttproducts_url_view.php @@ -36,11 +36,14 @@ * @package TYPO3 * @subpackage tt_products */ -use JambageCom\Div2007\Utility\FrontendUtility; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use JambageCom\Div2007\Utility\FrontendUtility; + +use JambageCom\TtProducts\Api\ParameterApi; + class tx_ttproducts_url_view implements SingletonInterface { public $conf; @@ -288,8 +291,9 @@ public function addURLMarkers( */ public function addQueryStringParam(&$queryString, $param, $bUsePrefix = false): void { - $piVars = tx_ttproducts_model_control::getPiVars(); - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $piVars = $parameterApi->getPiVars(); + $prefixId = $parameterApi->getPrefixId(); $temp = $piVars[$param] ?? ''; $temp = ($temp ?: (GeneralUtility::_GP($param) && ($param != 'pid') ? GeneralUtility::_GP($param) : 0)); @@ -315,7 +319,8 @@ public function getLinkParams( $piVarSingle = 'product', $piVarCat = 'cat' ) { - $prefixId = tx_ttproducts_model_control::getPrefixId(); + $parameterApi = GeneralUtility::makeInstance(ParameterApi::class); + $prefixId = $parameterApi->getPrefixId(); $queryString = []; if ($useBackPid) { @@ -349,9 +354,9 @@ public function getLinkParams( $this->addQueryStringParam($queryString, $piVarCat, $bUsePrefix); } - $listPointerParam = tx_ttproducts_model_control::getPointerPiVar('LIST'); + $listPointerParam = $parameterApi->getPointerPiVar('LIST'); $this->addQueryStringParam($queryString, $listPointerParam, $bUsePrefix); - $catlistPointerParam = tx_ttproducts_model_control::getPointerPiVar('CATLIST'); + $catlistPointerParam = $parameterApi->getPointerPiVar('CATLIST'); $this->addQueryStringParam($queryString, 'mode', false); $this->addQueryStringParam($queryString, $listPointerParam, $bUsePrefix);