Jump to content

Recommended Posts

Hi,

 

I have a question about formatting the friendly URL for category and subcategory and getting the matching products. I am using PrestaShop 1.5.2.0

 

Let's say we have a structure like this:

 

Category 1

- Spare Parts

- Accessories

 

 

Category 2

- Chips

- Accessories

 

I want to display the link like this: /category-1/accessories and to display the products from category 1->accessories. How can I achieve this?

 

The current behavior is when I click on accessories, being in category 1, the link is /accessories and the products that are displayed belong from both /category-1/accessories and /category-2/accessories

 

Thanks!

Share this post


Link to post
Share on other sites

Hi,

 

Here is solution.

 

//Change in classes/Dispatcher.php

 

//line number 60

 

'category_rule' => array(

'controller' => 'category',

'rule' => '{category:/}{id}-{rewrite}/',

'keywords' => array(

'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'),

'category' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

),

),

 

these two bold lines not there in current file

 

//classes/Link.php

 

line number 155

 

just update this function

 

 

 

public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null)

{

if (!$id_lang)

$id_lang = Context::getContext()->language->id;

$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);

 

if (!is_object($category))

$category = new Category($category, $id_lang);

 

// Set available keywords

$params = array();

$params['id'] = $category->id;

$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;

$params['meta_keywords'] = Tools::str2url($category->meta_keywords);

$params['meta_title'] = Tools::str2url($category->meta_title);

 

 

$pcategory= new Category($category->id_parent, $id_lang);

if($category->id_parent!=1 && $category->id_parent!=2)

$params['category'] = $pcategory->link_rewrite;

 

// Selected filters is used by the module blocklayered

$selected_filters = is_null($selected_filters) ? '' : $selected_filters;

 

if (empty($selected_filters))

$rule = 'category_rule';

else

{

$rule = 'layered_rule';

$params['selected_filters'] = $selected_filters;

}

 

return $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow);

}

 

 

 

 

got to admin Preferences->seo & Url

 

Change Route to category to this

 

{category:/}{id}-{rewrite}/

 

 

 

 

This if my first reply to prestashop forum.

 

I am working on prestashop from last 2 and half year.

 

I will keep updating forum.

 

Thanks

Share this post


Link to post
Share on other sites

Not all subdirectory displays.

Product: my.com/zapchasti/zapchasti-dlja-apple/displei-/3-displej-dlja-ipad2.html

Category: my.com/zapchasti-dlja-apple/displei-/

Edited by Dmit

Share this post


Link to post
Share on other sites

It works till first parent only not recursive

 

For recursive (Editing the lines posted by polaram):

==============CLASSES/Dispatcher.php===============

'rule' => '{categories:/}{id}-{rewrite}/',
'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'),

 

==============CLASSES/Link.php=====================

$cats = array();
foreach ($category->getParentsCategories() as $cat)
if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL
$cats[] = $cat['link_rewrite'];
$params['categories'] = implode('/', array_reverse($cats));

Edited by doubleD
  • Like 2

Share this post


Link to post
Share on other sites

i could not find the scheme of urls...!

 

i am able to see only these things in prestashop1.5.3

Set up URLs :

Set shop URL"

Robots file generation

 

Friendly URL and Automatically redirect to Canonical URL should be set to 'YES'

Edited by doubleD

Share this post


Link to post
Share on other sites

I'm not getting it to work. This is already in my dispatcher.php

 

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

 

Should i replace 'rule' => '{id}-{rewrite}', with

'rule' => '{categories:/}{id}-{rewrite}/',

?

Share this post


Link to post
Share on other sites

I'm not getting it to work. This is already in my dispatcher.php

 

Should i replace 'rule' => '{id}-{rewrite}', with

'rule' => '{categories:/}{id}-{rewrite}/',

?

 

Yes.

In Dispatcher in should be:

 

 

In Link.php in should be:

 

// Set available keywords

$params = array();

$params['id'] = $category->id;

$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;

$params['meta_keywords'] = Tools::str2url($category->meta_keywords);

$params['meta_title'] = Tools::str2url($category->meta_title);

 

$cats = array();

foreach ($category->getParentsCategories() as $cat)

if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL

