opencart seo friendly urls
opencart has built in seo friendly url but that’s for products only as far as i can tell. and you have to actually type out the terms. so i took it upon myself to make it friendlier and more automagic.
this is for opencart v1.4.8b
the format of url we are trying to achieve is:
/product/:product_id/:product_title
so it would look like something like /product/1/girls-gone-wild
change catalog/model/tool/seo_url.php
UPDATED: includes all urls now and added file for download (Catalog.rar (38))
-
public function rewrite($link)
-
{
-
if ($this->config->get(‘config_seo_url’))
-
{
-
-
$url = ”;
-
-
-
-
switch($data[‘route’])
-
{
-
case ‘product/product’:
-
$this->load->model(‘catalog/product’);
-
$product = $this->model_catalog_product->getProduct($data[‘product_id’]);
-
//get product categories
-
$path = ”;
-
{
-
$categories = $this->model_catalog_product->getCategories($product[‘product_id’]);
-
{
-
$path = $this->model_catalog_product->getPath($categories[’0′][‘category_id’]);
-
}
-
}
-
else
-
{
-
$path = $this->request->get[‘path’];
-
}
-
$url = $this->config->get(‘config_url’).‘product/’.$data[‘product_id’].‘/’.(!empty($path)?$path.‘/’:”).$this->toSlug($product[‘name’]);
-
break;
-
case ‘product/category’:
-
$this->load->model(‘catalog/category’);
-
$this->load->model(‘catalog/product’);
-
$path = ”;
-
{
-
$path = $this->model_catalog_product->getPathUp($categoryId[’0′]);
-
}
-
-
$category = $this->model_catalog_category->getCategory($categoryId);
-
$url = $this->config->get(‘config_url’).‘category/’.($path?$path:$data[‘path’]).‘/’.$this->toSlug($category[‘name’]);
-
break;
-
case ‘information/information’:
-
$this->load->model(‘catalog/information’);
-
$info = $this->model_catalog_information->getInformation($data[‘information_id’]);
-
$url = $this->config->get(‘config_url’).‘information/’.$data[‘information_id’].‘/’.$this->toSlug($info[‘title’]);
-
break;
-
default:
-
$url = $this->config->get(‘config_url’).$data[‘route’];
-
-
break;
-
}
-
{
-
-
$query = ”;
-
-
if ($data)
-
{
-
foreach ($data as $key => $value)
-
{
-
$query .= ‘&’ . $key . ‘=’ . $value;
-
}
-
-
if ($query)
-
{
-
}
-
}
-
return $url.$query;
-
}
-
return $link;
-
-
} else
-
{
-
return $link;
-
}
-
}
-
-
public function toSlug($name)
-
{
-
return $name;
-
}
then change catalog/controller/common/seo_url.php
-
public function index()
-
{
-
{
-
-
{
-
switch($parts[0])
-
{
-
case ‘category’:
-
$this->request->get[‘path’] = $parts[1];
-
break;
-
case ‘product’:
-
$this->request->get[‘product_id’] = $parts[1];
-
$this->request->get[‘path’] = $parts[2];
-
break;
-
case ‘information’:
-
$this->request->get[‘information_id’] = $parts[1];
-
break;
-
default:
-
$this->request->get[‘route’] = $this->request->get[‘_route_’];
-
break;
-
}
-
}
-
else
-
{
-
foreach ($parts as $part)
-
{
-
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = ‘" . $this->db->escape($part) . "’");
-
-
if ($query->num_rows)
-
{
-
-
if ($url[0] == ‘product_id’)
-
{
-
$this->request->get[‘product_id’] = $url[1];
-
}
-
-
if ($url[0] == ‘category_id’)
-
{
-
{
-
$this->request->get[‘path’] = $url[1];
-
} else
-
{
-
$this->request->get[‘path’] .= ‘_’ . $url[1];
-
}
-
}
-
-
if ($url[0] == ‘manufacturer_id’)
-
{
-
$this->request->get[‘manufacturer_id’] = $url[1];
-
}
-
-
if ($url[0] == ‘information_id’)
-
{
-
$this->request->get[‘information_id’] = $url[1];
-
}
-
} else
-
{
-
$this->request->get[‘route’] = ‘error/not_found’;
-
}
-
}
-
}
-
-
{
-
$this->request->get[‘route’] = ‘product/product’;
-
{
-
$this->request->get[‘route’] = ‘product/category’;
-
{
-
$this->request->get[‘route’] = ‘product/manufacturer’;
-
{
-
$this->request->get[‘route’] = ‘information/information’;
-
}
-
-
{
-
return $this->forward($this->request->get[‘route’]);
-
}
-
}
-
}

