Presently, the autocomplete callback returns results by assuming the field should be a multiple value reference. I believe it also looks for settings in the field settings array to determine valid product types. That should be altered so the same autocomplete code can work fine on a non-field form element.

Comments

pcambra’s picture

Issue tags: +dcparisprintmarch
pcambra’s picture

pcambra’s picture

I'm not sure of how to face this as the autocomplete function is highly dependent on the field and instance info:

The product reference field calls the autocomplete path this way:
'#autocomplete_path' => $instance['widget']['settings']['autocomplete_path'] . '/' . $instance['entity_type'] . '/' . $field['field_name'] . '/' . $instance['bundle'],

Then, the autocomplete gets the parameters, being the string the last one:
function commerce_product_autocomplete($entity_type, $field_name, $bundle, $string = '') {

And finally the products are returned by the match product function that uses both the field and the instance.
commerce_product_match_products($field, $instance, $tag_last, $match, array(), 10);

What should be done here?, a base autocomplete function and then depending on the information provided by the caller (field, entity_type, bundle...) fetch the products in one way or another?

vasike’s picture

Status: Active » Needs review
StatusFileSize
new3.48 KB

here is a patch inspired by Entity Reference autocomplete.

rszrama’s picture

Issue summary: View changes
Status: Needs review » Needs work

We cannot prepend an argument to this function. It would break any other module depending on the current signature.