[MOD] Use product urls based on productid (not name)

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Post Reply
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

[MOD] Use product urls based on productid (not name)

Post by Martin »

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:

Code: Select all

		public function _SetProductData($productid=0)
		{
After, Add:

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
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.
CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

Re: [MOD] Use product urls based on productid (not name)

Post by CharlieFoxtrot »

Absolutely Brilliant! Thank You! ~ I'd added a similar mod that allowed me to to the same thing... but it was not NEARLY as elegant and simple... and the address line always showed the non-SEO link.

I wonder if it's possible to do this with category names as well.

EDIT:

It appears that this mod will not work properly with earlier versions. My 4.07 version appears to be missing the file: /lib/class.urls.php
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."
Post Reply