$cats[] = $cat['link_rewrite'];

$params['categories'] = implode('/', array_reverse($cats));

 

// Selected filters is used by the module blocklayered

$selected_filters = is_null($selected_filters) ? '' : $selected_filters;

 

 

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

 

And route should be {categories:/}{id}-{rewrite}/

Share this post


Link to post
Share on other sites

I don't really understand it. Now I get this:

http://www.wifinetwe...es=access-point

 

And I want http://www.wifinetwe...s-point/indoor/

 

How should I do that?

 

I also get the message: The route {categories:/}{id}-{rewrite}/ is not valid

 

This is my dispatcher

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

 

And this is in link.php:

public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null)
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!is_object($category))
$category = new Category($category, $id_lang);
// Set available keywords
$params = array();
$params['id'] = $category->id;
$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
$params['meta_keywords'] = Tools::str2url($category->meta_keywords);
$params['meta_title'] = Tools::str2url($category->meta_title);
$cats = array();
foreach ($category->getParentsCategories() as $cat)
if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL
$cats[] = $cat['link_rewrite'];
$params['categories'] = implode('/', array_reverse($cats));
// Selected filters is used by the module blocklayered
$selected_filters = is_null($selected_filters) ? '' : $selected_filters;

Edited by BuB

Share this post


Link to post
Share on other sites

You need to make changes to override/classes/Dispatcher.php

 

'category_rule' => array(

'controller' => 'category',

'rule' => '{categories:/}{rewrite}/',

'keywords' => array(

'id' => array('regexp' => '[0-9]+'),

'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'category_rewrite'),

'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'),

'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

),

),

 

The Link php changes are OK

Then go to Seo&Url and place

{categories:/}{rewrite}/ instead of {categories:/}{id}-{rewrite}/

Share this post


Link to post
Share on other sites

I'm getting the numbers again I removed with the removeURL solution. Dispatcher.php and link.php as mentioned obove, but it's not working as you can see on http://www.wifinetwerken.nl/

 

EDIT: missed your last post, gonna try it now

Edited by BuB

Share this post


Link to post
Share on other sites

I'm getting the numbers again I removed with the removeURL solution. Dispatcher.php and link.php as mentioned obove, but it's not working as you can see on http://www.wifinetwerken.nl/

 

EDIT: missed your last post, gonna try it now

 

 

Still not working. Can it have something to do with the fact that I'm also using this http://www.prestasho...number-for-v15/ (vershion 0.22).

I 've noticed there is a 0.23 version posted by lapy90 which already includes the override...

Share this post


Link to post
Share on other sites

Hi,

 

How to add .html in category url and delete /content/ in cms url!!

 

Ho to delete /fr/ if fr is the default language or /en/ en is the default

 

aqwzsx159

Share this post


Link to post
Share on other sites

Hi,

 

How to add .html in category url and delete /content/ in cms url!!

 

Ho to delete /fr/ if fr is the default language or /en/ en is the default

 

aqwzsx159

Prestashop 1.5...

 

Q: How to add .html in category?

A: This one won't be easy to do... For now(as i know), the category link should end with slash ("/") sign at the end of url...

 

Q: How to delete /content/ in cms url?

A: Go to BackOffice->Settings->Seo&URL and change Route to CMS to

{rewrite}/

 

Q: How to delete /fr/ if fr is the default language or /en/ if en is the default language ... ?

A: No answer for this one too... But i agree it's a really good idea

Edited by doubleD

Share this post


Link to post
Share on other sites

Hello doubleD,

 

Q: How to delete /content/ in cms url?

A: Go to BackOffice->Settings->Seo&URL and change Route to CMS to

that don't work !

 

aqwzsx159

Share this post


Link to post
Share on other sites

Hello doubleD,

 

Q: How to delete /content/ in cms url?

A: Go to BackOffice->Settings->Seo&URL and change Route to CMS to

that don't work !

 

aqwzsx159

Is there any live link to see?

Prestashop 1.5.3.1 - > link

Edited by doubleD

Share this post


Link to post
Share on other sites

Is there any live link to see?

Prestashop 1.5.3.1 - > link

 

in 1.5.2 that don't work!!!! and {id}-{rewrite}/ id is required

