问题
A prestashop website at version 1.4.1.4 was working with category.php
file for category pages. The update to 1.6.0.6 unfortunatley deleted that file because it has been considered as deprecated. (URL structure changed after CMS update)
One consequence is the change in the URL structure.
from:
url/category.php?id_category=6
to :
url/index.php?id_category=6&controller=category&id_lang=2
So now, the first URL structure is giving 404.
The question:
We don't know why all the category pages are working fine with the new strucure, except the page for Home
(acceuil) category (the global parent category for all website categories). This home
category page is giving 404 even with the new structure. In other words, the following url is not working:
url/index.php?id_category=1&controller=category&id_lang=2
If I am not wrong, Prestashop gives id=1 by default to this home
category? What is going wrong in your point of you? Any insights are highly appreciated.
Edit based on Prestashop-Developper.co answer
When I checked my database in PhpMyAdmin:
After update from 1.4.1.4 to 1.6.0.6:
I found neither a category with id=0 nor a category with id=2. I only find the category Home with id=1 and category Root with id=104. Root is parent of Home, but the field is_root_category
for Home is set to 1!!!! I am really not understanding anything.
Before update from 1.4.1.4 to 1.6.0.6:
There is no Root category at all, and there is no is_root_category
field at all.
Note: These observations are based on the tables : ps_category, ps_category_group, ps_category_product, ps_category_shop before and after updtate =between 1.4.1.4 to 1.6.0.6.
回答1:
In PrestaShop 1.6 the Root & Home categories always return 404 (in PS 1.5 only Root returns 404), if you need to change that for Home category you must create an override for CategoryController.
Note that in PrestaShop 1.4 you have "Home" with id=1 and since 1.5 you have "Root" with id=1 and "Home" with id=2. Find the ID of the Home category.
Create file CategoryController.php in /override/controllers/front/ with the following content:
<?php
class CategoryController extends CategoryControllerCore
{
public function canonicalRedirection($canonicalURL = '')
{
if (Tools::getValue('live_edit'))
return ;
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop() || $this->category->id == Configuration::get('PS_ROOT_CATEGORY'))
{
$this->redirect_after = '404';
$this->redirect();
}
if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category))
FrontController::canonicalRedirection($this->context->link->getCategoryLink($this->category));
}
}
Make sure you delete /cache/class_index.php after creating the above file.
来源:https://stackoverflow.com/questions/24023989/home-category-page-not-working-after-update