prestashop类别/子类别使cms 404错误

时间:2018-08-23 02:49:14

标签: prestashop-1.6

我在本地环境中与prestashop合作,然后开设了一家商店,出现的问题如下。

购买该模块以删除网址ID:Module Pretty URLs,效果完美。

然后我要显示父类别的子类别的URL,例如:example.com/women/jeans

使用以下代码实现此目标,修改文件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]*'),
            ),
        ),

在Prestashop管理员中,将{categories:/}{rewrite}添加到类别的SEO / URL。

文件覆盖/类/Link.php

public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false)
    {
        if (!$id_lang) {
            $id_lang = Context::getContext()->language->id;
        }
        $url = $this->getBaseLink($id_shop, null, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
        if (!is_object($category)) {
            $category = new Category($category, $id_lang);
        }
        $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);

        $selected_filters = is_null($selected_filters) ? '' : $selected_filters;
        if (empty($selected_filters)) {
            $rule = 'category_rule';
        } else {
            $rule = 'layered_rule';
            $params['selected_filters'] = $selected_filters;
        }
        $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));
            }
        }

        $r_url = $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop);
        return $r_url;
    }

但是要做到这一点,CMS的所有页面都会向我抛出404,而不是可以。

0 个答案:

没有答案