2

I have a custom product option: date of birth. This date is usually the customers dob so I'd like it to be the default value of the custom option field.

In the date.phtml file getDateHtml function is called: <?php echo $this->getDateHtml(); ?>

The function creates the date field. I know how to get dob of the logged in customer but how do I pass it on to the getDateHtml function?

It does check for preconfigured values but i can't set one in custom product options.

Help anyone?

1

I would take a "quick an dirty" approach because modifying the way that custom options behave is not that easy.
how about adding a custom block with a custom phtml to the product page that contains a javascript that fills in the date field.
Something like

<?php if (Mage::getSingleton('customer/session')->isLoggedIn()) : ?>
    <script type="text/javascript">
        var dob = '<?php echo {get customer DOB here} //you already know how to do that ?>';
        $('date_input_id_here').value = dob;//or you can use any other selector
    </script>
<?php endif;?>

Don't take the code above literally. Use it as an idea.

  • Thanks Marius. However I have this custom option in several products and the input ID's are different. Any way to get this to replace all inputs including "date" string? – user2612498 Aug 28 '13 at 8:42
  • I know the id is different but I'm sure you can find a common selector for all of them. I will try and let you know – Marius Aug 28 '13 at 8:55
  • I think I found it. All the date options are selects and the ids look like this: options_*_day, options_*_month, options_*_year. You can get them like this: $$('select[id$="_day"]');. Same for month and year – Marius Aug 28 '13 at 9:00
  • Right. Thanks a lot for your time and help Marius! – user2612498 Aug 28 '13 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.