Post by abmcr » 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

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');
    	}
and in the getForm this

Code: Select all

$this->data['error_keyword'] = @$this->error['keyword'];
4) in each view change this

Code: Select all

<td><input type="text" name="keyword" value="<?php echo $keyword; ?>" />
       
          </td>
in

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>

New member

Posts

Joined
Wed Jun 03, 2009 11:38 pm

Post by abmcr » Wed Aug 05, 2009 4:09 pm

I need to integrate my suggestion because the prev code has a bug if you try to edit an exeisting record and you want mantain the SEO URL
in the model the function is

Code: Select all

public function validateUrlAlias($keyword,$query="") {
		$query = $this->db->query("SELECT COUNT(url_alias_id) AS total FROM " . DB_PREFIX . "url_alias WHERE keyword='$keyword' AND query<>'$query'");
		return $query->row['total'];
	}
In admin/controller/catalog/category.php function validateForm add

Code: Select all

if (($this->model_tool_seo_url->validateUrlAlias($this->request->post['keyword'],"category_id=".$this->request->get['category_id']))||((strlen($this->request->post['keyword']) < 3))) {
      		$this->error['keyword'] = $this->language->get('error_keyword');
    	}
In admin/controller/catalog/information.php function validateForm add

Code: Select all

if (($this->model_tool_seo_url->validateUrlAlias($this->request->post['keyword'],"information_id=".$this->request->get['information_id']))||((strlen($this->request->post['keyword']) < 3))) {
      		$this->error['keyword'] = $this->language->get('error_keyword');
    	}
In admin/controller/catalog/manufacturer.php function validateForm add

Code: Select all

if (($this->model_tool_seo_url->validateUrlAlias($this->request->post['keyword'],"manufacturer_id=".$this->request->get['manufacturer_id']))||((strlen($this->request->post['keyword']) < 3))) {
      		$this->error['keyword'] = $this->language->get('error_keyword');
    	}
In admin/controller/catalog/product.php function validateForm add

Code: Select all

if (($this->model_tool_seo_url->validateUrlAlias($this->request->post['keyword'],"product_id=".$this->request->get['product_id']))||((strlen($this->request->post['keyword']) < 3))) {
      		$this->error['keyword'] = $this->language->get('error_keyword');
    	}

New member

Posts

Joined
Wed Jun 03, 2009 11:38 pm

Post by deejayp » Sun Feb 28, 2010 1:18 am

sorry, but for the version 1.4 there's a solution !? :(

Newbie

Posts

Joined
Sat Feb 27, 2010 4:09 pm

Post by abmcr » Sun Feb 28, 2010 1:23 am

I not know the architecture of 1.4: may be it is possible to edit the code. :-[

New member

Posts

Joined
Wed Jun 03, 2009 11:38 pm
Who is online

Users browsing this forum: No registered users and 44 guests