Seite 1 von 1

Was mache ich falsch? Überladung der unteren Kategoriebeschreibung

Verfasst: 14 Dez 2025, 14:32
von Burkhard

Code: Alles auswählen

<?php
/* --------------------------------------------------------------
   CategoryDescriptionBottomThemeContentView.inc.php
   Gambio GmbH
   Released under GNU GPL v2
   --------------------------------------------------------------
*/

class _CategoryDescriptionJsonContentView extends _CategoryDescriptionJsonContentView_parent
{
	public function _assignCategoryData()
	{
		$result = parent::_assignCategoryData();

		if (isset($_GET['categories_id'])) 
		{
			$actual_categories_id = (int) $_GET['categories_id'];
			$sql = xtc_db_query("
				SELECT categories_description_bottom 
				FROM categories_description 
				WHERE categories_id = '$actual_categories_id' 
				LIMIT 1
			");

			if ($row = xtc_db_fetch_array($sql)) 
			{
				$htmlContent = $row['categories_description_bottom'];

					$faq = [];

					preg_match_all('/<h([1-4])[^>]*>(.*?)<\/h\1>/i', $htmlContent, $matches, PREG_OFFSET_CAPTURE);

					foreach ($matches[0] as $index => $fullMatch) {
						$headingText = strip_tags($matches[2][$index][0]);
						if (strpos($headingText, '?') !== false) {
							$startPos = $matches[0][$index][1] + strlen($fullMatch[0]);
							$endPos = isset($matches[0][$index + 1][1]) ? $matches[0][$index + 1][1] : strlen($htmlContent);
							$answerHtml = substr($htmlContent, $startPos, $endPos - $startPos);
							$answerText = trim(strip_tags($answerHtml));

							$faq[] = [
								'@type' => 'Question',
								'name' => $headingText,
								'acceptedAnswer' => [
									'@type' => 'Answer',
									'text' => $answerText
								]
							];
						}
					}

					$faqJson = [
						'@context' => 'https://schema.org',
						'@type' => 'FAQPage',
						'mainEntity' => $faq
					];


				$this->set_content_data('CATEGORIES_DESCRIPTION_JSON', json_encode($faqJson, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));

				// Debug-Variable
				$this->set_content_data('DEBUG_MESSAGE', 'läuft');
			}
		}

		return $result;
	}
}

?>
Die Datei heißt _CategoryDescriptionJsonContentView.inc.php und liegt in

/GXModules/bork_theme/ws7theme/Shop/Overloads/CategoryDescriptionBottomThemeContentView/

Das wird komplett ignoriert - auch wenn ich Syntaxfehler habe etc, keine Auswirkung...

Gibt es public function _assignCategoryData() nicht, oder ist der Dateiname falsch oder im falschen Ordner abgelegt?

Re: Was mache ich falsch? Überladung der unteren Kategoriebeschreibung

Verfasst: 14 Dez 2025, 15:30
von Dominik Späte
Burkhard hat geschrieben: 14 Dez 2025, 14:32 Gibt es public function _assignCategoryData() nicht
Jo dat. In der GXMainComponents/View/ThemeContentViews/categories/CategoryDescriptionBottomThemeContentView.inc.php gibt es nur die public function __construct() und sonst nichts.