Drupal Commerce, when adding/editing a product display, allows for the creation of new products and the selection of existing products, using the inline entity form.

I have created a marketplace website in which multiple sellers can create their products and product displays.

Question: how to limit the available products to those created by the logged in user? When a seller creates or edits a products, he should be able to only select his own products in he 'add existing product' field.

I would have expected that the field would allow for the selection of an entityreference view, but that seems not implemented in the module.

Alternatives to accomplish the same are welcome! Thanks

1 Answer 1


When you are adding an existing product to a product display there is an autocomplete field that you can use to search existing products.

This field is called entity_id. If you use hook_form_alter() and inspect the form you'll see this field has a property called #autocomplete_path.


$form['product_display_variations'][LANGUAGE_NONE]['form']['entity_id']['#autocomplete_path'] = 'inline_entity_form/autocomplete/node/product_display_variations/product_type';

You can visit that URL and see it just returns a set of json formatted results.

You can create your own path with hook_menu() and then use your path instead of the default one (make this change in hook_form_alter).

In your custom menu callback you can apply any additional logic (e.g. filtering by uid) to just return a sub-set of products. Then use drupal_json_output() to return your dataset.

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.