On our Drupal Commerce site, the Admin order-taking edit form (/admin/commerce/orders/*/edit) provides a pop-up menu to add products after you click the Add Line Item button.

However, I seem to recall it used to give us an Autocomplete text field instead. I think we changed this somewhere at some point to pop-up menu, but now really need to change it back, as we have too many products so a pop-up menu is crazy making.

I've tried changing it in manage fields for Product Display node and in Product entity, but that hasn't had an effect on the Admin order edit form.

Is there a way to change this product selector?

Comments

rszrama’s picture

Title: How do I change the Add Line Item product selector to an Autocomplete text field on the Admin order edit view » Use an autocomplete textfield for adding products to orders
Version: 7.x-1.0 » 7.x-1.x-dev
Category: support » feature

Actually, I don't believe that's ever had autocomplete integration. You probably changed it on your node type by using the "Autocomplete textfield" widget for the product reference field, but here it's still just a lowly select list. This should be upgraded to a feature request.

somatics’s picture

Ryan,
Thanks for the information. I guess I must just be mis-remembering that it had ever been an autocomplete field.

I think it would be really a great idea to make this a feature -- with even 100 hundred products (and we have several hundred), it's unmanageable to scroll through a list (and it irritates impatient customers!).

Do I have to do anything to request this feature, or is your change of the Category of this post sufficient?

Thanks again!
Steve

rszrama’s picture

My change will do the trick. I meant to do this long ago, so it's definitely gonna get in. : )

somatics’s picture

Awesome. Thanks, and as usual keep up the good work!

rszrama’s picture

Issue tags: +1.1 blocker

Tagging.

rfay’s picture

I think this one might go too many levels deep for me today :-)

paul.linney’s picture

I had changed this too for a current project, so made a patch that adds the autocomplete. The only thing I don't like is that it dumps the number into the textfield instead of a nice SKU: Name.

regards,
Paul

paul.linney’s picture

The actual file this time.

rfay’s picture

Status: Active » Needs review
rszrama’s picture

Status: Needs review » Active

Thanks for posting what you had working, Paul. However, I'd like to just copy the code from the Product Reference module, specifically from commerce_product_reference_field_widget_form() and commerce_product_reference_autocomplete_validate() so that there's no need to change the way the autocomplete callback works in the Product module. We should be able to do the exact same thing the autocomplete text field does here, which is use an element validate handler to convert SKUs into product IDs once the form is submitted.

paul.linney’s picture

Status: Active » Needs review
StatusFileSize
new3.54 KB

Thanks Ryan,

Makes sense not to alter the product module, so I had another look at this and copied the validation from the widget. I also added some error messages for empty submissions and attempts on multiple SKUs.

Updated `commerce_product_line_item_add_form` to prevent loading all the products, as autocomplete doesn't need these.

When adding additional line items with the same product id, is there a way to combine them if the exist in the order already or should they stay separate?

Paul

rszrama’s picture

It hasn't combined them thus far, and I think I'm happy with that. There's really no reason for it when the quantity update widget is baked right into the form. Will try to give this a review and get it in.

Status: Needs review » Needs work

The last submitted patch, 1292690-order-edit-product-add-autocomplete-1.patch, failed testing.

rszrama’s picture

Status: Needs work » Fixed

Ok, as it turns out, this was both simpler and a little more complex. It was simpler because this doesn't need any sort of validation based on multiple SKUs like the product reference widget does. It was more complex because the line item manager widget as coded doesn't really support the normal process of validation inside these AJAX calls. It's unfortunate, but the whole system is going to be replaced by an Inline Product Form approach in 2.x. I don't see any reason to make it all work here now when it's going to be rebuilt from scratch next version.

I also had to go through and fix various tests to accommodate the changed form element name and input type.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/1809ec3

paul.linney’s picture

Good stuff. I'll need to take a look at the Inline Product Form you have been working on and I did notice the test failure issues, just time got the better of me.

Paul

giorgosk’s picture

thanks for this feature but there are products that have attributes and hence the autocomplete can not accommodate adding attributes (color, size etc)

should I open up a seperate feature request for this ?

IMHO at least there should be a way to disable adding products for the admin or is a simple permission setting ?

the premise is that if eshop products have attributes giving the admin an incomplete way to add products is at the very least confusing

EDIT: forget about this request, I understand that you are going to implement this on 2.x version

WORKAROUND: for now the admins can create orders for themselves and when done change the user of the order.

rszrama’s picture

Yeah, they can assign the order to the user it needs to be for on the initial submit of the order add form. Also, because every variation of products attributes is represented by a separate product w/ a unique SKU, the autocomplete can easily accommodate products with attributes. The form has never actually presented grouped products like the Add to Cart form does, but as you found out about 2.x plans, we hope to fix that. : )

Automatically closed -- issue fixed for 2 weeks with no activity.