Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Getting SKU options from SKU View modes: 
User avatar
Certified Developer 13
Certified Developer 13
matt-pixelbuilders - 2/11/2014 10:52:58 AM
   
Getting SKU options from SKU
Hi guys,

Wondering how you would go about getting SKU options from the main SKU product. For example I'm outputting non-option SKU's in a repeater, I then want to get each of the selected product options from that SKU (or OrderItemInfo ultimately).

I'm able to check if the SKU has enabled options like:

if (SKUInfoProvider.HasSKUEnabledOptions(orderItem.OrderItemSKUID))

So I'm essentially looking to get the chosen product options from an order item.

User avatar
Certified Developer 13
Certified Developer 13
kentico_josefd - 2/27/2014 9:18:50 AM
   
RE:Getting SKU options from SKU
Hi Matt,

The Product Options are not stored in SKU InfoObject. The main hurdle is that SKU can have multiple Product Option Categories assigned (Size, Color, Fit), which each may contain multiple SKU Product options ({S, M, L}, {Red, Blue, Green}, {Slim, Normal}). Therefore what you need to do is get all Product Option Categories assigned to the SKU and then get all SKU Product options from each category and return them in one DataSet or list.

Here is a sample method returning HTML list of all SKU Product Options based on SKUID:

    private static string getProductOptions(int skuId)
{
if (skuId <= 0)
{
return null;
}

StringBuilder strReturn = new StringBuilder();

// Get all categories assigned to the SKU
InfoDataSet<OptionCategoryInfo> optionCategories = OptionCategoryInfoProvider.GetSKUOptionCategories(skuId, true);
if (!DataHelper.DataSourceIsEmpty(optionCategories))
{
InfoDataSet<SKUInfo> options = new InfoDataSet<SKUInfo>();

// Go through all Categories assigned to this SKU and add all Product Options from each category to the result set of all options.
foreach (OptionCategoryInfo item in optionCategories)
{
options.Items.Add(SKUInfoProvider.GetSKUOptions(item.CategoryID, true));
}

if (!DataHelper.DataSourceIsEmpty(options.Items))
{
strReturn.Append("<ul>");
// Process the list. You can do this in the previous step, if you do not need to process the set any other way.
foreach (SKUInfo item in options)
{
strReturn.Append("<li>" + item.SKUName + "</li>");
}
strReturn.Append("</ul>");
}
}

return strReturn.ToString();
}


Let me know if you need any further help.

Regards,
Josef Dvorak