Post by combusus » Mon Nov 07, 2011 3:12 am

Tested on v1.5.1.3 but should work on earlier versions.
If you have a manufacturer "Sony" for example: http://www.opencart.com/sony.html
The default links to products show as: http://www.opencart.com/apple.html/iPhone-4S.html

The fix below will replace the URL's with the category/product URL, example:
http://www.opencart.com/smart-phones/iPhone-4S.html

OPEN FILE ../catalog/controller/common/seo_url.php

FIND AT APPROX. LINE 2

Code: Select all

class ControllerCommonSeoUrl extends Controller {
ADD AFTER:

Code: Select all

/* BEGIN: Manufacturer SEO URL Fix (1 of 2) */
    
      public function get_cat_alias($cid)
      {
        $cid=intval($cid);
        $query='
          SELECT
            c.parent_id,
            a.keyword
          FROM
            '.DB_PREFIX.'category AS c,
            '.DB_PREFIX.'url_alias AS a,
            '.DB_PREFIX.'product_to_category AS pc
          WHERE
            c.category_id='.$cid.' && a.query="category_id='.$cid.'"
          LIMIT 1
        ';
        $result=$this->db->query($query);
        $results=array();
        foreach($result->rows as $row)
        {
          if(intval($row['parent_id'])!==0)$results[]=$this->get_cat_alias($row['parent_id']);
          if(isset($row['keyword']))$results[]=$row['keyword'];
        }
        return $results;
      }
      function output_cat_alias($array)
      {
        $result=array();
        foreach($array as $keyword)
        {
          if(is_array($keyword))
          {
            $result[]=$this->output_cat_alias($keyword);
          }else
          {
            $result[]=$keyword;
          }
        }
        return implode('',$result);
      }
      
/* END: Manufacturer SEO URL Fix (1 of 2) */
FIND AT APPROX. LINE 116

Code: Select all

	if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/product' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
ADD AFTER:

Code: Select all

	/* BEGIN: Manufacturer SEO URL Fix (2 of 2) */

              if($key == 'product_id')
              {
                $query='
                  SELECT
                    c.parent_id,
                    c.category_id
                  FROM
                    '.DB_PREFIX.'category AS c,
                    '.DB_PREFIX.'url_alias AS a,
                    '.DB_PREFIX.'product_to_category AS pc
                  WHERE
                    pc.product_id='.$value.' &&
                    pc.category_id=c.category_id
                  LIMIT 1
                ';
                $cat_current=$this->db->query($query);
                $query='
                  SELECT
                    a.keyword
                  FROM
                    '.DB_PREFIX.'url_alias AS a
                  WHERE
                    a.query="category_id='.$cat_current->row['category_id'].'"
                  LIMIT 1
                ';
                $cat_current_key=$this->db->query($query);
                $url=$this->get_cat_alias($cat_current->row['parent_id']);
                $url=array(0=>$url,1=>$cat_current_key->row['keyword']);
                $url='/'.$this->output_cat_alias($url);
              }

/* END: Manufacturer SEO URL Fix (2 of 2) */

User avatar
Newbie

Posts

Joined
Mon Feb 21, 2011 7:31 am

Post by wernerrenrew » Mon Nov 07, 2011 6:00 am

Hi,

May i ask why you use .html in the seo name of the manufacturers.

I use the default seo functions of v1.5.1.3
This is a url for product on my test server manufacturer apple

admin:
catalog/manufacturers/apple seo url apple
than i went to
system/design/banners/manufacturers to change the url for apple in the carousel

result http://demo-opencart.beoptimized.nl/app ... t-test-123

maybe i'm missing something

Regards Werner

Btw checkout my modules
Ultimate Zoom we believe not you but your customers should decide what their zoom preference is.
http://www.opencart.com/index.php?route ... on_id=3839

and my free modules
All clean urls cleans all urls seo url doesn't
http://www.opencart.com/index.php?route ... on_id=3802

Random Specials
http://www.opencart.com/index.php?route ... on_id=3809

User avatar
Active Member

Posts

Joined
Thu Oct 27, 2011 9:48 pm
Location - Netherlands

Post by combusus » Mon Nov 07, 2011 7:20 am

wernerrenrew wrote:Hi,
May i ask why you use .html in the seo name of the manufacturers.
Hi Werner, sure no problem:

1. Mainly because we are migrating a few sites to OC and we need to keep the URL structure the same.

2. Also because the way OC is now their can be 3 completely different links all going to the same products, canonical link elements or not this is just not good practice to have multiple links to the same page, especially when it's something so simple to prevent. Take notice the Google Sitemap spits out the duplicate link URLS, it's bad enough having the duplicate links but even worse having the sitemap tell Google. Not everyone would want their links like this but now people can have a choice.

Thanks - Combusus

User avatar
Newbie

Posts

Joined
Mon Feb 21, 2011 7:31 am

Post by wernerrenrew » Mon Nov 07, 2011 10:08 am

Hi,

I see your point but wouldn't it be more appropriate in this case to put something like this in your htaccess

Code: Select all

RewriteCond %{HTTPS} off
RewriteRule ^(.*)\.html$ http://%{HTTP_HOST}/$1?%{QUERY_STRING} [R=301,L]
RewriteRule ^(.*)\.html$ https://%{HTTP_HOST}/$1?%{QUERY_STRING} [R=301,L]
It's true opencart generates some duplicate content but the canonical takes care of that there will be no pagerank lost when you use it all pagerank will flow to the canonical url.

About the sitemap you have got a point there but you can do without it if the search engines know about your domain.

You would need it if your site has pages that would otherwise be hidden from search engines.

Practical case example look at the nvidia website http://www.nvidia.com/Download/index.aspx?lang=en-us
Finding the driver pages would be a problem for most if not all search engines you would need a sitemap to make sure all searchengines would see your driver pages

I love this software it's MVC (L) core is solid from what i've seen since i downloaded my first copy like 2 weeks ago i have million new ideas wish i didn't have to sleep :crazy:

Regards werner

User avatar
Active Member

Posts

Joined
Thu Oct 27, 2011 9:48 pm
Location - Netherlands
Who is online

Users browsing this forum: No registered users and 4 guests