Is it possible to add custom values to select options e.g. in configurable products?
I need to add the sku of the option to the option, so that it will become
<option id="354" price="10" sku="my_sku">Option name</option>
I figured out that the Block Class of the Select is Mage_Catalog_Block_Product_View_Options_Type_Select, so I overrided the class but I don't know which code I have to edit.
(削除) I found the definition of addOption in Mage_Catalog_Model_Product_Option but there is no big logic. (削除ここまで)
Edit: This is not the right definition.
The right definition is in the Block class Mage_Core_Block_Html_Select
/**
* Add an option to HTML select
*
* @param string $value HTML value
* @param string $label HTML label
* @param array $params HTML attributes
* @return Mage_Core_Block_Html_Select
*/
public function addOption($value, $label, $params=array())
{
$this->_options[] = array('value' => $value, 'label' => $label, 'params' => $params);
return $this;
}
Cache is deactivated.
1 Answer 1
I figured it out. The definition of addOption is in Mage_Core_Block_Html_Select, there are 3 parameters.
* @param string $value HTML value
* @param string $label HTML label
* @param array $params HTML attributes
You can pass new attributes by passing them as array via the 3rd parameter $params.
$select->addOption(
$_value->getOptionTypeId(),
$_value->getTitle() . ' ' . $priceStr,
array(
'price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false)
, 'sku' => $_value->getSku()
)
);