Access Stores Programmatically

Agile Store Locator provides support for programmatically retrieving stores using PHP. To obtain the stores, you can utilize the following method:

$clauses = [];

$limit = 100;
$offset = 0;

\AgileStoreLocator\Model\Store::get_stores($clauses, $limit, $offset);

You can pass various parameters in the $clauses array to filter the store values. The available parameters include:

  • title: Filter by store title.
  • description: Filter by store description.
  • street: Filter by store street address.
  • city: Filter by store city.
  • state: Filter by store state.
  • postal_code: Filter by store postal code.
  • phone: Filter by store phone number.
  • fax: Filter by store fax number.
  • email: Filter by store email.
$clauses = ['city' => 'NY'];

$limit = 100;
$offset = 0;

\AgileStoreLocator\Model\Store::get_stores($clauses, $limit, $offset);

By customizing these parameters in the $clauses array, you can retrieve the desired store information programmatically.

Create Cards without PHP #

If you prefer to avoid using PHP, Agile Store Locator also provides store cards that can be displayed using the [ASL_CARDS] shortcode. You can pass parameters to customize the displayed stores in a similar manner, you can follow the store cards documentation.

Create a New Store Programatically #

//	Create a new store programatically
if(method_exists("\AgileStoreLocator\Admin\Store", 'add_new_store')) {

	$store_data = [
		"title" => "Bid-Bon Development",
		"description" => "bid bid",
		"street" => "274 Kragga Kamma Road, Lorraine",
		"city" => "Port Elizabeth",
		"state" => "Eastern Cape",
		"postal_code" => "23452",
		//"lat" => "-33.96524",
		//"lng" => "25.50242",
		"phone" => "041 888 3534",
	];


	//	Todo, change it
	$have_coordinates = false;
    
    // Add Business Hours (JSON accepted)
    $store_data['open_hours'] = '{"mon":["09:30 AM - 06:30 PM"],"tue":["09:30 AM - 06:30 PM"],"wed":["09:30 AM - 06:30 PM"],"thu":["09:30 AM - 06:30 PM"],"fri":["09:30 AM - 06:30 PM"],"sat":"0","sun":"0"}';    

	//	I don't have coordinates :( Let's fetch it
	if(!$have_coordinates) {

		$google_server_key = \AgileStoreLocator\Helper::get_configs('server_key');

		//	1- Get the Coordinates for the provided zipcode
		$coordinates   		= \AgileStoreLocator\Helper::getCoordinates($store_data['street'], $store_data['city'], $store_data['state'], $store_data['postal_code'], $store_data['country'], $google_server_key);

		//	Found coordinates?
		if(!empty($coordinates)) {

				$store_data['lat'] = $coordinates['lat'];
				$store_data['lng'] = $coordinates['lng'];
		}
	}

	//  Add it to request['data']
	$_REQUEST['data'] = $store_data;
    
    // Custom Fields
	$_REQUEST['asl-custom'] = ['field_name_1' => 'xyz', 'field_name_2' => 'abc'];

	//	Create an instance
	$store_inst = new \AgileStoreLocator\Admin\Store();
	
	// Must be returned as object, else it will die
	$store_inst->as_object = true;

	//	Create Store
	$response = $store_inst->add_new_store();


	echo '<pre>';
	print_r($response);
	echo '/<pre>';
	die;
}

Access All Categories #


if(method_exists("\AgileStoreLocator\Model\Category", 'get_categories')) {

	$lang 			= ''; // Keep empty for default

	//	Get the Stores Categories
	$categories = \AgileStoreLocator\Model\Category::get_categories($lang);
}

To access them in parent and child hierarchy.

if(method_exists("\AgileStoreLocator\Model\Category", 'get_categories')) {

	$lang 			= ''; // Keep empty for default

	//	Get the Stores Categories
	$categories = \AgileStoreLocator\Model\Category::get_app_categories($lang);
}