SEO Urls 5 Pro for osCommerce

By | December 13, 2009

This is a new version of FWRMedia’s existing SEO Urls contribution. I’ve been beta teting it for the last few days and between a few users found a couple of issues [nothing major] which should be fixed when the final release is made.

The one thing that I really do not like about this module is the URL rewriting (in actual fact lack of rewrite) if the URL to be re-written includes attributes/options. There’s pretty much only 1 link that is completely annoying for me, and I’d like to see it solved before the release is made. But, in case it isn’t, here’s how to replicate the “annoying problem”;

1. Find a product which has options/attributes
2. Add to cart
3. The linkback from the shopping cart list to the product page, includes attributes and is therefore not rewritten. I think this is a mistake (note, I do not think it’s a bug, just a mistake not to rewrite it).

As an example, go here, select options, add to cart, then mousevoer the link back to the product…

How to solve this. Easy, at least in my preview Beta version it is!

Step 1: add a new true/false to the USU-init file…

Add this:
[php]@define(‘SEO_URLS_CART_RETURN’, ‘true’); // true or false
// true = SEO Urls are used from shopping cart link
// false = SEO Urls are NOT used from shopping cart link[/php]

probaby all these will be part of an admin interface rather than in a text file, if that happens, I’ll update the post appropriately.

Step 2: amend existing code in the shopping_cart file…

Find this:
[php] ‘

‘ . tep_image(DIR_WS_IMAGES . $products[$i][‘image’], $products[$i][‘name’], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . ‘

‘ .

‘ . $products[$i][‘name’] . ‘‘;[/php]

Change it to this:
[php]’

‘ . tep_image(DIR_WS_IMAGES . $products[$i][‘image’], $products[$i][‘name’], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . ‘

‘ .

‘ . $products[$i][‘name’] . ‘‘;[/php]

Save and upload both files. Done!

Now you can decide whether to have the link from the shopping cart rewritten [true] or not [false]. The only downside is that if you select “true”, the link will not contain the selected attributes – but that hardly matters I think.

Anyway, when the contribution comes out it is possible that this (or something like this) will be included in the core code. If not, then you can use my ideas on this page to give yourself more choice.

Explanation

In actual fact, all we are doing is changing this:
[php]$products[$i][‘id’][/php]

to this:
[php](SEO_URLS_CART_RETURN == ‘true’ ? tep_get_prid($products[$i][‘id’]) : $products[$i][‘id’])[/php]

This uses a TERNARY Operator to grab the value of SEO_URLS_CART_RETURN, and do either of this:[php]tep_get_prid($products[$i][‘id’])[/php] or this: [php]$products[$i][‘id’][/php] based on whether the value of SEO_URLS_CART_RETURN is “true” or not.

So, what is tep_get_prid?

Here is the code, taken from includes/functions/general.php:
[php]////
// Return a product ID from a product ID with attributes
function tep_get_prid($uprid) {
$pieces = explode(‘{‘, $uprid);

if (is_numeric($pieces[0])) {
return $pieces[0];
} else {
return false;
}
}[/php]

This is an existing osCommerce function which strips the attribute key[s] and value[s] from the URL. In other words, it would change this: http://demo.oscommerce.com/product_info.php?products_id=1{4}1{3}5 to this: http://demo.oscommerce.com/product_info.php?products_id=1

The part of the URL that controls attributes “{4}1{3}5” has been stripped using the function as it “explodes” the ID like this:

0: 1
1: 4}1
2: 3}5

and then simply outputs the value at “0”, which will be the product ID.

Conclusion

So, add it all up and you can see that what we are doing is putting in a new control “true/false” to use the tep_get_prid function to strip [or not!] the attributes from the URL.

A little clearer now?

Leave a Reply

Your email address will not be published. Required fields are marked *