Jump to content

[Resolved] Add manufacturer name to automatically generated SEO product URL


BullishD

Recommended Posts

note: This is more of a how to, instead of a question.  Please let me know if this is in the wrong spot.

I wanted to include our products manufacturer names in the automatically generated SEO product URL.  Since when people search for our particular products they will most likely include the manufacturer name in their search.  I figure adding the manufacturer name to the url should help with our SEO.  I couldn't find a solution on the forums (If one exists, I apologize), so I figured I would add mine here, just in case anyone in the future has a similar need.

I am running CubeCart 6.0.12.

The area that I was looking to modify is under products -> Search Engines tab.   and the field " Custom SEO URL Path * "    If this is left blank the system will automatically generate an SEO friendly url for the product.  the default behaviour generates the seo path based on the product name.  (and possibly the category if that option is selected in store settings)

example:

Product name:  Test Product

Manufacturer: Blue Chip

Default SEO url:  test-product

Desired SEO url: blue-chip-test-product

In order to accomplish this I had to modify the file ..\classes\seo.class.php

First, we want to bring back the products selected manufacturer.  Update the SQL statement to return this.

in classes\seo.class.php at or near line 276, change

} elseif (($prods = $GLOBALS['db']->select('CubeCart_inventory', array('product_id', 'name', 'cat_id'), array('product_id' => (int)$id), false, 1)) !== false) {

to

} elseif (($prods = $GLOBALS['db']->select('CubeCart_inventory', array('product_id', 'name', 'cat_id', 'manufacturer'), array('product_id' => (int)$id), false, 1, false)) !== false) {


This will bring back the ID value of the manufacturer.

The next step is to grab the name of the manufacturer, and then display this along with the product name.   This next block does both steps.

in classes\seo.class.php at or near line 293, replace the line

$path = empty($cat_directory) ? $prods[0]['name'] : $cat_directory.'/'.$prods[0]['name'];

with

$manufacturername = ($manuf = $GLOBALS['db']->select('CubeCart_manufacturers', array('name'), array('id' => (int)$prods[0]['manufacturer']))) ? $manuf[0]['name'] : '';
if ($manufacturername != '') {
	$path = empty($cat_directory) ? $manufacturername.'-'.$prods[0]['name'] : $cat_directory.'/'.$manufacturername.'-'.$prods[0]['name'];
} else {
	$path = empty($cat_directory) ? $prods[0]['name'] : $cat_directory.'/'.$prods[0]['name'];
}

And that is it.    the first line $manufacturername = ...  grabs the name of the manufacturer from the database given the id from the product query above.

the second line, and start of the if statement, checks if a manufacturer name exists;Iif it does, it will generate the SEO friend url including the manufacturer name; if it does not, then it will generate the SEO friendly url the 'default' way using just the product name (and possibly the category)

I am still new to CubeCart, so those of you with more experience, let me know if I can simplify / optimize this solution.    also, speak up if you think it is not worth it from an SEO perspective.  

I hope this helps someone down the road. 

 

Link to comment
Share on other sites

Very good.

May I recommend:

From:

$manufacturername = ($manuf = $GLOBALS['db']->select('CubeCart_manufacturers', array('name'), array('id' => (int)$prods[0]['manufacturer']))) ? $manuf[0]['name'] : '';
if ($manufacturername != '') {

To:

if (($manufacturername = strip_tags($GLOBALS['catalogue']->getManufacturer($prods[0]['manufacturer']))) != false) {

Catalogue->getManufacturer() may return an anchor tag, so that needs to be stripped off. Otherwise, the name. Otherwise, false.

I think it is best to use established class methods. That way, if the database schema should ever change, the class method will change along with it and still give the established return value.

Link to comment
Share on other sites

Firstly, I like the idea of the option of being able to add the manufacturer to the seo url although whether it will help your SEO depends on a large number of factors that will vary with every store, such as what category structure you have (and are losing from your SEO url), whether the manufacturer's name is well known and most importantly how well it ties in with all the other SERPS factors on that page.  Simply adding the manufacturer to the url will probably do little by itself. If doing it automatically, you also have to decide whether the category adds more or less than the manufacturer name.

Also, the whole point of the Custom SEO url field is that you can manually enter whatever you like into it, so a much better solution would be to simply enter that path and save it, rather than make core file changes to the code. Of course, if you have thousands or tens of thousands of products then doing it manually would be a long job but if it is that important to you then much better to do it via a plugin.

There are some on here that advocate hacking code and I have seen so many people start off justifying that it is only one or two small changes and they are simple to reproduce when you upgrade and before long the core code is hacked to pieces and it gets extremely complicated to upgrade. You can of course using file comparison tools (like Beyond Compare) to make it easier or even setup your own git repository, but neither of these are an easy way to solve the problem and can often be a lot more work than biting the bullet initially and doing it via a plugin.

Lastly, we have an Enhanced Manufacturers plugin (which already adds a lot of extra functionality around the basic built in) and it would be relatively simple to add this as an extra feature if you are interested.

Ian

Link to comment
Share on other sites

Thanks for the replies bsmither and Ian,

bsmither, that is great and exactly why I posted as I haven't figured out all the established methods yet,  much simpler.  thank you.   I will change to your version and test out

Ian, great points, and yes I was aware I would have to maintain these changes at upgrade time.   I was actually going to ask if it was worthwhile to make this change as a plug-in instead of core code changes.  (I haven't looked into how to do that yet).    Very good point with the categories and depending on how they are set up would negate the need for this change.    As the categories are currently set up, the manufacturers are not included (this store is for my wife's small business).   But they may decide to change that since they are still figuring out how they want it all laid out.  

Good points, worth mulling over.   Thank you

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...