1

i am using search api with commerce kickstart i have created a view and used it as an exposed form on the homepage, I have used the search api autocomplete module but its not working because the server is not supported. So I have made a custom module to do the autocomplete feature for my search filter block. This is the code

<?php

function ajaxforms_menu() {  
$items['ajaxforms/autocomplete'] = array(
'page callback' => 'ajaxforms_products',
'access arguments' => array('access ajax autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}


function ajaxforms_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form-display_products-page') {
$form['#submit'][] = 'ajaxforms_submit_funtion';
}
}
function ajaxforms_submit_function(&$form, &$form_state) {
$search_str = $form_state['values']['views-exposed-form-display-products-page'];
$form_state['rebuild'] = TRUE;
drupal_goto('path_to_your_search_view', array('query' => array('search_api_view_fulltext' => $search_str)));
}

function ajaxforms_products($string) {
$matches = array();

// DB table which holds products
$query = db_select('commerce_product', 'p');

// Select rows that match the string
$return = $query
->fields('p', array('title'))
->condition('p.title', '%' . db_like($string) . '%', 'LIKE')
->range(0, 10)
->execute();

// add matches to $matches
foreach ($return as $row) {
$matches[$row->title] = check_plain($row->title);
}

drupal_json_output($matches);
}

But its not working I dont know where I am wrong on this. Anyone have any idea on how to solve this ? I want the autocomplete in the block of the exposed filter search which I am using as a block

  • Is there something wrong with the question or did I missed anything because its been sometime that I have posted it and its not been answered yet. Please let me know if I missed something – H_alt Jul 5 '14 at 4:36
1

I got it working by using this example jQuery Autocomplete

If anyone else get stuck in this just ask me and I'll try to help out

| improve this answer | |
  • +1, Hi H_alt can you please help me with this, do you have custom module package ? if not how can I integrate with the custom module, I appreciate your help, thanks. – Bala Sep 5 '14 at 1:09
  • 1
    Yes i do have a custom module but it was not intended for this I just added the js files myself and provided the id of the search textfield in the js(jquery) file and it worked. I never used the actual drupal way to achieve that bcoz I was new(well still am) and couldnt get around it. Still trying to get it done though the drupal way. – H_alt Sep 6 '14 at 8:37
  • Thanks fro your reply I done it with this module drupal.org/project/search_api_autocomplete – Bala Sep 6 '14 at 9:23
  • 1
    In my case this module is not working it does not support the server or the service that the site is built on...Good if it worked for you. – H_alt Sep 7 '14 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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