SEO URL integration code
Posted: Mon Aug 03, 2009 5:49 pm
In the original code of OpenCart 1.3 it is possible to insert 2 or more SEO URL equal and this crash the application.
I have made a little modification to the code
1) edit the admin/model/tool/seo_url.php file in
2) in each language file in the admin/language/catalog section add this line
3) in admin/controller/catalog in each controller as a keyword tag add in the ValidateForm function this
and in the getForm this
4) in each view change this
in
I have made a little modification to the code
1) edit the admin/model/tool/seo_url.php file in
Code: Select all
<?php
//class ModelUrlAlias extends Model {
class ModelToolSeoUrl extends Model {
public function addUrlAlias($query, $keyword) {
$this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'category_id=" . (int)$category_id. "'");
$this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'category_id=" . (int)$category_id. "', keyword = '" . $this->db->escape($data['keyword']) . "'");
}
public function deleteUrlAlias($query) {
$this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'category_id=" . (int)$category_id. "'");
}
//verifica se URL sia univoco
//return FALSE if keyword is
public function validateUrlAlias($keyword) {
$query = $this->db->query("SELECT COUNT(url_alias_id) AS total FROM " . DB_PREFIX . "url_alias WHERE keyword='$keyword'");
return $query->row['total'];
}
}
?>
2) in each language file in the admin/language/catalog section add this line
Code: Select all
$_['error_keyword'] = 'Attenzione: SEO URL non univoco o non valido!';
3) in admin/controller/catalog in each controller as a keyword tag add in the ValidateForm function this
Code: Select all
$this->load->model('tool/seo_url');
if (($this->model_tool_seo_url->validateUrlAlias($this->request->post['keyword']))||((strlen($this->request->post['keyword']) < 3))) {
$this->error['keyword'] = $this->language->get('error_keyword');
}
Code: Select all
$this->data['error_keyword'] = @$this->error['keyword'];
Code: Select all
<td><input type="text" name="keyword" value="<?php echo $keyword; ?>" />
</td>
Code: Select all
<td><input type="text" name="keyword" value="<?php echo $keyword; ?>" />
<?php if (@$error_keyword) { ?>
<span class="error"><?php echo $error_keyword ?></span>
<?php } ?>
</td>