/** * Inits the main params for using in the script * * @param array $conf Configuration * * @return void */ public function init(array $conf = array()) { parent::init($conf); // Merge default vars, if other prefix_id if ($this->prefixId != 'tx_commerce_pi1') { $generellRequestVars = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_commerce'); if (is_array($generellRequestVars)) { foreach ($generellRequestVars as $key => $value) { if (empty($this->piVars[$key])) { $this->piVars[$key] = $value; } } } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['init'])) { \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi1/class.tx_commerce_pi1.php\'][\'init\'] is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Controller/ListController.php\'][\'init\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['init'] as $classRef) { $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'preInit')) { $hookObj->preInit($this); } } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['init'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['init'] as $classRef) { $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'preInit')) { $hookObj->preInit($this); } } } $this->templateFolder = 'uploads/tx_commerce/'; $this->pi_USER_INT_obj = 0; $this->conf['singleProduct'] = (int) $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'product_id', 's_product'); if ($this->conf['singleProduct'] > 0) { // product UID was set by Plugin or TS $this->singleViewAsPlugin = TRUE; } // Unset variable, if smaller than 0, as -1 is returend // when no product is selcted in form. if ($this->conf['singleProduct'] < 0) { $this->conf['singleProduct'] = FALSE; } $this->piVars['showUid'] = intval($this->piVars['showUid']) ?: 0; $this->piVars['showUid'] = $this->piVars['showUid'] ?: $this->conf['singleProduct']; $this->handle = $this->piVars['showUid'] ? 'singleView' : 'listView'; // Define the currency // Use of curency is depricated as it was only a typo :-) if ($this->conf['curency'] > '') { $this->currency = $this->conf['curency']; } if ($this->conf['currency'] > '') { $this->currency = $this->conf['currency']; } if (empty($this->currency)) { $this->currency = 'EUR'; } // Set some flexform values $this->master_cat = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'StartCategory', 's_product'); if (!$this->master_cat) { $this->master_cat = $this->conf['catUid']; } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'displayPID', 's_template')) { $this->conf['overridePid'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'displayPID', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'numberOfTopproducts', 's_product')) { $this->conf['numberOfTopproducts'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'numberOfTopproducts', 's_product'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showPageBrowser', 's_template')) { $this->conf['showPageBrowser'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showPageBrowser', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxRecords', 's_template')) { $this->conf['maxRecords'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxRecords', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxPages', 's_template')) { $this->conf['maxPages'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'maxPages', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'basketPid', 's_template')) { $this->conf['basketPid'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'basketPid', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'dontLinkActivePage', 's_template')) { $this->conf['pageBrowser.']['dontLinkActivePage'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'dontLinkActivePage', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showFirstLast', 's_template')) { $this->conf['pageBrowser.']['showFirstLast'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showFirstLast', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showRange', 's_template')) { $this->conf['pageBrowser.']['showRange'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showRange', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showItemCount', 's_template')) { $this->conf['pageBrowser.']['showItemCount'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'showItemCount', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'hscText', 's_template')) { $this->conf['pageBrowser.']['hscText'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'hscText', 's_template'); } if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template', 's_template') && file_exists($this->templateFolder . $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template', 's_template'))) { $this->conf['templateFile'] = $this->templateFolder . $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template', 's_template'); if ($this->cObj->fileResource($this->conf['templateFile'])) { $this->templateCode = $this->cObj->fileResource($this->conf['templateFile']); } } $accessible = FALSE; /** * Temporary category * * @var Tx_Commerce_Domain_Model_Category $tmpCategory */ $tmpCategory = NULL; if ($this->piVars['catUid']) { $this->cat = (int) $this->piVars['catUid']; $tmpCategory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->cat, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']); $accessible = $tmpCategory->isAccessible(); } // Validate given catUid, if it's given and accessible if (!$this->piVars['catUid'] || !$accessible) { $this->cat = (int) $this->master_cat; $tmpCategory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->cat, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']); } if (!isset($this->piVars['catUid'])) { $this->piVars['catUid'] = $this->master_cat; } if (is_object($tmpCategory)) { $tmpCategory->loadData(); } $this->category = $tmpCategory; $categorySubproducts = $this->category->getProductUids(); $frontend = $this->getFrontendController(); if (!$this->conf['singleProduct'] && (int) $this->piVars['showUid'] > 0 && !$GLOBALS['TSFE']->beUserLogin) { if (is_array($categorySubproducts)) { if (!in_array($this->piVars['showUid'], $categorySubproducts)) { $categoryAllSubproducts = $this->category->getProducts(); if (!in_array((int) $this->piVars['showUid'], $categoryAllSubproducts)) { // The requested product is not beblow the selected category // So exit with page not found $frontend->pageNotFoundAndExit($this->pi_getLL('error.productNotFound', 'Product not found', 1)); } } } else { $categoryAllSubproducts = $this->category->getProducts(); if (!in_array($this->piVars['showUid'], $categoryAllSubproducts)) { // The requested product is not beblow the selected category // So exit with page not found $frontend->pageNotFoundAndExit($this->pi_getLL('error.productNotFound', 'Product not found', 1)); } } } if ($this->piVars['catUid'] && $this->conf['checkCategoryTree'] == 1) { // Validate given CAT UID, if is below master_cat $this->masterCategoryObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->master_cat, $this->getFrontendController()->tmpl->setup['config.']['sys_language_uid']); $this->masterCategoryObj->loadData(); /** * Master category * * @var Tx_Commerce_Domain_Model_Category masterCategoryObj */ $masterCategorySubCategories = $this->masterCategoryObj->getChildCategoriesUidlist(); if (in_array($this->piVars['catUid'], $masterCategorySubCategories)) { $this->cat = (int) $this->piVars['catUid']; } else { // Wrong UID, so start with page not found $frontend->pageNotFoundAndExit($this->pi_getLL('error.categoryNotFound', 'Product not found', 1)); } } elseif (!isset($this->piVars['catUid'])) { $this->cat = (int) $this->master_cat; } if ($this->cat != $this->category->getUid()) { // Only, if the category has been changed unset($this->category); /** * Category * * @var Tx_Commerce_Domain_Model_Category category */ $this->category = \TYPO3\CMS\Core\Utility\GeneralUtility::makeinstance('Tx_Commerce_Domain_Model_Category', $this->cat, $GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid']); $this->category->loadData(); } $this->internal['results_at_a_time'] = $this->conf['maxRecords']; $this->internal['maxPages'] = $this->conf['maxPages']; // Going the long way ??? Just for list view $long = 1; switch ($this->handle) { case 'singleView': if ($this->initSingleView($this->piVars['showUid'])) { $long = 0; } break; default: } if ($this->cat > 0) { $this->category_array = $this->category->returnAssocArray(); $catConf = $this->category->getTyposcriptConfig(); if (is_array($catConf['catTS.'])) { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->conf, $catConf['catTS.']); } if ($long) { $this->category->setPageTitle(); $this->category->getChildCategories(); if ($this->conf['groupProductsByCategory']) { $this->category_products = $this->category->getProducts(0); } elseif ($this->conf['showProductsRecLevel']) { $this->category_products = $this->category->getProducts($this->conf['showProductsRecLevel']); } else { $this->category_products = $this->category->getProducts(0); } if ($this->conf['useStockHandling'] == 1) { $this->category_products = Tx_Commerce_Utility_GeneralUtility::removeNoStockProducts($this->category_products, $this->conf['products.']['showWithNoStock']); } $this->internal['res_count'] = count($this->category_products); } } else { $this->content = $this->cObj->stdWrap($this->conf['emptyCOA'], $this->conf['emptyCOA.']); $this->handle = FALSE; } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['postInit'])) { \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi1/class.tx_commerce_pi1.php\'][\'postInit\'] is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Controller/ListController.php\'][\'postInit\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi1/class.tx_commerce_pi1.php']['postInit'] as $classRef) { $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'postInit')) { $hookObj->postInit($this); } } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['postInit'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['postInit'] as $classRef) { $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'postInit')) { $hookObj->postInit($this); } } } }
/** * Returns if this category has products with stock * * @return bool TRUE, if this category has products with stock, FALSE if not */ public function hasProductsWithStock() { $result = FALSE; if ($this->hasProducts()) { $result = count(Tx_Commerce_Utility_GeneralUtility::removeNoStockProducts($this->getProducts(), 0)); } return $result; }
/** * Makes the list view for the current categorys * * @return string the content for the list view */ public function makeListView() { if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['preRenderListView'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/ListController.php']['preRenderListView'] as $classRef) { $hookObjectsArr[] = GeneralUtility::getUserObj($classRef); } } /** * Category LIST */ $categoryOutput = ''; $this->template = $this->templateCode; if ($this->category->hasSubcategories()) { /** * Category * * @var $oneCategory Tx_Commerce_Domain_Model_Category */ foreach ($this->category->getChildCategories() as $oneCategory) { $oneCategory->loadData(); $this->currentCategory =& $oneCategory; if ($this->conf['hideEmptyCategories'] == 1) { // First check TS setting (ceap) // afterwards do the recursive call (expensive) if (!$oneCategory->hasProductsInSubCategories() || $this->conf['useStockHandling'] && !$oneCategory->hasProductsWithStock()) { // This category is empty, so // skip this iteration and do next continue; } } $linkArray = array(); $linkArray['catUid'] = $oneCategory->getUid(); $linkArray['showUid'] = ''; if ($this->useRootlineInformationToUrl == 1) { $linkArray['path'] = $this->getPathCat($oneCategory); $linkArray['mDepth'] = $this->mDepth; } else { $linkArray['mDepth'] = ''; $linkArray['path'] = ''; } if ($this->basketHashValue) { $linkArray['basketHashValue'] = $this->basketHashValue; } /** * Build TS for Linking the Catergory Images */ $localTs = $this->conf['categoryListView.']['categories.']; if ($this->conf['overridePid']) { $typoLinkConf['parameter'] = $this->conf['overridePid']; } else { $typoLinkConf['parameter'] = $this->pid; } $typoLinkConf['useCacheHash'] = 1; $typoLinkConf['additionalParams'] = $this->argSeparator . $this->prefixId . '[catUid]=' . $oneCategory->getUid(); $productArray = $oneCategory->getProducts(); if (1 == $this->conf['displayProductIfOneProduct'] && 1 == count($productArray)) { $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[showUid]=' . $productArray[0]; } else { $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[showUid]='; } if ($this->useRootlineInformationToUrl == 1) { $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[path]=' . $this->getPathCat($oneCategory); $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[mDepth]=' . $this->mDepth; } if ($this->basketHashValue) { $typoLinkConf['additionalParams'] .= $this->argSeparator . $this->prefixId . '[basketHashValue]=' . $this->basketHashValue; } $localTs['fields.']['images.']['stdWrap.']['typolink.'] = $typoLinkConf; $localTs['fields.']['teaserimages.']['stdWrap.']['typolink.'] = $typoLinkConf; $localTs = $this->addTypoLinkToTypoScript($localTs, $typoLinkConf); $tmpCategory = $this->renderCategory($oneCategory, '###CATEGORY_LIST_ITEM###', $localTs, 'ITEM'); /** * Build the link * * @depricated * Please use TYPOLINK instead */ $linkContent = $this->cObj->getSubpart($tmpCategory, '###CATEGORY_ITEM_DETAILLINK###'); if ($linkContent) { $link = $this->pi_linkTP_keepPIvars($linkContent, $linkArray, TRUE, 0, $this->conf['overridePid']); } else { $link = ''; } $tmpCategory = $this->cObj->substituteSubpart($tmpCategory, '###CATEGORY_ITEM_DETAILLINK###', $link); if ($this->conf['groupProductsByCategory'] && !$this->conf['hideProductsInList'] && !$this->conf['hideProductsInSubcategories']) { $categoryProducts = $oneCategory->getProducts(); if ($this->conf['useStockHandling'] == 1) { $categoryProducts = Tx_Commerce_Utility_GeneralUtility::removeNoStockProducts($categoryProducts, $this->conf['products.']['showWithNoStock']); } $categoryProducts = array_slice($categoryProducts, 0, $this->conf['numberProductsInSubCategory']); $productList = $this->renderProductsForList($categoryProducts, $this->conf['templateMarker.']['categoryProductList.'], $this->conf['templateMarker.']['categoryProductListIterations']); /** * Insert the Productlist */ $tmpCategory = $this->cObj->substituteMarker($tmpCategory, '###CATEGORY_ITEM_PRODUCTLIST###', $productList); } else { $tmpCategory = $this->cObj->substituteMarker($tmpCategory, '###CATEGORY_ITEM_PRODUCTLIST###', ''); } $categoryOutput .= $tmpCategory; } } $categoryListSubpart = $this->cObj->getSubpart($this->template, '###CATEGORY_LIST###'); $markerArray['CATEGORY_SUB_LIST'] = $this->cObj->substituteSubpart($categoryListSubpart, '###CATEGORY_LIST_ITEM###', $categoryOutput); $startPoint = $this->piVars['pointer'] ? $this->internal['results_at_a_time'] * $this->piVars['pointer'] : 0; // Display TopProducts??? // for this, make a few basicSettings for pageBrowser $internalStartPoint = $startPoint; $internalResults = $this->internal['results_at_a_time']; // set Empty default $markerArray['SUBPART_CATEGORY_ITEMS_LISTVIEW_TOP'] = ''; if (!$this->conf['groupProductsByCategory'] && $this->conf['displayTopProducts'] && $this->conf['numberOfTopproducts']) { $this->top_products = array_slice($this->category_products, $startPoint, $this->conf['numberOfTopproducts']); $internalStartPoint = $startPoint + $this->conf['numberOfTopproducts']; $internalResults = $this->internal['results_at_a_time'] - $this->conf['numberOfTopproducts']; $markerArray['SUBPART_CATEGORY_ITEMS_LISTVIEW_TOP'] = $this->renderProductsForList($this->top_products, $this->conf['templateMarker.']['categoryProductListTop.'], $this->conf['templateMarker.']['categoryProductListTopIterations'], $this->conf['topProductTSMarker']); } // ########### product list ###################### if (is_array($this->category_products)) { $this->category_products = array_slice($this->category_products, $internalStartPoint, $internalResults); } if (!$this->conf['hideProductsInList']) { if (isset($this->piVars['showUid'])) { $this->piVars['showUid'] = ''; } // Write the current page to The session to have a back to last product link $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_commerce_lastproducturl', $this->pi_linkTP_keepPIvars_url(array(), 1)); $markerArray['SUBPART_CATEGORY_ITEMS_LISTVIEW'] = $this->renderProductsForList($this->category_products, $this->conf['templateMarker.']['categoryProductList.'], $this->conf['templateMarker.']['categoryProductListIterations']); } $templateMarker = '###' . strtoupper($this->conf['templateMarker.']['categoryView']) . '###'; $markerArrayCat = $this->generateMarkerArray($this->category->returnAssocArray(), $this->conf['singleView.']['categories.'], 'category_', 'tx_commerce_categories'); $markerArray = array_merge($markerArrayCat, $markerArray); if ($this->conf['showPageBrowser'] == 1 && is_array($this->conf['pageBrowser.']['wraps.'])) { $this->internal['pagefloat'] = (int) $this->piVars['pointer']; $this->internal['dontLinkActivePage'] = $this->conf['pageBrowser.']['dontLinkActivePage']; $this->internal['showFirstLast'] = $this->conf['pageBrowser.']['showFirstLast']; $this->internal['showRange'] = $this->conf['pageBrowser.']['showRange']; $hscText = !($this->conf['pageBrowser.']['hscText'] != 1); $markerArray['CATEGORY_BROWSEBOX'] = $this->pi_list_browseresults($this->conf['pageBrowser.']['showItemCount'], $this->conf['pageBrowser.']['tableParams.'], $this->conf['pageBrowser.']['wraps.'], 'pointer', $hscText); } else { $markerArray['CATEGORY_BROWSEBOX'] = ''; } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['listview'])) { GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/lib/class.tx_commerce_pibase.php\'][\'listview\'] is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Controller/BaseController.php\'][\'listView\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_pibase.php']['listview'] as $classRef) { $hookObj =& GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'additionalMarker')) { $markerArray = $hookObj->additionalMarker($markerArray, $this); } } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['listView'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/BaseController.php']['listView'] as $classRef) { $hookObj = GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'additionalMarker')) { $markerArray = $hookObj->additionalMarker($markerArray, $this); } } } $markerArray = $this->addFormMarker($markerArray); $template = $this->cObj->getSubpart($this->templateCode, $templateMarker); $content = $this->cObj->substituteMarkerArray($template, $markerArray, '###|###', 1); $content = $this->cObj->substituteMarkerArray($content, $this->languageMarker); return $content; }