Magento – How to get option label and there value’s label from params passed by product page

magento-1magento-1.7

I have created a new action which is called when the customer select the options on product page and submit the product form. I get this array when i print the params posted.enter image description here

Now how should i get the option labels so that i can save the information what customer have selected in the custom table i have created in the database.

As you can see there is just option ids and there values. I need to save some thing like option label and it's values as it goes to the cart in the default magento.

Update after using Vinai's Solution:

 datepart for part (c) not found in array


 Trace:
 #0 /home/my_dir/public_html/lib/Zend/Date.php(1077): Zend_Date->_calculate('set', Array, 'c', 'en_AU')
 #1 /home/my_dir/public_html/lib/Zend/Date.php(197): Zend_Date->set(Array, 'c', 'en_AU')
 #2 /home/my_dir/public_html/app/code/core/Mage/Core/Model/Locale.php(474): Zend_Date->__construct(Array, 'c', Object(Zend_Locale))
 #3 /home/my_dir/public_html/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php(167): Mage_Core_Model_Locale->date(Array, 'c', NULL, false)
 #4 /home/my_dir/public_html/app/code/local/Browsewire/Quote/controllers/IndexController.php(43): Mage_Catalog_Model_Product_Option_Type_Date->getFormattedOptionValue(Array)
 #5 /home/my_dir/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Browsewire_Quote_IndexController->subformAction()
 #6 /home/my_dir/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('subform')
 #7 /home/my_dir/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
 #8 /home/my_dir/public_html/app/code/core/Mage/Core/Model/App.php(304): Mage_Core_Controller_Varien_Front->dispatch()
 #9 /home/my_dir/public_html/app/Mage.php(596): Mage_Core_Model_App->run(Array)
 #10 /home/my_dir/public_html/index.php(80): Mage::run('', 'store')

11 {main}

Best Answer

It looks like you are talking about individual product options.
You can get at the info as follows:

$params = Mage::app()->getRequest()->getParams();
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->load($params['product']);
$info = new Varien_Object($params);

// Don't throw an exception if required options are missing
$processMode = Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_LITE;

$options = array();
foreach ($product->getOptions() as $option) {
    /* @var $option Mage_Catalog_Model_Product_Option */
    $group = $option->groupFactory($option->getType())
        ->setOption($option)
        ->setProduct($product)
        ->setRequest($info)
        ->setProcessMode($processMode)
        ->validateUserValue($info->getOptions());

    $optionValue = $info->getData('options/' . $option->getId());
    $options[] = array(
        'label' => $option->getTitle(),
        'value' => $group->getFormattedOptionValue($optionValue),
        'print_value' => $group->getPrintableOptionValue($optionValue),
        'option_id' => $option->getId(),
        'option_type' => $option->getType(),
        'custom_view' => $group->isCustomizedView()
    );
}

Now have a look at $options...

For further details refer to Mage_Catalog_Helper_Product_Configuration::getCustomOptions() (used to render the options in the cart) and Mage_Catalog_Model_Product_Type_Abstract::_prepareOptions() (used to prepare the product options for the quote items).