Edited by aqwzsx159

Share this post


Link to post
Share on other sites

in 1.5.2 that don't work!!!! and {id}-{rewrite}/ id is required

Update to the latest vesrsion or post a screenshot, link, live website link ...

Share this post


Link to post
Share on other sites

work for PS 1.5.4.1???

 

It seems it doesn't work on 1.5.4.1. Made it to rewrite them as I wish, but it gives a 404 error :).

Share this post


Link to post
Share on other sites

Great post, thank you!! it works well on PS 1.5.6. but {id} needs to stay there.

 

Do you know a way that root "Home" could also appear in the url ? I mean .../home/category/subcategory 

As far as "Home" name can be, multilingual, changed by a key word, we believe this could also help with SEO.

Share this post


Link to post
Share on other sites

Help! I was making changes to a site based on this string and now the entire site is down, and I can't even access the admin panel. I tried reverting all the changes but I don't see that fixing anything...

 

 

__

Nevermind it was cached.

Edited by rrosenblatt88

Share this post


Link to post
Share on other sites

Help! I was making changes to a site based on this string and now the entire site is down, and I can't even access the admin panel. I tried reverting all the changes but I don't see that fixing anything...

 

 

__

Nevermind it was cached.

 

Erase .htaccess and undo changes on override and try again

Share this post


Link to post
Share on other sites

Update to the latest vesrsion or post a screenshot, link, live website link ...

hello there!...awesome thread, but nobody mentioned subcategory and category urls. when I set up everything like you said, product page is ok, but when I visit category page it shows me

 

home/categoryname-id/?categories=

 

and for subcategory

 

home/subcategoryname-id/?categories=

 

and it should be

for cat

home/categoryname/

 

for subcat

home/categoryname/subcategoryname/

 

 

thank you!

Share this post


Link to post
Share on other sites

This solution works fine with Prestashop 1.6 , but I have one question.

I have product pages: {rewrite}/p{id}/

And category pages: {categories:/}{rewrite}/c{id}/

And then I have URL for exaple: http://site.com/product-ipod/p1780/ - everything works fine, but then i use http://site.com/product-ipod/p1780 - without "/" - i have 404 error.

I can make the rule in htaccess file ta add "/" at the end of every url , but i have many pages in index like prices-drop, new-products and other tpl pages without "/" . And then htaccess rule add it to utl http://site.comprices-drop/ I have 404 error. 

Can you tell me solution to make a rule - to add " / " to url if it is needed.

Share this post


Link to post
Share on other sites

hello there!...awesome thread, but nobody mentioned subcategory and category urls. when I set up everything like you said, product page is ok, but when I visit category page it shows me

 

home/categoryname-id/?categories=

 

and for subcategory

 

home/subcategoryname-id/?categories=

 

and it should be

for cat

home/categoryname/

 

for subcat

home/categoryname/subcategoryname/

 

 

thank you!

You did not add the rule in the dispatcher

'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'),

Mind the extra "/" character in the regexp as opposed to the first example on this topic.

 

Runs great with 1.6. So thanks for the solution!

Share this post


Link to post
Share on other sites

In presta 1.6.1.1 there is no longer an option to enter categories as a keyword in the Route to category section of the Backoffice. :mellow:

 

Can you guys think of a good way around this?

Share this post


Link to post
Share on other sites

Hi,

 

Here is solution.

 

//Change in classes/Dispatcher.php

 

//line number 60

 

'category_rule' => array(

'controller' => 'category',

'rule' => '{category:/}{id}-{rewrite}/',

'keywords' => array(

'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'),

'category' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

),

),

 

these two bold lines not there in current file

 

//classes/Link.php

 

line number 155

 

just update this function

 

 

 

public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null)

{

if (!$id_lang)

$id_lang = Context::getContext()->language->id;

$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);

 

if (!is_object($category))

$category = new Category($category, $id_lang);

 

// Set available keywords

$params = array();

$params['id'] = $category->id;

$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;

$params['meta_keywords'] = Tools::str2url($category->meta_keywords);

$params['meta_title'] = Tools::str2url($category->meta_title);

 

 

$pcategory= new Category($category->id_parent, $id_lang);

