We are currently using the autocomplete product references to select a product that is associated with a separate content type. Currently this list is a global list that shows all available products, however we would like to limit the return from the autocomplete callback to only show the products that the logged in user created. This can be easily accomplished within a separate module if I could only hook_query_alter the query created within _commerce_product_match_products_standard. But in order to do this, I would like to have a tag added that would allow any module to alter this query from within the autocomplete callback. Then I could do something like this...
/**
* Implementation of hook_query_commerce_product_access_alter().
*/
function mymodule_query_commerce_product_match_alter(QueryAlterableInterface $query) {
global $user;
// If the user does not have access to administer product entities then restrict this list.
if (!user_access('administer commerce_product entities')) {
$query->where('cp.uid=' . $user->uid);
}
}
Patch to follow.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1866310-add-product-match-query-alter-2.patch | 658 bytes | travist |
Comments
Comment #1
travist CreditAttribution: travist commentedHere is the patch that allows this to happen.
Comment #2
travist CreditAttribution: travist commentedHere is the patch that allows this to happen.
Comment #3
rszrama CreditAttribution: rszrama commentedGreat idea. Welcome to the committers log. : )
Comment #4
travist CreditAttribution: travist commentedAwesome. Thanks Ryan.