title: Magento Import Product Set Parent Category to use for URL Key. Wrong url key used on Category page
body: <p>-- <em>Update</em> --</p>
  
  <p>I've identified the problem to lie in the category page, listing the product links.</p>
  
  <p>This process uses getCategoryIds to get the product url with category.</p>
  
  <p>This makes me think I will have to set an additional attribute to define the desired parent to use for the url-key.</p>
  
  <p>I will update with information on how this goes.</p>
  
  <p>Any suggestions on a better way to handle creating this link, or if there's anyway to avoid the additional attribute to set which category is first, that would be helpful.</p>
  
  <p>-- <em>Original</em> --</p>
  
  <p>I am using the default Magento Product Import to import a CSV of the Products</p>
  
  <p>Each product is set to up to 3 categories. Initially, the url key for all of these seemed to be off. I noticed it was using whichever was defined last for the category as the url key for the product. (i.e. site.com/products/last-category/product-key)</p>
  
  <p>So I reversed the order of these in the Import. This seemed to fix most of them, but not all. There are still a few that get put under a different category's url key.</p>
  
  <p>It looks like there are just a random few who end up using the first category to set the url key's parent url (i.e. site.com/products/first-category/product-key).</p>
  
  <p>I deleted everything, cleared cache, logged out, tried everything again, and still the same ones have the same issue.</p>
  
  <p>There doesn't seem to be anything in the CSV that would indicate which ones are being processed differently. I've looked into the visibility of the product and the category, but the strange thing is that this doesn't have any barring on the placement at all.</p>
  
  <p>I was hoping someone could point me in the right direction as to what may be causing this.</p>
  
  <p>I looked at the URL Rewrite, as I thought it may be something there, maybe a lingering url rewrite, but when i deleted everything, those all were cleared as well.</p>
  
  <p>Re-importing, creates the same few that have the wrong parent.</p>
  
  <p>I cannot seem to find much information on the _root_category field of the import CSV, could this be the reason? I just have all these set to Default Category.</p>
  
  <p>I can give more specific examples if that would help, I don't want to make this more confusing than it has to be though.</p>
  
  <p>Any assistance would be greatly appreciated. I've looked everywhere I can think to do so.</p>
  
  <p>Any thoughts? Where have I forgot to poke around? Should I do some edit to the Import script (which I was hoping to avoid)?</p>
  
  <p><em>EDIT</em></p>
  
  <p>The URL key does work if I type it into the address bar. Say I want Category1/Product1, I can access it. But if i go to Category1/, in the catalog, the link is to Category3/Product1.
  But only for a few of these items. I am not sure what is causing this.
  There does not seem to be any tie to alphabetical sorting of the category.
  Could this have something to do with the Category ID?
  On the ones that work, it looks like the Category ID is higher than the others it's in. So perhaps it's assigning the url key to whichever Category has the highest ID value.</p>
  
  <p>How do I prevent this from happening? It's starting to look like I'm going to have to do something with the import script. Which is the best way to handle this? Creating an Advanced Dataflow, or edit the core?</p>