i.ahmed Posted August 23, 2014 Share Posted August 23, 2014 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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 23, 2014 Share Posted August 23, 2014 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. Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 23, 2014 Author Share Posted August 23, 2014 Hi Bsmither, thanks for your reply. I've just enabled: Category name in new product URL = (ticked) The current products still showing the same url Is there anything else I'm missing? Thanks in advance Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 23, 2014 Author Share Posted August 23, 2014 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 23, 2014 Share Posted August 23, 2014 "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. Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 23, 2014 Author Share Posted August 23, 2014 bsmither... your an absolute legend and a huge asset to this community, works like a charm, thank you! Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 24, 2014 Author Share Posted August 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 24, 2014 Share Posted August 24, 2014 "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')? Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 24, 2014 Author Share Posted August 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 24, 2014 Share Posted August 24, 2014 I see where the problem of two identically named products is happening. This problem is now revealed since allowing CubeCart to trigger it's auto seo path generation on an existing product. I'll be back shortly. Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 24, 2014 Share Posted August 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 24, 2014 Author Share Posted August 24, 2014 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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 24, 2014 Share Posted August 24, 2014 "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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 24, 2014 Share Posted August 24, 2014 Please double-check your edits. My initial experiments show that a same-named product will get the initial seo path, but there will be the unique suffix added. Quote Link to comment Share on other sites More sharing options...
i.ahmed Posted August 25, 2014 Author Share Posted August 25, 2014 Bizaare, its working now I must of made a mistake within the edit somewhere! Thanks for taking the time to help out, how does one buy you a drink or something around here? PayPal? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.