1

I'd like to retrieve the contents of the text field (custom option) that the customer entered at the product page. I have tried functions such as: getValue, getPost, getMyCustomValue, getAttributeText and a few others.

$_options = Mage::getModel('catalog/product_option')->getProductOptionCollection($product);
//var_dump($_options,true);
foreach ($_options as $option) {
    //print_r($option);
    $title = $option->getDefaultTitle();
    //foreach ($option->getValues() as $value) {
    //  print_r($value->getData());
    //}     
    $value = $option->getOptionText();
    echo "<br />".$title." - ".$value."<br />";
}

I am working within /app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php in Magento 1.9.1. Any idea which function is used to "get" the text field of a custom option?

  • Why are you working in this file? You shouldn't edit the core! That being said, $product->getCustomOption($code)['value'] should work, but only if this product instance has already been prepared with the user data. – Fabian Schmengler Jul 15 '15 at 14:43
  • Just trying to adjust pricing on a product. I will be reverting and moving to the appropriate location. What is $code? Does that need to be changed? – NotJay Jul 15 '15 at 14:48
  • $code is the code of the custom option. If you want to access all custom options, use $product->getCustomOptions() instead to get an array. But do yourself a favor and do it right from the beginning: what you need is an observer for catalog_product_get_final_price (as explained here: magento.stackexchange.com/a/74463/243) – Fabian Schmengler Jul 15 '15 at 14:52

Your Answer

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

Browse other questions tagged or ask your own question.