-- Update --

I think the issue is in the category list view. It generates the product link to the product, for the page, in a loop.

I have it getting the product categories, and using that to build the URL.

I am thinking I will have to define which one i want to be the parent in an additional attribute, and then check that attribute for the category url-key that I want to use.

Any suggestions on the best way to accomplish this?

-- Update --

I have noticed that the issue seems to be because of the way magento creates it's url-key for a product is based off the highest Category ID of the categories it belongs to.

The largest category ID defines the url-key.

So if I have product1 in category1, category2, and category3; I want the url key of category1 (i.e. site.com/category1/product1), but if category3 has a larger ID than category1, the url key will be site.com/category3/product1, even when you navigate to site.com/category1 the link is to site.com/category3/product1.

I could remove it from additional categories that have a higher ID, but that is not an ideal solution.

Is there anyway to set the full url key? or is there somewhere i can force the preference of a certain category's url-key?

-- Original --

I am attempting to import products and categories via CSV.

I have this process working, and everything imports without throwing an error.

I have my products belonging to anywhere from 1 to 3 categories.

In the import, the url key for most of the products is correct, it just seems to be some random ones that do not get the url key of the first parent (category).

It seemed that initially they all were using the last, so i switched the order to be reversed.

This fixed most all of them, but ones that are set up pretty much the same, and should have the same parent url key, are randomly using one of the other categories as a URL key.

I tried deleting everything (Products and Categories), cleared my cache storage. Checked that the URL Rewrites were removed, and tried importing again.

I get the same result.

The does not seem to be any ties to visibility, as one which is incorrect is set to 4, and another is 1 (which i would expect 1 to be erroring if either of the two.)

I have most of the categories inactive, I want to roll out additional categories after launch.

I would think it would take preference to the visible categories, but the one i want to to show up in is visible, and it gets placed in an inactive one.

I am not sure what else may cause this. Or where else to look for the problem. I do not see anything that would indicate why those specific products are different. But each time I import, the same ones fall into the wrong category.

Any help would be greatly appreciated. If someone could at least point me in the right direction.

I can give more specific examples if required, I didn't want to confuse things more than this already is.

  • Please check this great debugging tutorial and report back. Jul 23, 2014 at 23:11
  • As much as that is a great resource, I do not believe this issue is within the scope of that document. I have refined the problem a bit, and have made an update to the question. The problem lies with the inheritance of the url-key from the parent category with the highest ID. Jul 24, 2014 at 13:32

1 Answer 1


In an effort not to have duplicate URLs, but link additional categories to the product in another category, with one URL, I ended up solving this issue as follows.

I created an additional product attribute, parent_url_key.

In my import script, I added the prefered parent URL Key for each product in this value.

On the Category Product List view, instead of just using:


I did this to create my product URL:

$url = $_product->getProductUrl();
if($categoryParent = $_product->getResource()->getAttribute('parent_url_key')) {
    $categoryParentVal = $categoryParent->getFrontend()->getValue($_product);
    if($categoryParentVal) {
        $url = $this->getUrl($categoryParentVal).basename($url);

This way it checks for a defined parent, or uses the current category if it's undefined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.