1

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?

  • Can you explain a little more what exactly is doing your module ? For example : In which table is the data of this custom option registered ? – hellimac Jun 5 '15 at 7:59
  • it's a module to create configurable products programmatically and each configurable product contains a custom option where the customer can enter their name. – Mag-Newbie Jun 5 '15 at 8:07
3

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);
}
4

You need use this code to get custom options of the product:

    if($_product->hasOptions()) {
        foreach($_product->getOptions() as $option) {
            echo 'Option title is: ' . $option->getTitle();
            echo 'Option type is: ' . $option->getType();
            echo 'Option values:';
            foreach($option->getValues() as $value) {
                echo '- ' . $value->getTitle() . ': ' . $value->getPrice();
            }
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.