if($category->id_parent!=1 && $category->id_parent!=2)

$params['category'] = $pcategory->link_rewrite;

 

// Selected filters is used by the module blocklayered

$selected_filters = is_null($selected_filters) ? '' : $selected_filters;

 

if (empty($selected_filters))

$rule = 'category_rule';

else

{

$rule = 'layered_rule';

$params['selected_filters'] = $selected_filters;

}

 

return $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow);

}

 

 

 

 

got to admin Preferences->seo & Url

 

Change Route to category to this

 

{category:/}{id}-{rewrite}/

 

 

 

 

This if my first reply to prestashop forum.

 

I am working on prestashop from last 2 and half year.

 

I will keep updating forum.

 

Thanks

Hi,

 

I have followed your above steps, 

 

MY actual structure which i want:

myurl.com/maincategory/subcategory/pagename.html

 

 

Till here its working fine:

myurl.com/maincategory/subcategory/

 

After following your steps, coming below:

myurl.com/subcategory/pagename.html

 

But i want also 

myurl.com/maincategory/subcategory/pagename.html

 

 

Could you please help, Thanks

Share this post


Link to post
Share on other sites

For recursive (Editing the lines posted by polaram):

==============CLASSES/Dispatcher.php===============

'rule' => '{categories:/}{id}-{rewrite}/',
'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'),
==============CLASSES/Link.php=====================

$cats = array();
foreach ($category->getParentsCategories() as $cat)
if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL
$cats[] = $cat['link_rewrite'];
$params['categories'] = implode('/', array_reverse($cats));

Hi,

 

This code works for me but only till two level of category (i.e. home>>category>sub category). My shop has sub sub categories also. I tried to make changes as below but did not work. Either 3rd level categories are not working or product page is showing 404 error.

 

==============CLASSES/Dispatcher.php===============

'rule' => '{categories:/}{id}-{rewrite}/',

'categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),

 

I had to remove / from 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), above as when I add it the products links shows 404 error but the 3rd level category links works.

 

I also tried to make below changes to link.php by adding 3, in array of line 3 but did not work either

==============CLASSES/Link.php=====================

$cats = array();

foreach ($category->getParentsCategories() as $cat)

if (!in_array($cat['id_category'], array(1, 2, 3, $category->id)))//remove root, home and current category from the URL

$cats[] = $cat['link_rewrite'];

$params['categories'] = implode('/', array_reverse($cats));

 

Any way to work around the same code for 3 levels of category tree & not get 404 errors on product page?

 

Thanks.

Edited by abhimanyu_rishi

Share this post


Link to post
Share on other sites

Hi friend,

I read alls post and i make the changes in dispatcher.php and link.php and work fine.

But i want the same in product page   mydomain.com/maincategory/subcategory/product.

I'm modiffy in link.php getProductLink and i think i have to modify this 

 if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories', $id_shop)) {
            $params['category'] = (!$category) ? $product->category : $category;
            $cats = array();
            foreach ($product->getParentCategories($id_lang) as $cat) {
                if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) {
                    //remove root and home category from the URL
                    $cats[] = $cat['link_rewrite'];
                }
            }
            $params['categories'] = implode('/', $cats);
        }
 
 
but i put this and dont work,.... 
 
        $cats = array();
        foreach ($category->getParentsCategories() as $cat)
            if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL
              $cats[] = $cat['link_rewrite'];
              
        $params['categories'] = implode('/', array_reverse($cats));
 
 

 

Share this post


Link to post
Share on other sites

For Prestashop 1.7 (PS1.7.2.2) i managed to get the same by doing this:

in classes/Link.php add the following to getCategoryLink

        if ($dispatcher->hasKeyword('category_rule', $idLang, 'parent_categories', $idShop))
        {
            $category = $this->getCategoryObject($category, $idLang);
            //RETRIEVING ALL THE PARENT CATEGORIES
            $cats = array();
            foreach ($category->getParentsCategories($idLang) as $cat) {
                if (!in_array($cat['id_category'], array(1, 2, $category->id))) {
                    //remove root, home and current category from the URL
                    
                    //HACK, category_id is added by hand, better would be to generate the subpaths via
                    //Dispatcher but quickfix
                    $cats[] = $cat['id_category']."_".$cat['link_rewrite'];
                    
                }
            }
            
            
            //   
            //        //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?)
            $params['parent_categories'] = implode('/', array_reverse($cats));//ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER
            
        }

