Search code examples
phpseoopencarturl-routing

How do I create an SEO-friendly link for custom, dynamically generated pages in Opencart?


I'm using Opencart 2.0 framework

I have controller that is called happy_hours.php there I'm looping through the product and categories for the current hour. For categories I'm creating links like this

'href'  => $this->url->link('product/happy_hours', 'id='   . $category['category_id'])

In the .tpl file the link looks like this:

index.php?route=product/happy_hours&id=65

In the database table oc_url_alias I've added a record for the SEO link for 'happy_hours' like

query = product/happy_hours
keyword = happyhours

Now I can access now domain.com/happyhours

But how do i create SEO link like this for categories?

domain.com/happyhours/categoryname

Update

fix posted


Solution

  • some how manage to do it

    in soe_url.php controller

    elseif ($key == 'id') {
    
                    $categories[] = $value;
    
                    foreach ($categories as $category) {
                        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'happy_hour_id=" . (int)$category . "'");
    
                        if ($query->num_rows && $query->row['keyword']) {
                            $url .= '/' . $query->row['keyword'];
                        } else {
                            $url = '';
    
                            break;
                        }
                    }
                        unset($data[$key]);
                }
    

    in database url_alias

    query = happy_hour_id=65
    keyword = happyhour/category name
    

    in final

    domain.com/happyhour/category name