How to display only the options categories of a specific product in MVC

Dominic Boyer asked on October 29, 2020 22:13

So here my question:
1-With the categoryID how can I have access to the option properties list of that category for the 3 types?

With this API:
OptionCategoryInfoProvider.GetProductOptionCategories
I can pass the skuid in the parameter and it return some properties like the categoryID, categoryName… So with that information, I can get all the categoryID associated with that product. (a good start)

Thank you

Recent Answers


David te Kloese answered on October 30, 2020 12:25

What version of Kentico are you using? OptionCategoryInfoProvider.GetProductOptionCategories was removed in version 11?

Instead it's you should use Data Query API: devnet.kentico.com/.../kentico-8-technology-dataquery-api

I don't quite get what you want but is guess based on the CategoryID get the categories? Something like:

var categories =
OptionCategoryInfoProvider.GetOptionCategories()
    .WhereEquals("CategoryID", yourCatIDValueInteger);
0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on October 30, 2020 13:30

Im using kentico 12 and the OptionCategoryInfoProvider.GetProductOptionCategories seem to work for me. It return properties like the categoryID, categoryName...

The API OptionCategoryInfoProvider.GetOptionCategories() is not good for what i want to accomplish, cause i dont have the categoryID, i only have the skuid.

So with the first API i can have a list of all categoryID associated with a product. Now i try to find a way to display the options properties for the 3 types (text, products and attribute)

Ex:
Size (attribute with radio button)
- small +25$
- large +30$

Shoelace (product with checkbox / can choose multiple here)
- green +25$
- red +30$
- blue +30$

Message (inscription with textbox)
- add your name on shoe +10$, please enter the name on the textbox

And i need the action to add those in the cart too :)

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 30, 2020 14:37

Hi,

sorry you're right! I should have opened a solution :).

Do you have the sample site installed? There are some examples you could check.

Also I recommend to have a look at the API examples: docs.xperience.io/.../product-options-and-variants

Options are actually stored as SKU itself... So you would need to get the category assigned to the SKUID you had, and get all available options from there.

So based on the Category Id you already have you can now get the options using something like:

// Gets all product options with the option category
var options = SKUInfoProvider.GetSKUs().WhereEquals("SKUOptionCategoryID", optionCategory.CategoryID);

the logic you can also see in the api examples comes down to:

  • a SKU with .WhereNull("SKUOptionCategoryID") = a product

  • a SKU with .WhereNotNull("SKUOptionCategoryID") = an option

Hope this helps

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on October 30, 2020 14:40

Thank you David, i will try to implement this, and let you know soon :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.