[MOD] Use product urls based on productid (not name)
Posted: Thu Jan 31, 2013 7:14 pm
The Interspire system relies on the product name as the basis for any links so even if you are not using SEO, as soon as you change the name of a product you will find that any links to that product are immediately broken unless you put in place redirects.
While this mod doesn't deal with the way the system stores the URLs or cross links within the store, it does mean that you can put in place links to your products that use the productid rather than the name, making it a bit easier not to be caught out.
Open: includes/classes/class.product.php
Find:
After, Add:
You can then use a link like:
http:// www. yoursite .com/products.php?productid=[productid_value]
The productid value is the one used in your products database or easily identified if you go into the admin > Products and mouseover the "edit" link for your target product (eg: http:// www. yoursite .com/admin/index.php?ToDo=editProduct&productId=393)
The code then looks up the normal product URL and redirects the browser to load the page as it would normally so the end user will have the standard URL shown in their browser address bar rather than a non-SEO link.
While this mod doesn't deal with the way the system stores the URLs or cross links within the store, it does mean that you can put in place links to your products that use the productid rather than the name, making it a bit easier not to be caught out.
Open: includes/classes/class.product.php
Find:
Code: Select all
public function _SetProductData($productid=0)
{
Code: Select all
//MOD Accept Productid as arg for product link
/*
* Allows the use of products.php?productid=xx as a link that then links
* to the name product url regardless of any product name changes
*/
if(array_key_exists('productid', $_REQUEST) && $_REQUEST['productid'] > 0) {
$productid = intval($_REQUEST['productid'])* 1;
require_once ISC_BASE_PATH . "/lib/class.urls.php";
header('Location: '.ISC_URLS::getProductUrl($productid));
}
//MOD END Accept Productid as arg for product link
http:// www. yoursite .com/products.php?productid=[productid_value]
The productid value is the one used in your products database or easily identified if you go into the admin > Products and mouseover the "edit" link for your target product (eg: http:// www. yoursite .com/admin/index.php?ToDo=editProduct&productId=393)
The code then looks up the normal product URL and redirects the browser to load the page as it would normally so the end user will have the standard URL shown in their browser address bar rather than a non-SEO link.