Post by david.gilbert » Thu Aug 07, 2008 11:58 pm

After Reading through a few different threads in the forums here, I Got a FULL URL ALIAS and ALIAS Generation system built, tested and ready for OpenCart.

Installation Instructions are included!

This adds a new menu item (Generate URL Aliases) and also setups OpenCart to function Properly with them.

I forgot to mention it in the instructions so here Goes!
When you add or remove a product, category or page you will need to re-generate the aliases!

Hope you Guys Like it

-Dave

*** EDIT - Updated the Alias Generator to generate Aliases for ALL OpenCart static pages! such as Search/Checkout/Account etc.. ****
*** EDIT 2 - Fixed a few other minor bugs fixed the typo in htaccess.txt ***
*** EDIT 3 - Fixed links not being aliased in the content area of the store (ie. browsing by category) ***
*** EDIT 4 - Replaced Subcategory Generation With Qphoria's Subcategory generation Code  ***

Attachments

Last edited by david.gilbert on Sat Aug 09, 2008 12:30 pm, edited 1 time in total.

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by Qphoria » Fri Aug 08, 2008 12:02 am

Thanks for this David! :)

Just to confirm, since it replaces the menu files, adding this will cause me to lose the other stuff in my admin menu (like export/import) right?

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by david.gilbert » Fri Aug 08, 2008 12:17 am

Yes it will I realized I hadn't added entries for the checkout and search pages etc.. so I'm about to re-Upload the complete update to the original post..

You can see what it does @ http://www.ultimate-realty.org/
*** Please note though this is an actual production site in progress! Please don't go placing orders etc..! ***

Hopefully Daniel and HM2k Will include this with future releases of OpenCart!!  ;D

-Dave
Last edited by david.gilbert on Fri Aug 08, 2008 12:23 am, edited 1 time in total.

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by SiteE@se » Fri Aug 08, 2008 12:58 am

Nice one, Dave  :)

Just a couple of points noted in initial testing:

a) Typo in the .htaccess file:

EewriteCond %{REQUEST_FILENAME} !-d

should of course be

RewriteCond %{REQUEST_FILENAME} !-d

b)  Sub-categories are picked up and show the .html links in the generated list of aliases in admin but when browsing the store the links seem to use the standard 0.7.8 aliasing  ???

Chris @ SiteE@se Web Design


Active Member

Posts

Joined
Mon Dec 17, 2007 7:40 am
Location - UK

Post by david.gilbert » Fri Aug 08, 2008 1:02 am

Just noticed that myself,

To be honest, I don't have the answer to why right now, but I will work on it and try to get it fixed in the next day or two!

-Dave

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by david.gilbert » Fri Aug 08, 2008 4:01 am

Ok.. I have fixed the error with the URLS as you browse the categories. Now All Links update to static HTML pages through the URL Aliases option..

Regards

-Dave

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by david.gilbert » Fri Aug 08, 2008 3:24 pm

I just realized I haven't included the reviews pages in the SEO Upgrade Pack! I will post a new download as soon as it is done.

-Dave

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by Qphoria » Sat Aug 09, 2008 3:42 am

Working really great, however it seems to create multiple aliases for the same products:

Code: Select all

controller=category&path=0_1  	electronics.html  	 Update  Delete
controller=category&path=1 	electronics.html 	Update Delete
controller=category&path=1_2 	consumer-gadgets.html 	Update Delete
controller=category&path=2 	consumer-gadgets.html 	Update Delete
controller=category&path=22_23 	accessories.html 	Update Delete
controller=category&path=23 	accessories.html 
This seems to be because you can link to products off of the home page directly, and it takes you to its "own" version of that product.
Like there's
Home -> Category 1 -> Sub Category 1 - > ipod
and there's
Home -> ipod

This isn't really a bug in your mod, as it is a valid link path within OpenCart. But because of this, it is throwing my SubCategory mod out of whack because I do a check on the path and the full path of "22_23" works, but the partial path of just "23" doesn't.

I wonder why OpenCart doesn't just use the single path to an item, including the full product and category path inside of its request string. That would fix my problem, and reduce the amount of aliasing.

I am going to try to hack a way to get around this so that the subcategories can look up this url alias table and get the "full path" version instead of the short pathed version. Unless maybe there is a way during the url alias generation to check that.
Last edited by Qphoria on Sat Aug 09, 2008 3:45 am, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Sat Aug 09, 2008 4:16 am

Another question too...
I am looking at the generate_url_alias controller code, and it seems you are doing all the controllers with hardcoding. Couldn't you just loop through all files in the controller directory and use the filename to generate their alias name

