How do get product option value from order item

Ryan Nguyen asked on February 5, 2020 12:10

Hello I can't found API to get product option value from order item with (k12).

product options: screenshot

Anyone can help me on this?

Correct Answer

Dmitry Bastron answered on February 5, 2020 15:23

Hi Chu,

Yes, product options are stored as Order Items and they have a reference to main order item. You can check this directly in the database in the COM_OrderItem you will see OrderItemGuid and OrderItemParentGuid:

  • If OrderItemParentGuid is null - it is your main order item
  • If OrderItemParentGuid is NOT empty - this is a product option assigned to the order item

Also, there is another column called OrderItemSKUID which is a reference to COM_SKU table where products AND product options are stored.

So you can amend your code to something like:

var items = OrderItemInfoProvider.GetOrderItems(order.OrderID);
foreach (var orderItem in items.Where(x => x.OrderItemParentGUID == Guid.Empty))
{
    // do something with order item

    foreach (var orderItemOption in items.Where(x => x.OrderItemParentGUID == orderItem.OrderItemGUID))
    {
        // do something with order item option
        var text = orderItemOption.OrderItemText;
    }
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Dat Nguyen answered on February 5, 2020 12:28

1 votesVote for this answer Mark as a Correct answer

Ryan Nguyen answered on February 5, 2020 14:22

@Dat Nguyen: That isn't what i need. I want to get value of product option from order not add/update product option for product. See my here

0 votesVote for this answer Mark as a Correct answer

Ryan Nguyen answered on February 5, 2020 14:36 (last edited on February 5, 2020 14:38)

I can see product option values now, but it is a bit confused. (a product option is also a order item)

Here is my code

 OrderInfo order = OrderInfoProvider.GetOrderInfo(3);
    if (order != null)
    {

        var items = OrderItemInfoProvider.GetOrderItems(order.OrderID);
        foreach (var item in items)
        {
            string optionName = item.OrderItemSKUName; // a product option is also a order item
            string optionValue = item.OrderItemText;
            Response.Write("</br></br>OrderItemSKUName: " + optionName + ". OrderItemText: " + optionValue);
            var skuid = item.OrderItemSKUID;
            var options = OptionCategoryInfoProvider.GetProductOptionCategories(skuid, true);
            foreach (var option in options)
            {
                Response.Write("</br> - Product's option: " + option.CategoryFullName);
            }
        }
    }

Result: result screenshot

1 votesVote for this answer Mark as a Correct answer

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