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 ***
Professional Website Services - http://www.davidmgilbert.com/
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!!
-Dave
Professional Website Services - http://www.davidmgilbert.com/
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
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/
Regards
-Dave
Professional Website Services - http://www.davidmgilbert.com/
-Dave
Professional Website Services - http://www.davidmgilbert.com/
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
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.
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.
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.
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'));
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'));
Great stuff, Q Confirming this works on my test site. Really good to see collaboration like thisQphoria 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
Chris
Chris @ SiteE@se Web Design
- 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)
Professional Website Services - http://www.davidmgilbert.com/
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);
}
-Dave
Professional Website Services - http://www.davidmgilbert.com/
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
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');
}
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.
Code: Select all
$dir_cat_cont = "D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\";
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!
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/
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.fido-x wrote: Just a little suggestion. Instead ofmaybe use DIR_CONTROLLER since it's in the config files anywayCode: Select all
$dir_cat_cont = "D:\\EasyWAMP\\www\\opencart\\catalog\\controller\";
Code: Select all
define('DIR_CATALOG_CONTROLLER', 'D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\');
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!
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 filefido-x wrote: Addto your admin/config.php.Code: Select all
define('DIR_CATALOG_CONTROLLER', 'D:\\EasyWAMP\\www\\opencart\\catalog\\controller\\');
Something like $_SERVER['DocumentRoot']
Users browsing this forum: No registered users and 1 guest