something like

// Get array of controller files for url generation
$arrControllers = array();
if ($handle = opendir(dirname(__FILE__) . '/controller)) {
    while (false !== ($file = readdir($handle))) {
   if ($file != '.' && $file != '..' && substr($file,1) != '.') {
$arrControllers[] = $file;
}
    }
    closedir($handle);
}

The do a foreach on all the files. This way, its future proof resistant and will autofind all custom controllers too.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Sat Aug 09, 2008 4:45 am

Actually there does seem to be a slight limitation now that I see it..


You assume subcategories to only go 2 deep. But categories can go many many deep
So its not just {0}_{1}

Looks like you need to left join the category table with category_description and get the parent_id. If 0 then you can do the single {0} but if not zero, you need to somehow find if they are more than one deep.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Sat Aug 09, 2008 5:09 am

Doh! ;D I got it.. This will fix both of our contribs:

It was easier than I thought. I forgot there was a "Path" field in category. You are using path=category_id but the better choice would be path=path, as it keeps the hierarchy of the categories. No need to find what level deep it is, as it's already there. It also means that you can handle the categories as one, instead of making separate queries for subcategories.


In admin/controller/generate_url_alias.php
Change:

Code: Select all

        //generate category
        $sql = "select category_id, name from category_description";
        $this->_generate_url_alias($sql, 'controller=category&path={0}', array('category_id'), array('name'));

        //generate sub-category into category
        $sql = "select category.parent_id, category.category_id, category_description.category_id, category_description.name FROM category, category_description WHERE category.category_id = category_description.category_id";
        $this->_generate_url_alias($sql, 'controller=category&path={0}_{1}', array('parent_id', 'category_id'), array('name'));
        
to this:

Code: Select all

        //generate categories & subcategories
        $sql = "select c.parent_id, c.path, cd.name from category_description cd left join category c on (c.category_id = cd.category_id)";
        $this->_generate_url_alias($sql, 'controller=category&path={0}', array('path'), array('name'));        
Now you don't need the subcategory code at all and you won't get multiple copies of things. And now my subcategory mod doesn't choke on it :)
Last edited by Qphoria on Sat Aug 09, 2008 5:12 am, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by SiteE@se » Sat Aug 09, 2008 5:33 am

Qphoria wrote: Now you don't need the subcategory code at all and you won't get multiple copies of things. And now my subcategory mod doesn't choke on it :)
Great stuff, Q  Confirming this works on my test site.  Really good to see collaboration like this  ;D  ;D

Chris

Chris @ SiteE@se Web Design


Active Member

Posts

Joined
Mon Dec 17, 2007 7:40 am
Location - UK

Post by david.gilbert » Sat Aug 09, 2008 12:49 pm

Ok, I have updated the generate_url_alias.php as per Qphoria's code and made it available in the first post. For reference here is a small to-do list for further improvements:
  • Make The Reviews SEO Friendy (I have not yet got around to this)
  • Change the product Alias Generation to show /category/product-1.html instead of /category-product-1.html - Suggested by bruce Completed
  • Dynamically set the names for pages such as contact-us.html etc.. to reflect the stores language (perhaps create one for each language.. Google love this)
Last edited by david.gilbert on Sat Aug 09, 2008 11:12 pm, edited 1 time in total.

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by david.gilbert » Sat Aug 09, 2008 1:37 pm

Qphoria,

After thinking about your idea for the controllers using this code:

Code: Select all

// Get array of controller files for url generation
$arrControllers = array();
if ($handle = opendir(dirname(__FILE__) . '/controller)) {
    while (false !== ($file = readdir($handle))) {
      if ($file != '.' && $file != '..' && substr($file,1) != '.') {
         $arrControllers[] = $file;
      }
    }
    closedir($handle);
}
It wouldnt work too well because come controllers have multiple actions attributed to them.

-Dave

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by Qphoria » Sat Aug 09, 2008 10:55 pm

^^ Hmm. Not sure I understand. I'm just talking about getting their file name matchup like

Instead of hardcoding this:

Code: Select all

 //insert static information
        $this->_insert_url_alias('controller=home', 'index.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=contact', 'contact-us.html');  //NOT YET LOCALIZED
        $this->_insert_url_alias('controller=sitemap', 'sitemap.html');  //NOT YET LOCALIZED
        $this->_insert_url_alias('controller=search', 'search.html');  //NOT YET LOCALIZED   
        
        //Accounts
        $this->_insert_url_alias('controller=account', 'my-account.html');  //NOT YET LOCALIZED  
        $this->_insert_url_alias('controller=account_login', 'login.html');  //NOT YET LOCALIZED  
        $this->_insert_url_alias('controller=account_logout', 'logout.html');  //NOT YET LOCALIZED  
        $this->_insert_url_alias('controller=account_create', 'create-account.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=account_success', 'account-created.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=account_download', 'account-downloads.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=account_edit', 'edit-account.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=account_password', 'change-password.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=account_address', 'address-book.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=account_history', 'order-history.html');  //NOT YET LOCALIZED
        
        //Checkout
        $this->_insert_url_alias('controller=cart', 'cart.html');  //NOT YET LOCALIZED
        $this->_insert_url_alias('controller=checkout_shipping', 'checkout-shipping.html');  //NOT YET LOCALIZED  
        $this->_insert_url_alias('controller=checkout_address&action=shipping', 'change-shipping-address.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=checkout_payment', 'checkout-payment.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=checkout_address&action=payment', 'change-payment-address.html');  //NOT YET LOCALIZED 
        $this->_insert_url_alias('controller=checkout_confirm', 'checkout-confirm.html');  //NOT YET LOCALIZED
        $this->_insert_url_alias('controller=checkout_success', 'checkout-success.html');  //NOT YET LOCALIZED
I got this to work the same way:

Code: Select all

// Get array of controller files for url generation
        $arrControllers = array();
        $dir_cat_cont = "D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\";
        if ($handle = opendir($dir_cat_cont)) {
            while (false !== ($file = readdir($handle))) {
              if ($file != '.' && $file != '..' && substr($file,1) != '.') {
                 $arrControllers[] = $file;
              }
            }
            closedir($handle);
        }

        foreach ($arrControllers as $arrController) {
            $this->_insert_url_alias('controller=' . $arrController, str_replace('_', '-', str_replace('.php', '', $arrController)) . '.html');
        }
I hardcoded the catalog/controller directory because I'm lazy but you could find the proper method for that. You also will need to add a check for subdirectories because my override subdirectory was being found as a file. But otherwise the end result in the database is the exact same.

Now it will also be dynamic for any custom controllers and you have no maintenance :)

You could even skip the secondary for loop and just insert directly from the file search loop to make it smaller. :)
Last edited by Qphoria on Sat Aug 09, 2008 11:00 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Sat Aug 09, 2008 11:03 pm

