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?
$product->getCustomOption($code)['value']
should work, but only if this product instance has already been prepared with the user data.$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 forcatalog_product_get_final_price
(as explained here: magento.stackexchange.com/a/74463/243)