Home /Tutorials /Retrieving members by promotion key
Retrieving members by promotion key

NotePromotions were rebranded as Purchase Options after this code was initially written. In the future, we aim to refactor our code to use consistent terminology.

To get started, you’ll need the business and location keys. You can use the ListModel endpoint to retrieve these for all locations in the business.

// Retrieve the list of locations for a business. 
$o_model = new \WellnessLiving\Wl\Location\ListModel($o_config); 
$o_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. 
$o_model->k_business='3'; 
$o_model->get(); 
 
// Print the location ID, name, and address. 
foreach($o_model->a_location as $a_location) 
  echo $a_location['k_location'].'    '.$a_location['s_title'].'    '.$a_location['text_address']."\n"; 

After obtaining the k_location, you can retrieve a list of Purchase Options sold at the location by using the CatalogListModel endpoint. Filter the results based on the id_sale values representing different types of Purchase Options: 

  • PROMOTION_CLASS = 1 for classes
  • PROMOTION_SERVICE = 2 for appointments
  • PACKAGE = 5 for packages
  • PROMOTION_RESOURCE = 9 for Book-a-Spot assets

You need the k_id for the matching Purchase Options, which corresponds to the k_promotion value in this case.

// Retrieve the list of products from the store. 
$o_catalog_model = new \WellnessLiving\Wl\Catalog\StaffApp\CatalogList\CatalogListModel($o_config); 
$o_catalog_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. 
$o_catalog_model->k_business='3'; 
$o_catalog_model->k_location='3'; 
 
// Perform the request. 
$o_catalog_model->get(); 

// Print each product's k_id, id_sale, and name. 
foreach ($o_catalog_model->a_shop_product as $a_product) 
{ 
  if($a_product['id_sale'] === WlSaleSid::PROMOTION_SERVICE) 
    echo 'Appointment Membership: '; 
  else if($a_product['id_sale'] === WlSaleSid::PROMOTION_CLASS) 
    echo 'Class Membership: '; 
  else if($a_product['id_sale'] === WlSaleSid::PACKAGE) 
    echo 'Package: '; 
  else if($a_product['id_sale'] === WlSaleSid::PROMOTION_RESOURCE) 
    echo 'Resource Membership: '; 
  echo $a_product['k_id'].' '.$a_product['id_sale'].' '.$a_product['text_title']."\n"; 
}

Once you’ve selected the k_promotion values, you can retrieve the members who own these Purchase Options with the MemberByPromotionModel endpoint. Only members with active Purchase Options will be returned. Multiple Purchase Options can be requested in one call by providing their keys as a comma-separated list.

// Retrieve members by Purchase Option keys.
$o_promotion_model = new \WellnessLiving\Wl\Member\Purchase\MemberByPromotionModel($o_config); 
$o_promotion_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. 
$o_promotion_model->k_business='3'; 
$o_promotion_model->s_promotion_keys='1,16,29'; 

// Perform the request. 
$o_promotion_model->get(); 
 
foreach($o_promotion_model->a_clients as $a_client) 
 echo $a_client['uid']."\n";