/** * Set up the subcategories block in the current shop page. * @param integer $parent_id The optional parent ShopCategory ID, * defaults to 0 (zero). * @return boolean True on success, false otherwise * @global array */ static function showCategories($parent_id = 0) { if ($parent_id) { $objCategory = ShopCategory::getById($parent_id); // If we can't get this ShopCategory, it most probably does // not exist. if (!$objCategory) { // Retry using the root. $parent_id = 0; } else { // Show the parent ShopCategory's image, if available $imageName = $objCategory->picture(); if ($imageName) { self::$objTemplate->setVariable(array('SHOP_CATEGORY_CURRENT_IMAGE' => \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $imageName, 'SHOP_CATEGORY_CURRENT_IMAGE_ALT' => $objCategory->name())); } } } // Get all active child categories with parent ID $parent_id $arrShopCategory = ShopCategories::getChildCategoriesById($parent_id, true); if (!is_array($arrShopCategory)) { return false; } $cell = 0; $arrDefaultImageSize = false; // For all child categories do... foreach ($arrShopCategory as $objCategory) { $id = $objCategory->id(); $catName = $objCategory->name(); $imageName = $objCategory->picture(); $thumbnailPath = self::$defaultImage; $description = $objCategory->description(); $description = nl2br(htmlentities($description, ENT_QUOTES, CONTREXX_CHARSET)); $description = preg_replace('/[\\n\\r]/', '', $description); if (empty($arrDefaultImageSize)) { //\DBG::log("Shop::showCategories(): ".\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . self::$defaultImage); $arrDefaultImageSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . self::$defaultImage); self::scaleImageSizeToThumbnail($arrDefaultImageSize); } $arrSize = $arrDefaultImageSize; if (!$imageName) { // Look for a picture in the Products. $imageName = Products::getPictureByCategoryId($id); } if (!$imageName) { // Look for a picture in the subcategories and their Products. $imageName = ShopCategories::getPictureById($id); } if ($imageName) { $thumb_name = \ImageManager::getThumbnailFilename($imageName); if (file_exists(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopPath() . '/' . $thumb_name)) { // Image found! Use that instead of the default. $thumbnailPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $thumb_name; $arrSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . $thumbnailPath); self::scaleImageSizeToThumbnail($arrSize); } } if ($imageName) { self::$objTemplate->setVariable('SHOP_CATEGORY_IMAGE', contrexx_raw2encodedUrl(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $imageName)); } self::$objTemplate->setVariable(array('SHOP_CATEGORY_ID' => $id, 'SHOP_CATEGORY_NAME' => htmlentities($catName, ENT_QUOTES, CONTREXX_CHARSET), 'SHOP_CATEGORY_THUMBNAIL' => contrexx_raw2encodedUrl($thumbnailPath), 'SHOP_CATEGORY_THUMBNAIL_SIZE' => $arrSize[3], 'SHOP_CATEGORY_DESCRIPTION' => $description)); // Add flag images for flagged ShopCategories $strImage = ''; $arrVirtual = ShopCategories::getVirtualCategoryNameArray(); foreach ($arrVirtual as $strFlag) { if ($objCategory->testFlag($strFlag)) { $strImage .= '<img src="images/content/' . $strFlag . '.jpg" alt="' . $strFlag . '" />'; } } if ($strImage) { self::$objTemplate->setVariable('SHOP_CATEGORY_FLAG_IMAGE', $strImage); } if (self::$objTemplate->blockExists('subCategories')) { self::$objTemplate->parse('subCategories'); if (++$cell % 4 == 0) { self::$objTemplate->parse('subCategoriesRow'); } } } return true; }