Jump to content

Changing the Routing for Catagory controller in Presta 8.1 ? Overriding Dispatcher.php no longer works ?


Pedram

Recommended Posts

Hello.

I'm upgrading my site from 1.7 to 8.1 (working on a copy of my site on localhost atm)

There was around a hundred modules, some auto upgraded and some i manually upgraded and bug fixed all to work on 8.1

the only one I could not fix was a SEO module that changed the Categories from the default being {id}-{Category_Name} into  /Category-parent/Category-name/

So I checked on how it did this, and I notice it did it by overriding the Dispatcher.php file that can be found in the "Classes" folder.

First I tried to fix that, but after a few try, I wanted to check if the Override itself is the problem or not.

So I first went and removed that module's override file and then directly edited the Dispatcher.php file from Prestashop core files.

\classes\Dispatcher.php

https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Dispatcher.php#L63

but no matter what I change, it actually won't change the routing...

So at this point I'm not sure if the problem is the module's override, rather it might be Presta 8 is not using this routing code anymore ? or is it overwriting this somewhere else ? is there any clue that could help me here ?

 

I have made custom routing modules before, so I'm going on by that same assumption here.

since when I made custom routing for my module before, I simply set the rule to the url pattern I wanted it to show and it worked. but here it wont work by editing the rule section. making me suspect it might be a new Presta 8 change.

We got this :

        'category_rule' => [
            'controller' => 'category',
            'rule' => '{id}-{rewrite}',
            'keywords' => [
                'id' => ['regexp' => '[0-9]+', 'param' => 'id_category'],
                'rewrite' => ['regexp' => self::REWRITE_PATTERN],
                'meta_keywords' => ['regexp' => '[_a-zA-Z0-9-\pL]*'],
                'meta_title' => ['regexp' => '[_a-zA-Z0-9-\pL]*'],
            ],
        ]

the rule being {id}-{rewrite} is basically what will show up in front office.

So just for testing, I made it like this :

        'category_rule' => [
            'controller' => 'category',
            'rule' => 'categorytest/{id}-{rewrite}',
            'keywords' => [
                'id' => ['regexp' => '[0-9]+', 'param' => 'id_category'],
                'rewrite' => ['regexp' => self::REWRITE_PATTERN],
                'meta_keywords' => ['regexp' => '[_a-zA-Z0-9-\pL]*'],
                'meta_title' => ['regexp' => '[_a-zA-Z0-9-\pL]*'],
            ],
        ]

but nothing actually happened.

it still works same as before.

Address is still "MySite.com/id-categoryname" in my site.

it does not even fail to load or any error, it works as if my change here is overwritten back to default somewhere else.

but this code is not completely unused either, coz if I simply remove it or change the route name (category_rule), then the whole rewriting for categories simply stop working and the url change back to the original "index.php?controller=category_rule&id={id}&rewrite={Name}"

So this is indeed being used by prestashop to pick up the rule for rewriting the categories... but the "rule" section of it seems to not matter what edit i make, always stay the same...

 

 

So Long story short,

Any Idea where I need to edit to make fix my categories routing ?

or I could simply delete this old 3rd party module and make my own if there is a better, newly recommended way of me changing my category routing from the default to "/category-parent/category-name" type of address.

Any Advice is appreciated.

Thanks.

Link to comment
Share on other sites

Okay, so I got this to work somehow.

The problem is, I'm not sure how I got it to work in the end...

My progress last night lead me to checking and working on the loadRoutes function inside Dispatcher.php which might redefine the "rule" value of the route, but I didn't change anything yet and sleep.

Today I just started by resetting and disable and re-enabling a bunch of SEO modules and then it just started working by itself... without me changing anything.

 

So I assume it was a weird problem happening due to the auto upgrading from 1.7 to 8.1 and it somehow fixed itself after something got reset somewhere.

Still if anyone got any advice on anything in this topic or something I might have gotten wrong, feel free to comment, I'm always open to learn for the future :D

Thanks.

Link to comment
Share on other sites

it might have been. Thanks.

I did delete the Prod and Dev folder before a few time after the update from 1.7 to 8.1.

but I didn't do any cache cleaning while editing for this problem yesterday.

mostly coz I thought mainly the .js files and sometimes .tpl files are cached and need cleaning and didn't realize .php files might need it too.

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...