Commerce 2 | Quantity Dropdown with Default Values -> Error I need to allow the costumers to choose specific quantities for specific type of products but I would like to avoid adding 2 extra modules to my website ( Commerce Extended Quantity &amp; Extended Number Field). So I used a form alter function like here Set default &quot;Quantity&quot; dropdown select in product. Commerce Kickstart. 

The issue is that the input is transformed to a dropdown but when the form is submitted, a blank page appears with the message "The website encountered an unexpected error" and the error in admin/reports/dblog is Cannot unset string offsets in Drupal\Core\Field\WidgetBase-&gt;extractFormValues()... Here is the code I use:

function mymodule_form_alter(&amp;$form, $form_state, $form_id) {

  if (strpos($form_id, "commerce_order_item_add_to_cart_form") !== false) {

  // Change widget type of quantity to select list
 $form['quantity'] = array(
'#title' =&gt; t('Quantity'),
'#type' =&gt; 'select',
'#datatype' =&gt; 'integer', // &lt;-- I added this one to fix Notice: Undefined index: #datatype in commerce_cart_add_to_cart_form_validate() when you click add to cart button
'#options' =&gt; array(
  1 =&gt; '1',
  2 =&gt; '2',
  3 =&gt; '3'
)
);   


 }}


Does anybody know if there is a way to fix this error? Thanks!
I found the solution to my issue:  

 function mymodule_form_alter(&amp;$form, $form_state, $form_id) {

 if (strpos($form_id, "commerce_order_item_add_to_cart_form") !== false) {
$form['quantity']['widget'][0]['value']['#default_value'] = 1;
 $form['quantity']['widget'][0]['value']['#step'] = 0.5;
   $form['quantity']['widget'][0]['value']['#min'] = 1;
    $form['quantity']['widget'][0]['value']['#max'] = 3;
    $form['quantity']['widget'][0]['value']['#type'] = 'select';       
 $form['quantity']['widget'][0]['value']['#options'] = array(
 '1' =&gt; t('1 hour'),
'1.5' =&gt; t('1,5 hour'),   
  '2' =&gt; t('2 hours'),
   '2.5' =&gt; t('2,5 hours'),
   '3' =&gt; t('3 hours') );
    }}