Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Integration with Fluxstore app technical question
This topic contains 15 replies, has 2 voices, and was last updated by abhijitpattil 10 months, 1 week ago.
- AuthorPosts
- May 7, 2022 at 3:00 pm #37734
Hi,
I am looking to integrate the ASP with FluxStore App. I am exploring ways to do it. One question came from devloper of FluxStore App.
“Could you check if the Ajax Search Pro supports the JSON request or XHR request (with JSON return format) then it could be integrated with FluxStore app.”
Can you please give your input on this question?
May 9, 2022 at 9:18 am #37739Hi,
By default the plugin returns structured HTML output with additional information via JSON separated by delimiters. The JSON information is returned as a string inbetween
!!ASPSTART_DATA!!
and!!ASPEND_DATA!!
delimiters.This data can be parsed from the XHR response like this:
data_response = response.match(/!!ASPSTART_DATA!!(.*[\s\S]*)!!ASPEND_DATA!!/); data_response = JSON.parse(data_response[1]);
The
Best,data_response
variable wil contain the results as an object array. This is a javascript example, but the same can be achieved with any other programming language.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 10, 2022 at 1:18 pm #37757Hi @Ernest,
FluxStore team is actively checking to integrate Ajax Search Pro with their app. They have one more question.
Hi, could you help to check with Ajax Search Pro to see if they could share the example of the URL when requesting via Postman ?
Please give me details! Thank you!
May 10, 2022 at 2:57 pm #37760Okay, I will try to help with this as much as possible. Unfortunately the plugin does not have a rest API yet, but we have a documentation on adding custom endpoints via the WP Rest API.
The main issue with integration is, that users can create multiple search instances, each with different configurations – and it is very much possible to have multilpe search bars configured differently for woocommerce, as well as search bars not searching WooCoomerce at all at the same time.
Doing a “generic” request to do a search is not going to work, the specific search bar has to be specified by ID.To simplify this, I constructed this REST endpoint, which tries to “auto detect” the search instance created for WooCommerce. This exact endpoint will be implemented in a future release. If you add this to your theme functions.php file:
function asp_custom_rest_handler( $data ) { $id = -1; $defaults = $args = array( 's' => '' ); foreach ( $defaults as $k => $v ) { $param = $data->get_param($k); if ( $param !== null ) { $args[$k] = $param; } } // Fetch the search ID, which is probably the WooCommerce search foreach ( wd_asp()->instances->get() as $instance ) { if ( in_array('product', $instance['data']['customtypes'] ) ) { $id = $instance['id']; break; } } // No search was found with products enabled, set it explicitly if ( $id == -1 ) { $args['post_type'] = array('product'); } $asp_query = new ASP_Query($args, $id); return $asp_query->posts; } // POST to: http://example.com/wp-json/ajax-search-pro/v1/woo_search add_action( 'rest_api_init', function () { register_rest_route('ajax-search-pro/v0', '/woo_search', array( 'methods' => 'POST', 'callback' => 'asp_custom_rest_handler', )); });
Then the usage is:
curl --location --request POST 'https://test.local/wp-json/ajax-search-pro/v1/woo_search?s=test'
..or postman link.
We are planning to add this exact endpoint as well to a future release – so they can safely implement requests to it now if they want to, it will be compatible.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 10, 2022 at 3:10 pm #37763Hi @Ernest,
Thank you for taking time to do this! I really appreciate your time & work! I have forwarded your reply in detail to FluxStore Team. If they have any more questions i will contact you. I hope some fruitful outcome from this experiment.
May 18, 2022 at 3:29 pm #37794Hi @Ernest,
I have received below message from FluxStore App team that they have successfully implemented Ajax Search Pro to their app. (Screenshot attached).
But they are having trouble showing other product data, like product price, product MRP etc.
Hence, again i am requesting you to kindly help us over here.“Confirm the feature is done and will ready on v3.0 – https://tppr.me/E3U3x
Could you contact Ajax Search Pro on how to display the pricing from the Product? We could not see from the search result.”
Attachments:
You must be logged in to view attached files.May 20, 2022 at 9:45 am #37803Hi,
I recommend getting that information via the WooCommerce API functions instead. The plugin returns the post type objects as results, as requested from wordpress, and some additional data is added to the
$post->asp_data
variable. However that may not be set for API searches like this, I need to double check.Try changing the $defaults variable in the above code to:
$defaults = $args = array( 's' => '', '_ajax_search' => true );
Then in the results objects, the
$post->content
or the$post->asp_data->content
should have the same exact output of the title and content fields as in the site ajax search.I am not a 100% sure, you may have to test this to be sure.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 20, 2022 at 9:52 am #37806Hello again!
Thanks for reply! I have forwarded this to FluxStore App team. I will tell them to test this and experiment. I will contact you if they have any more questions regarding this.
May 21, 2022 at 6:09 am #37815Hi @Ernest,
I tried adding
$defaults = $args = array( 's' => '', '_ajax_search' => true );
this to functions.php file but the results missing asp_data field completely. Below are results before adding this and after. Can you please check again?
RESPONSE ON POSTMAN (BEFORE)
[ { "ID": 3096, "post_author": "28", "post_date": "2022-01-11 14:37:23", "post_date_gmt": "2022-01-11 09:07:23", "post_content": "Each strip contain 10 tablets", "post_title": "Levocetirizine 5mg and Montelukast 10mg Tablet", "post_excerpt": "Levocetirizine (5mg) + Montelukast (10mg) Tablet", "post_status": "publish", "comment_status": "closed", "ping_status": "closed", "post_password": "", "post_name": "levocetirizine-5mg-and-montelukast-10mg-tablet", "to_ping": "", "pinged": "", "post_modified": "2022-05-10 20:54:12", "post_modified_gmt": "2022-05-10 15:24:12", "post_content_filtered": "", "post_parent": 0, "guid": "http://janaushadhistore.in/?post_type=product&p=3096", "menu_order": 0, "post_type": "product", "post_mime_type": "", "comment_count": "0", "filter": "raw", "asp_guid": "https://janaushadhistore.in/shop/levocetirizine-5mg-and-montelukast-10mg-tablet/", "asp_id": 3096, "blogid": 1, "asp_data": { "id": 3096, "blogid": 1, "title": "Levocetirizine 5mg and Montelukast 10mg Tablet", "post_title": "Levocetirizine 5mg and Montelukast 10mg Tablet", "content": "Levocetirizine (5mg) + Montelukast (10mg) Tablet", "excerpt": "Levocetirizine (5mg) + Montelukast (10mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Montelukast-Levocetrizine.jpg", "date": "2022-01-11 14:37:23", "post_date": "2022-01-11 14:37:23", "menu_order": 0, "relevance": 1000200, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 0, "link": "https://janaushadhistore.in/shop/levocetirizine-5mg-and-montelukast-10mg-tablet/", "asp_guid": "https://janaushadhistore.in/shop/levocetirizine-5mg-and-montelukast-10mg-tablet/" } }, { "ID": 3091, "post_author": "28", "post_date": "2022-01-11 14:29:07", "post_date_gmt": "2022-01-11 08:59:07", "post_content": "Each strip contain 10 tablets", "post_title": "Montelukast 10mg Tablet", "post_excerpt": "Montelukast (10mg) Tablet", "post_status": "publish", "comment_status": "closed", "ping_status": "closed", "post_password": "", "post_name": "montelukast-10mg-tablet", "to_ping": "", "pinged": "", "post_modified": "2022-05-10 20:56:12", "post_modified_gmt": "2022-05-10 15:26:12", "post_content_filtered": "", "post_parent": 0, "guid": "http://janaushadhistore.in/?post_type=product&p=3091", "menu_order": 0, "post_type": "product", "post_mime_type": "", "comment_count": "0", "filter": "raw", "asp_guid": "https://janaushadhistore.in/shop/montelukast-10mg-tablet/", "asp_id": 3091, "blogid": 1, "asp_data": { "id": 3091, "blogid": 1, "title": "Montelukast 10mg Tablet", "post_title": "Montelukast 10mg Tablet", "content": "Montelukast (10mg) Tablet", "excerpt": "Montelukast (10mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Montelukast-10.jpg", "date": "2022-01-11 14:29:07", "post_date": "2022-01-11 14:29:07", "menu_order": 0, "relevance": 1000200, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 1, "link": "https://janaushadhistore.in/shop/montelukast-10mg-tablet/", "asp_guid": "https://janaushadhistore.in/shop/montelukast-10mg-tablet/" } }, { "ID": 3093, "post_author": "28", "post_date": "2022-01-11 14:36:27", "post_date_gmt": "2022-01-11 09:06:27", "post_content": "Each strip contain 10 tablets", "post_title": "Montelukast 10mg and Fexofenadine 120mg Tablet", "post_excerpt": "Montelukast (10mg) + Fexofenadine (120mg) Tablet", "post_status": "publish", "comment_status": "closed", "ping_status": "closed", "post_password": "", "post_name": "montelukast-10mg-and-fexofenadine-120mg-tablet", "to_ping": "", "pinged": "", "post_modified": "2022-05-10 20:55:08", "post_modified_gmt": "2022-05-10 15:25:08", "post_content_filtered": "", "post_parent": 0, "guid": "http://janaushadhistore.in/?post_type=product&p=3093", "menu_order": 0, "post_type": "product", "post_mime_type": "", "comment_count": "0", "filter": "raw", "asp_guid": "https://janaushadhistore.in/shop/montelukast-10mg-and-fexofenadine-120mg-tablet/", "asp_id": 3093, "blogid": 1, "asp_data": { "id": 3093, "blogid": 1, "title": "Montelukast 10mg and Fexofenadine 120mg Tablet", "post_title": "Montelukast 10mg and Fexofenadine 120mg Tablet", "content": "Montelukast (10mg) + Fexofenadine (120mg) Tablet", "excerpt": "Montelukast (10mg) + Fexofenadine (120mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Montelukast-Fexofenadine.jpg", "date": "2022-01-11 14:36:27", "post_date": "2022-01-11 14:36:27", "menu_order": 0, "relevance": 1000120, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 2, "link": "https://janaushadhistore.in/shop/montelukast-10mg-and-fexofenadine-120mg-tablet/", "asp_guid": "https://janaushadhistore.in/shop/montelukast-10mg-and-fexofenadine-120mg-tablet/" } }, { "ID": 3077, "post_author": "28", "post_date": "2022-01-11 13:01:53", "post_date_gmt": "2022-01-11 07:31:53", "post_content": "Each strip contain 10 tablets", "post_title": "Acebrophylline 200mg and Montelukast 10mg Tablet SR", "post_excerpt": "Acebrophylline (200mg) + Montelukast (10mg) Tablet", "post_status": "publish", "comment_status": "closed", "ping_status": "closed", "post_password": "", "post_name": "acebrophylline-200mg-and-montelukast-10mg-tablet-sr", "to_ping": "", "pinged": "", "post_modified": "2022-05-10 21:02:48", "post_modified_gmt": "2022-05-10 15:32:48", "post_content_filtered": "", "post_parent": 0, "guid": "http://janaushadhistore.in/?post_type=product&p=3077", "menu_order": 0, "post_type": "product", "post_mime_type": "", "comment_count": "0", "filter": "raw", "asp_guid": "https://janaushadhistore.in/shop/acebrophylline-200mg-and-montelukast-10mg-tablet-sr/", "asp_id": 3077, "blogid": 1, "asp_data": { "id": 3077, "blogid": 1, "title": "Acebrophylline 200mg and Montelukast 10mg Tablet SR", "post_title": "Acebrophylline 200mg and Montelukast 10mg Tablet SR", "content": "Acebrophylline (200mg) + Montelukast (10mg) Tablet", "excerpt": "Acebrophylline (200mg) + Montelukast (10mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Acebrophyline-Montelukast_-1.jpg", "date": "2022-01-11 13:01:53", "post_date": "2022-01-11 13:01:53", "menu_order": 0, "relevance": 1000120, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 3, "link": "https://janaushadhistore.in/shop/acebrophylline-200mg-and-montelukast-10mg-tablet-sr/", "asp_guid": "https://janaushadhistore.in/shop/acebrophylline-200mg-and-montelukast-10mg-tablet-sr/" } } ]
RESPONSE ON POSTMAN (AFTER)
[ { "id": 3096, "blogid": 1, "title": "Levocetirizine 5mg and Montelukast 10mg Tablet", "post_title": "Levocetirizine 5mg and Montelukast 10mg Tablet", "content": "Levocetirizine (5mg) + Montelukast (10mg) Tablet", "excerpt": "Levocetirizine (5mg) + Montelukast (10mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Montelukast-Levocetrizine.jpg", "date": "2022-01-11 14:37:23", "post_date": "2022-01-11 14:37:23", "menu_order": 0, "relevance": 1000200, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 0, "link": "https://janaushadhistore.in/shop/levocetirizine-5mg-and-montelukast-10mg-tablet/" }, { "id": 3091, "blogid": 1, "title": "Montelukast 10mg Tablet", "post_title": "Montelukast 10mg Tablet", "content": "Montelukast (10mg) Tablet", "excerpt": "Montelukast (10mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Montelukast-10.jpg", "date": "2022-01-11 14:29:07", "post_date": "2022-01-11 14:29:07", "menu_order": 0, "relevance": 1000200, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 1, "link": "https://janaushadhistore.in/shop/montelukast-10mg-tablet/" }, { "id": 3093, "blogid": 1, "title": "Montelukast 10mg and Fexofenadine 120mg Tablet", "post_title": "Montelukast 10mg and Fexofenadine 120mg Tablet", "content": "Montelukast (10mg) + Fexofenadine (120mg) Tablet", "excerpt": "Montelukast (10mg) + Fexofenadine (120mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Montelukast-Fexofenadine.jpg", "date": "2022-01-11 14:36:27", "post_date": "2022-01-11 14:36:27", "menu_order": 0, "relevance": 1000120, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 2, "link": "https://janaushadhistore.in/shop/montelukast-10mg-and-fexofenadine-120mg-tablet/" }, { "id": 3077, "blogid": 1, "title": "Acebrophylline 200mg and Montelukast 10mg Tablet SR", "post_title": "Acebrophylline 200mg and Montelukast 10mg Tablet SR", "content": "Acebrophylline (200mg) + Montelukast (10mg) Tablet", "excerpt": "Acebrophylline (200mg) + Montelukast (10mg) Tablet", "image": "https://janaushadhistore.in/wp-content/uploads/Acebrophyline-Montelukast_-1.jpg", "date": "2022-01-11 13:01:53", "post_date": "2022-01-11 13:01:53", "menu_order": 0, "relevance": 1000120, "priority": 100, "group_priority": 1, "p_type_priority": 1, "post_type": "product", "customfp": "1", "customfs": "1", "content_type": "pagepost", "g_content_type": "post_page_cpt", "primary_order": 3, "link": "https://janaushadhistore.in/shop/acebrophylline-200mg-and-montelukast-10mg-tablet-sr/" } ]
I have attached json file downloaded from POSTMAN below.
Used URL for test: https://janaushadhistore.in/wp-json/ajax-search-pro/v0/woo_search?s=montekCode added to functions.php file
function asp_custom_rest_handler( $data ) { $id = -2; $defaults = $args = array( 's' => '', '_ajax_search' => true ); foreach ( $defaults as $k => $v ) { $param = $data->get_param($k); if ( $param !== null ) { $args[$k] = $param; } } // Fetch the search ID, which is probably the WooCommerce search foreach ( wd_asp()->instances->get() as $instance ) { if ( in_array('product', $instance['data']['customtypes'] ) ) { $id = $instance['id']; break; } } // No search was found with products enabled, set it explicitly if ( $id == -2 ) { $args['post_type'] = array('product'); } $asp_query = new ASP_Query($args, $id); return $asp_query->posts; } // POST to: http://example.com/wp-json/ajax-search-pro/v1/woo_search add_action( 'rest_api_init', function () { register_rest_route('ajax-search-pro/v0', '/woo_search', array( 'methods' => 'POST', 'callback' => 'asp_custom_rest_handler', )); });
Attachments:
You must be logged in to view attached files.May 23, 2022 at 11:41 am #37822Okay, it is actually what I expected. I would recommend using the initial solution then, it includes much more information.
To answer the original question: the
Best,$post->asp_data->content
field contains the “description” field as defined by the user on the ajax search pro back-end, I would recommend using that. They can customize the output of that field via the advanced title/content fields feature, which supports displaying the price and other custom field/taxonomy contents. I believe that is what the user expects to see by default.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 23, 2022 at 11:55 am #37823Hi @Ernest,
I will surely try and let you know the results.
May 23, 2022 at 12:36 pm #37828Hi @Ernest,
Can you please tell me how to show ‘Add To Cart’ Button using this method in Description?
May 23, 2022 at 2:02 pm #37834The only way to do that is via a custom code, this knowledge base will help.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 26, 2022 at 5:13 am #37862Thanks for update! Also, please check FluxStore App They have included compatibility for Ajax Search Pro! Because of your help this was possible at all! Thank you very much!
May 26, 2022 at 10:26 am #37865That is fantastic, thank you for mediating in this 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.