In classes/Dispatcher.php this replace 'category_rule' with this:

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

It's a nasty quick fix, but it does the job.

  • Like 1

Share this post


Link to post
Share on other sites

Anybody know the solution for Prestashop 1.6?

 

Thank you.

Share this post


Link to post
Share on other sites
On 25.09.2017 at 12:16 PM, Inform-All said:

For Prestashop 1.7 (PS1.7.2.2) i managed to get the same by doing this:

in classes/Link.php add the following to getCategoryLink


        if ($dispatcher->hasKeyword('category_rule', $idLang, 'parent_categories', $idShop))
        {
            $category = $this->getCategoryObject($category, $idLang);
            //RETRIEVING ALL THE PARENT CATEGORIES
            $cats = array();
            foreach ($category->getParentsCategories($idLang) as $cat) {
                if (!in_array($cat['id_category'], array(1, 2, $category->id))) {
                    //remove root, home and current category from the URL
                    
                    //HACK, category_id is added by hand, better would be to generate the subpaths via
                    //Dispatcher but quickfix
                    $cats[] = $cat['id_category']."_".$cat['link_rewrite'];
                    
                }
            }
            
            
            //   
            //        //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?)
            $params['parent_categories'] = implode('/', array_reverse($cats));//ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER
            
        }

In classes/Dispatcher.php this replace 'category_rule' with this:


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

It's a nasty quick fix, but it does the job.

 

 

Are You sure it works? I have 404 error ...

 

I've deleted this in Link.php and added Your code. PRestashop 1.7.2.2

if ($dispatcher->hasKeyword($rule, $idLang, 'meta_keywords', $idShop)) {
            $category = $this->getCategoryObject($category, $idLang);
            $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords'));
        }
        if ($dispatcher->hasKeyword($rule, $idLang, 'meta_title', $idShop)) {
            $category = $this->getCategoryObject($category, $idLang);
            $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title'));
        }

 

Share this post


Link to post
Share on other sites

Sorry for the late response, did you also rebuild the .htaccess after the changes? 
Besides what might make a problem is if you have (sub) category's with the same name. 
As i said it's a quick and nasty fix that worked for me. 

Share this post


Link to post
Share on other sites
Posted (edited)
On 2/15/2013 at 12:47 PM, cool and charming said:

were can i find this...?

 

 

got to admin Preferences->seo & Url

Vidmate iTunes Notepad++

Change Route to category to this

 

{category:/}{id}-{rewrite}/

I have a question about formatting the friendly URL for category and subcategory and getting the matching products. I am using PrestaShop 1.5.2.0

Edited by CORIYATSIA

Share this post


Link to post
Share on other sites
On 9/25/2017 at 12:16 PM, Inform-All said:

For Prestashop 1.7 (PS1.7.2.2) i managed to get the same by doing this:

in classes/Link.php add the following to getCategoryLink


        if ($dispatcher->hasKeyword('category_rule', $idLang, 'parent_categories', $idShop))
        {
            $category = $this->getCategoryObject($category, $idLang);
            //RETRIEVING ALL THE PARENT CATEGORIES
            $cats = array();
            foreach ($category->getParentsCategories($idLang) as $cat) {
                if (!in_array($cat['id_category'], array(1, 2, $category->id))) {
                    //remove root, home and current category from the URL
                    
                    //HACK, category_id is added by hand, better would be to generate the subpaths via
                    //Dispatcher but quickfix
                    $cats[] = $cat['id_category']."_".$cat['link_rewrite'];
                    
                }
            }
            
            
            //   
            //        //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?)
            $params['parent_categories'] = implode('/', array_reverse($cats));//ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER
            
        }

In classes/Dispatcher.php this replace 'category_rule' with this:


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

It's a nasty quick fix, but it does the job.

Hi, i follow your post but i obtain an error 500 :( Prestashop 1.7.4.4

Share this post


Link to post
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

×

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More