On the Create an Order page (/admin/commerce/orders/add), my client is not able to see more than 10 items in the dropdown when using the 'Add Line Item' for a Product. I can see that in the commerce_product.module that the function function commerce_product_autocomplete() is limiting with the following line:

// Get an array of matching products.
$products = commerce_product_match_products($field, $instance, $tag_last, $match, array(), 10);

..but how can this be overridden? Trying to implement a change in a custom module does not seem to be read by the system. Can anyone explain why this is, and how it can be changed?

Any help is greatly appreciated. Thanks!

1 Answer 1


This should be the screen you are referring to yes?

Add product to order

The field here is an auto complete field that is widely used in Drupal Commerce. And yes the hints are limited because if they were not limited then the AJAX call could take a very long time to run. You have to keep typing to narrow down your options in the provided guesses.

Short answer: No you cannot change this without hacking Commerce.

Long answer: To change this would require a lot of work because the create order form (/admin/commerce/orders/add) is built by attaching fields from the entity. Specifically here is the code that creates the form in the image above. So in order to change this you would have to alter the field types of the order entity. Specifically the Product SKU field would have to be altered and it's call back replaced with one that would load more than 10 items. Doing so would of course alter Commerce and any upgrade you did to Commerce would erase your alterations.

// Add the field related form elements.
$form_state['commerce_order'] = $order;
field_attach_form('commerce_order', $order, $form, $form_state);

This uses field_attach_form to attach elements to the existing form based off the entity, in this case the entity 'commerce_order'.

  • 1
    That is a very thorough answer, Brady - thanks! Unfortunately, I am required to change this for my client. From what I've understood of what you've said, it looks like my only viable hope is to apply a patch, which I would of course have to modify for each new variation of commerce that I later upgrade to. Would you agree that is pretty much the only way to accomplish this?
    – PWM
    Dec 16, 2014 at 1:04
  • 1
    Yes a patch would be the only way to go, then you would need to perform regression testing whenever you update Commerce (which isn't often thankfully). I have been running a large ecommerce site for 2.5 years and haven't had to upgrade Commerce yet.
    – Brady
    Dec 16, 2014 at 7:20
  • Great answer, Brady, and I second the ned for a patch here. For what it's worth, I use drush make files now to build the codebase for my projects thanks to Platform.sh, so applying patches that we maintain internally is automated. However, for the projects I maintain on Pantheon or bespoke hosting I add a patches folder to sites/all (or the relevant modules parent directory, sometimes a profile) and use a subdirectory for each contrib module I patch so I can scan it for patches as part of my manual module update process. Hope that helps. Dec 16, 2014 at 11:24

Your Answer

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

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