Jump to content
  • 0

Kategorie als Startseite benutzen


katasun

Question

Bei einem lokal installierten Prestashop, Version 8.17 möchte ich gerne als Startseite direkt eine Kategorieseite aufrufen.

Dazu gibt es viele Anleitungen für die verschiedenen Versionen von Prestashop. Ich habe eine Override von IndexController eingerichtet und Beispielcode aus dem Netz eingetragen. Danach habe ich im Backend den Cache gelöscht und eine Neukompilierung erzwungen.

Dies hat aber keine Änderung bei Shop gezeigt. Cache Dateien auf Dateiebene habe ich nicht gefunden. Kennt jemand eine Anleitung oder kann mir jemand meinen Fehler nennen?

Ich sollte mindestens eine Fehlermeldung bekommen, falls der Code falsch ist. Ich bin Anfänger beim Prestashop.

 

 

<?php
class IndexController extends CategoryControllerCore
{
    public $php_self = 'index';
    public function init()
    {
        $_GET['id_category'] = (int) 12; // Replace 12 with the actual ID of your category
        parent::init();
    }
    public function initContent()
    {
        parent::initContent();
    }
}
?>

 

 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Ich kenne mich da zu wenig aus, normalerweise extended eine class IndexController ja IndexControllerCore, aber vielleicht geht das auch so, du hättest ja mal die Anleitung verlinken können, dann kann man das leichter beurteilen.

Der einfachste Weg müßte eine Umleitung in der .htaccess sein.

Link to comment
Share on other sites

  • 0

Du musst keine PrestaShop-Controller ändern, um deine Startseite auf eine bestimmte Kategorie umzuleiten.
Füge dies in deine .htaccess ein (URL der Kategorie entsprechend anpassen):

RewriteEngine On RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^$ /12-category-name [R=301,L]

Für eine temporäre Weiterleitung benutze [R=302,L].
Diese Methode ist einfach, rückgängig zu machen und funktioniert für alle Besucher.

Link to comment
Share on other sites

  • 0

Vielen Dank für die Antwort. Ich habe ein die Suche bei Google benutzt und dann wurde mir dieses Beispiel an Code angezeigt. Ich hatte zumindest eine Fehlermeldung erwartet.

Danke für den Hinweis mit Rewrite, ich bin ganz neu im Shop und dachte es gibt da eine relativ einfache Möglichkeit, eine Landingpage auszuwählen.

Falls ich eine einfache Lösung finde, werde ich diese hier posten.

Gruss Katasun

Link to comment
Share on other sites

  • 0
5 hours ago, katasun said:

Thank you for the answer. I used a Google search and then this sample code came up. I was expecting at least an error message.

Thanks for the tip about rewrite. I'm brand new to the shop and thought there would be a relatively easy way to select a landing page.

If I find a simple solution, I will post it here.

Greetings Katasun

I am sure Igave you the most simple solution. 😀  

Link to comment
Share on other sites

  • 0
vor 16 Stunden schrieb katasun:

Ich habe ein die Suche bei Google benutzt und dann wurde mir dieses Beispiel an Code angezeigt.

Am Anfang der Ergebnisse wird bei Google jetzt meist eine KI-Antwort angezeigt, die fantasiert manchmal ziemlich rum ...

Also immer nur nach echten Quellen schauen!

Ungültige oder an einer falschen Stelle stehende PHP-Anweisungen erzeugen normalerweise keine Fehlermeldung, sondern werden einfach ignoriert. Das mit der .htaccess ist allerdings sowieso der einfachere Weg, wenn man den richtigen Code hat.

Link to comment
Share on other sites

  • 0

Danke für die Tipps,

das es nicht funktioniert hat, lag an mir. Es gab ein Berechtigungsproblem an den Dateien. Dadurch wurde der Cache anscheinend nicht richt gelöscht.

Dem Hinweis mit der KI stimme ich zu, aber ich hatte wenigsten eine Fehlermeldung erwartet.

Die Umleitung in Kürze:

Ordner anlegen :  prestashop_root/override/controllers/front/IndexController.php

In der Datei IndexController.php soll stehen:

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */


   class IndexController extends CategoryControllerCore {
       public $php_self = 'index';
       public function init() {
           $_GET['id_category'] = 3; // Replace '2' with the desired category ID
           parent::init();
       }
       public function initContent() {
           parent::initContent();
       }
   }

Gruss Katasun

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...