Jump to content

Show full url


Tamade

Recommended Posts

How should I put in Seo and Urls so that when I click on the categories it shows me all the previous categories?

I want it to put:

/ Bedrooms / tables

currently out:

/ tables

in the products it puts it well:

/ bedrooms / tables / table without legs

classic

v1.7.6.5

Thank you

Link to comment
Share on other sites

PRESTASHOP 1.7

I see you're worried about it.

./classes ->

Link.php

public function getCategoryLink(
        $category,
        $alias = null,
        $idLang = null,
        $selectedFilters = null,
        $idShop = null,
        $relativeProtocol = false
    ) {
        $dispatcher = Dispatcher::getInstance();

        if (!$idLang) {
            $idLang = Context::getContext()->language->id;
        }

        $url = $this->getBaseLink($idShop, null, $relativeProtocol) . $this->getLangLink($idLang, null, $idShop);

        // Set available keywords
        $params = array();

        
        if (!is_object($category)) {
            $params['id'] = $category;
        } else {
            $params['id'] = $category->id;
        }

        // Selected filters is used by the module ps_facetedsearch
        $selectedFilters = null === $selectedFilters ? '' : $selectedFilters;

        if (empty($selectedFilters)) {
            $rule = 'category_rule';
        } else {
            $rule = 'layered_rule';
            $params['selected_filters'] = $selectedFilters;
        }

        if (!$alias) {
            $category = $this->getCategoryObject($category, $idLang);
        }
        
        
        $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;

        
        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'));
        }
        
        /* added subcategories */
		$cats = array();
        $categ = new Category($params['id']);    
		foreach ($categ->getParentsCategories($idLang) as $cat){    
			if (!in_array($cat['id_category'], array(1, 2, $categ->id)))    
			$cats[] = $cat['link_rewrite'];    
        }
        
        $params['subcategories'] = implode('/', array_reverse($cats));

        return $url . Dispatcher::getInstance()->createUrl($rule, $idLang, $params, $this->allow, '', $idShop);
    }

Dispatcher.php

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

 

SEO & URL

obrazek.png.503052fe26aae6dbc3d82aa0aa4476a0.png

Edited by Guest (see edit history)
Link to comment
Share on other sites

1. add this two file to ./override/classes/ folder

Link.php

Link.php

Dispatcher.php

Dispatcher.php

 

2. Admin -> Shop parameters -> Traffic & SEO

a) add {subcategories:/} Route to category

obrazek.png.503052fe26aae6dbc3d82aa0aa4476a0.png

b) disable Friendly URL

c) enable Friendly URL

DONE !

Thank you for giving me a like clicking on the gray heart below the posts 😉

Edited by Guest (see edit history)
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...