PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to create Category / Subcategory Friendly URL in PrestaShop?

 June 30, 2022     prestashop     No comments   

Issue

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!


Solution

This question was answered on the PrestaShop forum. You can find it here http://www.prestashop.com/forums/topic/220017-category-subcategory-url/

The solution - add this changes to the fallowing classes

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));


Answered By - psu
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing