1

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.

asked May 14, 2019 at 8:47

1 Answer 1

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()
 )
);
answered May 14, 2019 at 9:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.