Want to display a drop down select instead of the text input field in Drupal's Ubercart?


Category: drupal

Open modules/ubercart/uc_product/uc_product.module

Around line #1299 replace


  if ($node->default_qty > 0 && variable_get('uc_product_add_to_cart_qty', FALSE)) {
    $form['qty'] = array('#type' => 'textfield',
      '#title' => t('Quantity'),
      '#default_value' => $node->default_qty,
      '#size' => 5,
      '#maxlength' => 6,
    );
  }


With


  if ($node->default_qty > 0 && variable_get('uc_product_add_to_cart_qty', FALSE)) {
    $form['qty'] = array('#type' => 'select',
      '#title' => t('Quantity'),
      '#default_value' => $node->default_qty,
      '#options' => array(1=>'1',2=>'2',3=>'3',4=>'4',5=>'5',6=>'6',7=>'7',8=>'8',9=>'9',10=>'10',)
    );
  }


Substitue the array with whichever values you would like the drop down to offer. It's that simple :)


Comments

Is there a way to do by role

Thanks for this!
Is there a way to do this based on user role. For example, if logged in as 'dealer' show select box else show textbox.

Not Working

Its change text box to drop down select quantity, but when customer add to cart (3 pcs) , cart still count quantity as '1'.

My dropdown quantity has 3, 6, 9, 12, 15, 18 etc. When customer select '3', shopping cart still count quantity as '1', '6' as '2', '9' as '3' and so on. Please help.

Simply change the option text

Simply change the option text shown above to be the desired quantities you wish to use :)

Thanks~

Thanks~

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.