skip to Main Content

When i edit product/category how can i check if seo keyword already exist in database ? i need it for custom use

4

Answers


  1. Chosen as BEST ANSWER

    Checking for duplicate SEO

    Controller

    $url_alias_info = $this->model_catalog_url_alias->getUrlAlias($this->request->post['keyword']);
    
    if ($url_alias_info && isset($this->request->post['category_id']) && $url_alias_info['query'] != 'category_id=' . $this->request->post['category_id']) {
     $json['error'] = 'SEO exist';
    }
    

    Model

    public function getUrlAlias($keyword) {
      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($keyword) . "'");
    
      return $query->row;
    }
    

  2. Depends on what version of OpenCart do you use. In OpenCart 3 when you try to save SEO URL that already exist – you will receive a message
    enter image description here

    Although there is a place, where yo can search across all OpenCart SEO URLs. You will find it in Design – SEO URL
    enter image description here

    Login or Signup to reply.
  3. if you want to check by programmatically then you can use following function for check, if SEO is exist or not. this will work in all version.

    function check_seo($keyword = ''){
        if(version_compare(VERSION, '3.0.0.0', '<')){ // below 3.0.0.0 version
            $SQL = "SELECT * FROM " . DB_PREFIX . "url_alias WHERE `keyword` LIKE '" . $this->db->escape($keyword)."'";
        }else{
            $SQL = "SELECT * FROM " . DB_PREFIX . "seo_url WHERE `keyword` LIKE '" . $this->db->escape($keyword)."'";
        }
        $found =  $this->db->query($SQL." LIMIT 1")->num_rows;
    
        if($found){
            // SEO already exists
        }else{
            // You can use this $keyword for SEO
        }
    }
    

    like if you want to check only for mac category SEO then check below Query and image,

    Query :

    SELECT * FROM `oc_url_alias` WHERE `query` LIKE 'category_id=%' AND `keyword` LIKE 'mac'
    

    enter image description here

    Login or Signup to reply.
  4. You can solve this issue with simple steps.

    -> Go to your opencart database and find "oc_seo_url" table open it.

    -> search that records which are have keyword field null/empty

    -> delete that records

    You can see in the picture bellow.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search