Ok, think I've sorted it.
Please note, I've modified catalog\controller\common\SEO_URL.php from version 1.4.9.3 - just copy paste the entire contents below into the file (after making a backup).
Code: Select all
<?php
class ControllerCommonSeoUrl extends Controller {
public function index() {
if (isset($this->request->get['_route_'])) {
$parts = explode('/', $this->request->get['_route_']);
foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
if ($query->num_rows) {
$url = explode('=', $query->row['query']);
if ($url[0] == 'product_id') {
$this->request->get['product_id'] = $url[1];
}
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$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';
return; // If ANY part of the URL fails, RETURN so we show a 404
// otherwise, if the NEXT part of the url is valid, we 'skip' the 404! Bad.
}
}
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
if($this->VerifyCategoryPath($this->request->get['path']) == true){
$this->request->get['route'] = 'product/category';
}
else{
$this->request->get['route'] = 'error/not_found';
}
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
}
if (isset($this->request->get['route'])) {
return $this->forward($this->request->get['route']);
}
}
}
// Passed value such as "51" or "35_36_51" - with the upper most category being first
public function VerifyCategoryPath($catIds){
// if its only one level deep
if(strpos($catIds,"_") == false){
return $this->CheckCategoryParent($catIds, 0);
}
$parts = explode('_', $catIds);
$prevParentId = 0;
foreach ($parts as $part) {
if($this->CheckCategoryParent($part, $prevParentId) == false){
return false;
}
$prevParentId = $part;
}
return true;
}
public function CheckCategoryParent($catId, $parentid){
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE parent_id = '" . $parentid . "' AND category_id = '".$catId."'");
if ($query->num_rows) {
return true;
}
return false;
}
}
?>
Overview
After line 33:
Code: Select all
$this->request->get['route'] = 'error/not_found';
add:
Code: Select all
return; // If ANY part of the URL fails, RETURN so we show a 404 otherwise, if the NEXT part of the url is valid, we 'skip' the 404! Bad.
Change line 42:
Code: Select all
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
To this:
Code: Select all
} elseif (isset($this->request->get['path'])) {
if($this->VerifyCategoryPath($this->request->get['path']) == true){
$this->request->get['route'] = 'product/category';
}
else{
$this->request->get['route'] = 'error/not_found';
}
And at the bottom of the file, just before:
Put this:
Code: Select all
// Passed value such as "51" or "35_36_51" - with the upper most category being first
public function VerifyCategoryPath($catIds){
// if its only one level deep
if(strpos($catIds,"_") == false){
return $this->CheckCategoryParent($catIds, 0);
}
$parts = explode('_', $catIds);
$prevParentId = 0;
foreach ($parts as $part) {
if($this->CheckCategoryParent($part, $prevParentId) == false){
return false;
}
$prevParentId = $part;
}
return true;
}
public function CheckCategoryParent($catId, $parentid){
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE parent_id = '" . $parentid . "' AND category_id = '".$catId."'");
if ($query->num_rows) {
return true;
}
return false;
}
Seems to work fine. I've not had chance to test it fully yet as its a bit late here...