Just a little suggestion. Instead of

Code: Select all

$dir_cat_cont = "D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\";
maybe use DIR_CONTROLLER since it's in the config files anyway

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by david.gilbert » Sat Aug 09, 2008 11:09 pm

Bruce and I have been working quite intensley this evening on making the SEO pack true multi-lingual, It seemed that if you had a second language installed it would alias all url's for the first language  with the aliases for the second language. We got past this by adding a language_id to the url_alias table and changing the routines for the information, category and product alias generations.  

We are currently working on making the static pages also multi-lingual (contact, sitemap, account, login, etc..) to further diversify the system and make the site more SEO friendly as far as google and other SE's are concerned when it comes to the second language.

We will then look at the reviews and get them done  8)

-Dave

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by Qphoria » Sat Aug 09, 2008 11:15 pm

fido-x wrote: Just a little suggestion. Instead of

Code: Select all

$dir_cat_cont = "D:\\EasyWAMP\\www\\opencart\\catalog\\controller\";
maybe use DIR_CONTROLLER since it's in the config files anyway
Right, well I said i was lazy.. the reality tho is that I tried that first, but since generate_url_alias.php file is in the admin section it thinks "DIR_CONTROLLER" = "D:\\EasyWAMP\\www\\opencart\\admin\\controller\" instead of the catalog side. This is supposed to be aliasing the catalog side of things. That's why its up to david to find the correct path way.  ;)
Last edited by Qphoria on Sat Aug 09, 2008 11:16 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Sat Aug 09, 2008 11:19 pm

Add

Code: Select all

define('DIR_CATALOG_CONTROLLER', 'D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\');
to your admin/config.php.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Sat Aug 09, 2008 11:27 pm

fido-x wrote: Add

Code: Select all

define('DIR_CATALOG_CONTROLLER', 'D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\');
to your admin/config.php.
LOL yea, but remember contribs are supposed to keep to themselves. Not start modifying every file on your disk. He needs to figure out how to do it from within the generate_url_alias.php file

Something like $_SERVER['DocumentRoot']

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 3 guests