This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Integration with Fluxstore app technical question

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

#37815
abhijitpattilabhijitpattil
Participant

Hi @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=montek

Code 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',
	));
});