# Get MainCategory from BaseProductToCategoryLink collection

**URL:** <https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419>\
**Category:** Questions\
**Tags:** litium-6\
**Created:** [April 3, 2020, 10:04am UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419 "2020-04-03T10:04:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![micmil](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@micmil](https://forum.litium.com/u/micmil)\
**Post date:** [April 3, 2020, 10:04am UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419/1 "2020-04-03T10:04:58Z")

</div>

_[Question (in english) - remember to come back and check the answer that solves your question to mark it as resolved, formatting of messages with [markdown](https://commonmark.org/help/)]_

Litium version: _[6.3.7]_

I’m working on an article import which needs to be modified, and in the part where variants are added to a MainCategory it is fetched like this:  
var editableBaseProduct = baseProduct.MakeWritableClone();  
mainCategory = editableBaseProduct.CategoryLinks.First(c =\> c.MainCategory);  
Add variants to it:  
mainCategory.ActiveVariantSystemIds.Add(variant.SystemId);

It is working fine but then I noticed that on a product with 2 categories, both of them had MainCategory as “true” when i was debugging, that shouldn’t be possible or should it?

If I use the GetMainCategory extension one category is returned. I went on to check in Litium/Plan section and saw that the category that was returned was not selected, the other category was, why is that?

Basically I need to know if I’m adding variants to the correct MainCategory.

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 3, 2020, 11:23am UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419/2 "2020-04-03T11:23:51Z")

</div>

One base product can only have one main category selected in each assortment.

---

<div class="post-metadata">

**Author:** ![micmil](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@micmil](https://forum.litium.com/u/micmil)\
**Post date:** [April 3, 2020, 12:18pm UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419/3 "2020-04-03T12:18:19Z")

</div>

There is only one assortment, the image shows 2 categories that belong to the same assortment as I see it.

 ![Fresks-cats](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/e5bb16e8273c08882d89bcee1f3f0f03e92a14d3.jpeg)

If I do: baseProduct.GetMainCategory(CurrentState.Current.WebSiteID); I get the “Glasull” category which is not the selected one as in the image.  
When I look in baseProduct.CategoryLinks both categories have MainCategory property as “true”.

I can use the extension for getting the MainCategory but I wanted to know if this is a bug or is this behaviour normal?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 3, 2020, 1:09pm UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419/4 "2020-04-03T13:09:46Z")

</div>

Please, report that as a bug on our docs-site, it sounds like a validation rule is missing.

---

<div class="post-metadata">

**Author:** ![micmil](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@micmil](https://forum.litium.com/u/micmil)\
**Post date:** [April 3, 2020, 1:21pm UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419/5 "2020-04-03T13:21:37Z")

</div>

Ok, thanks for your help!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [May 1, 2020, 1:21pm UTC](https://forum.litium.com/t/get-maincategory-from-baseproducttocategorylink-collection/1419/6 "2020-05-01T13:21:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
