Jump to content

Product SEO URL


i.ahmed
 Share

Recommended Posts

So I've added categories and sub-categories, the urls work fine.

 

i.e

 

store.com/category

store.com/sub-category

 

but the product appears as:

 

store.com/product.html

 

even though its in /category/sub-category

 

I can set the custom seo path but isn't the process auto, if the product is assigned to category as the primary etc?

 

I only noticed this when I added a product with the same name in two different categories and I got a error saying unique seo path has been created due to duplicated products.

 

Thanks in advance

Link to comment
Share on other sites

In admin, Store Settings, Search Engines tab, Category name in new product URL, if this is enabled, then CubeCart should be pre-pending the category path (the names of the categories from top-level to the name of the product's primary category).

 

But from creating a new product in admin, if you specify a Custom SEO path, or when changing the Custom SEO path of an existing product, then the previous paragraph no longer applies.

Link to comment
Share on other sites

Update.

 

I Created a new product and assigned the category, the url is showing correctly now thanks to your tip - category/sub/product.html

 

How am I able to append the category for all the other products?

 

I tried to go in to the product and manually delete the custom seo path and saved the product but that didn't help.

Link to comment
Share on other sites

"I tried to edit the product and delete the custom seo path, but that didn't help."

 

If you are wanting CubeCart to pre-pend the category path automatically, and there is already a custom seo path on the product's Search Engines tab, then we need to make an edit to a function because as of now, I see no code that will have CubeCart deliberately blank an existing path.

 

The problem is that CubeCart will always re-use the existing path when we try to blank that field.

 

In the file /classes/seo.class.php, near line 313:

Was:
case 'prod':
case 'product':
case 'viewprod':
// check its not been made already
if (($existing = $GLOBALS['db']->select('CubeCart_seo_urls', 'path', array('type' => 'prod', 'item_id' => $id))) !== false) {
  $path = $existing[0]['path'];
} else if (($prods = $GLOBALS['db']->select('CubeCart_inventory', array('product_id', 'name', 'cat_id'), array('product_id' => (int)$id), false, 1)) !== false) {
 
Now:
case 'prod':
case 'product':
case 'viewprod':
/* // check its not been made already
if (($existing = $GLOBALS['db']->select('CubeCart_seo_urls', 'path', array('type' => 'prod', 'item_id' => $id))) !== false) {
  $path = $existing[0]['path'];
} else */ if (($prods = $GLOBALS['db']->select('CubeCart_inventory', array('product_id', 'name', 'cat_id'), array('product_id' => (int)$id), false, 1)) !== false) {

Then try this: change the product's custom path to just a slash.

 

That is:

Was:

Custom SEO URL Path: test-product-1

 

Now:

Custom SEO URL Path: /

 

Save.

 

CubeCart should now perform the automatic sequence of creating a default seo path.

 

We must use a slash (which will eventually be discarded) because a browser, when submitting a form, will not include an element with an empty value.

Link to comment
Share on other sites

Me again, I've arrived at a slight stumbling block.

 

So I'm renaming the urls by adding "/" which is working great except for when I have:

 

store.com/productRED.html

+

store.com/productRED.html

 

When I do "/" it goes into its correct category = category/sub-cat/productRED.html

 

When I do it on the second one, its not being told to append a custom identifier on the end so it reverts back to:

 

store.com/productRED.html

instead of

store.com/productRED--p44.html

 

but it does append it if I add it from new.

Link to comment
Share on other sites

"When I do it on the second one, its not being told to append a custom identifier on the end"

 

I'm not following.

 

I would think that setting the Custom SEO Path of the second product would cause CubeCart to pre-pend the second product's category path - assuming the second product's category path is not the same as the first product's category path.

 

Are you saying you have two products, both in the same category, both named the same Product Name ('productRED')?

Link to comment
Share on other sites

Are you saying you have two products, both in the same category, both named the same Product Name ('productRED')?

 

Yep thats right, i have a category with two products with the same name.

 

If I add the product from new, cubecart will append a unique seo path relative to the category, but the already existing products, it reverts it back to root for some reason.

Link to comment
Share on other sites

I haven't tried this myself as yet, so make sure to have a backup of the file.

 

In the file /classes/seo.class.php, near lines 600-612 (CC5212, 615-627 for CC5213):

Was:
if (($existing = $GLOBALS['db']->select('CubeCart_seo_urls', 'id', array('type' => $type, 'item_id' => $item_id))) !== false) {
    $GLOBALS['db']->update('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path), array('id' => $existing[0]['id']));
} else {
    //Check for dup path
    if(!$GLOBALS['db']->select('CubeCart_seo_urls', false, array('path' => $path))) {
        $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path));
    } else {
        // Force unique path is it's already taken
        $unique_id = substr($type,0,1).$item_id;
        $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path.'-'.$unique_id));
        $GLOBALS['gui']->setError($GLOBALS['language']->settings['seo_path_taken']);
    }
}
 
Now:
// Determine if the record should be updated or a new record inserted.
// If a new record is to be inserted, determine if the path is already in use elsewhere.
// If so, make the path unique and display a general error.
/* But let's not use this process. Instead, use the process that follows.
if (($existing = $GLOBALS['db']->select('CubeCart_seo_urls', 'id', array('type' => $type, 'item_id' => $item_id))) !== false) {
    $GLOBALS['db']->update('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path), array('id' => $existing[0]['id']));
} else {
    //Check for dup path
    if(!$GLOBALS['db']->select('CubeCart_seo_urls', false, array('path' => $path))) {
        $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path));
    } else {
        // Force unique path is it's already taken
        $unique_id = substr($type,0,1).$item_id;
        $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path.'-'.$unique_id));
        $GLOBALS['gui']->setError($GLOBALS['language']->settings['seo_path_taken']);
    }
}
*/
// Determine if the path is already in use elsewhere.
// If so, make the path unique and display a general error.
// Then, determine if the record should be updated or a new record inserted.
if($GLOBALS['db']->count('CubeCart_seo_urls', 'id', array('path' => $path)) > 0) {
    // Force unique path because supplied/generated path is already taken
    $path .= '-' . substr($type,0,1).$item_id;
    $GLOBALS['gui']->setError($GLOBALS['language']->settings['seo_path_taken']);
}
if (($existing = $GLOBALS['db']->select('CubeCart_seo_urls', 'id', array('type' => $type, 'item_id' => $item_id))) !== false) {
    $GLOBALS['db']->update('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path), array('id' => $existing[0]['id']));
} else {
    $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path));
}

The original code is still there, but has had comments added and the code has been commented out. Then the new code with comments follows.

 

I will experiment with this code myself shortly.

Link to comment
Share on other sites

Ah thanks for that but I get the seo message:

 

The following errors were detected:

  • The SEO path specified is already in use with another item. A unique one has been specified for you. Please check and amend if necessary.

 

And the product still appears in the root as oppose to the category

Link to comment
Share on other sites

"I get the seo message."

 

That's to be expected. CubeCart is initially checking to see if the auto-generated path is already in use - which that path is in use because of what you said in post #9.

 

What's not expected is for the database record update to not happen.

 

I'll be checking on the code shortly.

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.

 Share

×
×
  • Create New...