Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm using Opencart version 1.5.5.1 and this is the exact code that worked for me:</p> <pre><code>&lt;?php class ControllerCommonSeoUrl extends Controller { /* SEO Custom URL */ private $url_list = array ( 'common/home' =&gt; '', 'checkout/cart' =&gt; 'cart', 'account/register' =&gt; 'register', 'account/wishlist' =&gt; 'wishlist', 'checkout/checkout' =&gt; 'checkout', 'account/login' =&gt; 'login', 'product/special' =&gt; 'special', 'affiliate/account' =&gt; 'affiliate', 'checkout/voucher' =&gt; 'voucher', 'product/manufacturer' =&gt; 'brand', 'account/newsletter' =&gt; 'newsletter', 'account/order' =&gt; 'order', 'account/account' =&gt; 'account', 'information/contact' =&gt; 'contact', 'account/return/insert' =&gt; 'return', 'information/sitemap' =&gt; 'sitemap', ); /* SEO Custom URL */ public function index() { // Add rewrite to url class if ($this-&gt;config-&gt;get('config_seo_url')) { $this-&gt;url-&gt;addRewrite($this); } // Decode URL if (isset($this-&gt;request-&gt;get['_route_'])) { $parts = explode('/', $this-&gt;request-&gt;get['_route_']); foreach ($parts as $part) { $query = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this-&gt;db-&gt;escape($part) . "'"); if ($query-&gt;num_rows) { $url = explode('=', $query-&gt;row['query']); if ($url[0] == 'product_id') { $this-&gt;request-&gt;get['product_id'] = $url[1]; } if ($url[0] == 'category_id') { if (!isset($this-&gt;request-&gt;get['path'])) { $this-&gt;request-&gt;get['path'] = $url[1]; } else { $this-&gt;request-&gt;get['path'] .= '_' . $url[1]; } } if ($url[0] == 'manufacturer_id') { $this-&gt;request-&gt;get['manufacturer_id'] = $url[1]; } if ($url[0] == 'information_id') { $this-&gt;request-&gt;get['information_id'] = $url[1]; } } else { $this-&gt;request-&gt;get['route'] = 'error/not_found'; } } /* SEO Custom URL */ if ( $_s = $this-&gt;setURL($this-&gt;request-&gt;get['_route_']) ) { $this-&gt;request-&gt;get['route'] = $_s; }/* SEO Custom URL */ if (isset($this-&gt;request-&gt;get['product_id'])) { $this-&gt;request-&gt;get['route'] = 'product/product'; } elseif (isset($this-&gt;request-&gt;get['path'])) { $this-&gt;request-&gt;get['route'] = 'product/category'; } elseif (isset($this-&gt;request-&gt;get['manufacturer_id'])) { $this-&gt;request-&gt;get['route'] = 'product/manufacturer/info'; } elseif (isset($this-&gt;request-&gt;get['information_id'])) { $this-&gt;request-&gt;get['route'] = 'information/information'; } if (isset($this-&gt;request-&gt;get['route'])) { return $this-&gt;forward($this-&gt;request-&gt;get['route']); } } } public function rewrite($link) { $url_info = parse_url(str_replace('&amp;amp;', '&amp;', $link)); $url = ''; $data = array(); parse_str($url_info['query'], $data); foreach ($data as $key =&gt; $value) { if (isset($data['route'])) { if (($data['route'] == 'product/product' &amp;&amp; $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') &amp;&amp; $key == 'manufacturer_id') || ($data['route'] == 'information/information' &amp;&amp; $key == 'information_id')) { $query = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this-&gt;db-&gt;escape($key . '=' . (int)$value) . "'"); if ($query-&gt;num_rows) { $url .= '/' . $query-&gt;row['keyword']; unset($data[$key]); } } elseif ($key == 'path') { $categories = explode('_', $value); foreach ($categories as $category) { $query = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'"); if ($query-&gt;num_rows) { $url .= '/' . $query-&gt;row['keyword']; } } unset($data[$key]); } /* SEO Custom URL */ if( $_u = $this-&gt;getURL($data['route']) ){ $url .= $_u; unset($data[$key]); }/* SEO Custom URL */ } } if ($url) { unset($data['route']); $query = ''; if ($data) { foreach ($data as $key =&gt; $value) { $query .= '&amp;' . $key . '=' . $value; } if ($query) { $query = '?' . trim($query, '&amp;'); } } return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query; } else { return $link; } } /* SEO Custom URL */ public function getURL($route) { if( count($this-&gt;url_list) &gt; 0) { foreach ($this-&gt;url_list as $key =&gt; $value) { if($route == $key) { return '/'.$value; } } } return false; } public function setURL($_route) { if( count($this-&gt;url_list) &gt; 0 ){ foreach ($this-&gt;url_list as $key =&gt; $value) { if($_route == $value) { return $key; } } } return false; }/* SEO Custom URL */ } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload