Integration with Fluxstore app technical question

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Integration with Fluxstore app technical question

This topic contains 7 replies, has 2 voices, and was last updated by abhijitpattil abhijitpattil 2 hours, 6 minutes ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #37734
    abhijitpattil
    abhijitpattil
    Participant

    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?

    #37739
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #37757
    abhijitpattil
    abhijitpattil
    Participant

    Hi @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!

    #37760
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Okay, 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 :)


    #37763
    abhijitpattil
    abhijitpattil
    Participant

    Hi @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.

    #37794
    abhijitpattil
    abhijitpattil
    Participant

    Hi @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.
    #37803
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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 :)


    #37806
    abhijitpattil
    abhijitpattil
    Participant

    Hello 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.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.