Magento 1.9 – Get Custom Option Values of a Product

configurable-productcustom-optionsmagento-1.9

In my magento store, I have implemented a custom module to add configurable products programmatically. In those products I have added Custom Option, a text field for user to input some data.

Now I have this requirement of retrieving all the values of the custom option entered by users who purchased the specific product. (I need to retrieve the values using the product ID)

Is there a way I can achieve this?

Best Answer

Check product_options column in sales_flat_order_item table.

You can use order_item collection and get the value of that field like that:

$orderItems = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('product_id', '123');

foreach($orderItems as $orderItem){
    $options = $orderItem->getProductOptions();
    var_dump($options);
}
Related Topic