I can't believe I could not find a solution to an issue which was supposed to be a simple, common sense one.
If I chosse to add a custom option as date field for a product, I want to have the month displaying in its long format in the drop-down field and not as a number.
So instead of having 01,02,03 etc in the drop-down I want to have January,February,March etc.
However, there is apparently NO option in magento to achieve that even though short,medium & long form for "month" are definied somewhere in the core.
So in short: Admin > Product > Custom Options > added date option (dispalying as standard drop-down).
I need to replace the 01,02,03 with January,February,March etc.
Can someone please help me achieve that?
Thanks!
PS: this forum is FULL of BUGS and prevents one from posting by throwing back apparent error messages while NO error is actually present and/or displayed! Wasted 1/2 hour to be able to post a simple message!
Solved! Go to Solution.
Easy man, this forum has been imporved a lot and is getting better, its not hard to use.
About your question, its also easy, add this method to Mage_Catalog_Block_Product_View_Options_Type_Date (its better to rewrite it in local)
protected function _getMonthSelectFromToHtml($name, $from, $to, $value = null) { $options = array( array('value' => '', 'label' => '-') ); for ($i = $from; $i <= $to; $i++) { $options[] = array('value' => $i, 'label' => Zend_Locale::getTranslation($i, 'Month', Mage::app()->getLocale()->getLocaleCode())); } return $this->_getHtmlSelect($name, $value) ->setOptions($options) ->getHtml(); }
then find out
monthsHtml = $this->_getSelectFromToHtml('month', 1, 12);
in getDropDownsDateHtml, replace with
monthsHtml = $this->_getMonthSelectFromToHtml('month', 1, 12);
There is a block in magento called Mage_Catalog_Block_Product_View_Options_Type_Date. This block has a method
getDropDownsDateHtml that generates the html for the dropdowns. Inside this method, there is a method call to
_getSelectFromToHtml to generate the html for the months. If you create a block class that extends this class, you can change the behavior of the method _getSelectFromToHtml to return full names of the months by making the label text instead of a number.
To utilize your class you would need to update the catalog.xml file in your custom theme to reference this new block class. Here is the catalog.xml snippet you need to override:
<block type="catalog/product_view" name="product.info.options.wrapper" as="product_options_wrapper" template="catalog/product/view/options/wrapper.phtml" translate="label"> <label>Info Column Options Wrapper</label> <block type="core/template" name="options_js" template="catalog/product/view/options/js.phtml"/> <block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml"> ... <action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action> </block>
Change the <block> tag inside the <action> method to reference your new block and that should be that.
Easy man, this forum has been imporved a lot and is getting better, its not hard to use.
About your question, its also easy, add this method to Mage_Catalog_Block_Product_View_Options_Type_Date (its better to rewrite it in local)
protected function _getMonthSelectFromToHtml($name, $from, $to, $value = null) { $options = array( array('value' => '', 'label' => '-') ); for ($i = $from; $i <= $to; $i++) { $options[] = array('value' => $i, 'label' => Zend_Locale::getTranslation($i, 'Month', Mage::app()->getLocale()->getLocaleCode())); } return $this->_getHtmlSelect($name, $value) ->setOptions($options) ->getHtml(); }
then find out
monthsHtml = $this->_getSelectFromToHtml('month', 1, 12);
in getDropDownsDateHtml, replace with
monthsHtml = $this->_getMonthSelectFromToHtml('month', 1, 12);
You are a genious, thank you very much!
After making the changes you advised in app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php it all worked like a charm!
Thanks again! That really helped!