Home /Tutorials /Getting members by promotion key
Getting members by promotion key

WellnessLiving uses the term “Purchase Option” to formally describe passes, memberships, and packages. However, the developer team informally refers to these as “promotions” throughout the developer documentation. Note that these terms refer to the same thing. 

To get started, we’ll need the business and location keys. We can use the Location\ListModel endpoint to get these for all locations in the business. 

// Get the list of locations for a business. 
$o_model = new \WellnessLiving\Wl\Location\ListModel($o_config); 
$o_model->cookieSet($o_notepad->cookieGet()); // Keep cookies to keep 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 we have the k_location, we can get a list of Purchase Options that the location sells by using the Catalog\StaffApp\CatalogList\CatalogListModel endpoint. We want to list any items with one of the matching id_sale values: 

PROMOTION_CLASS = 1 // Purchase Options for classes.

PROMOTION_SERVICE = 2 // Purchase Options for appointments.

PACKAGE = 5 // Purchase Options for packages.

PROMOTION_RESOURCE = 9 // Purchase Options for Book-a-Spot assets.

We’ll want to get the k_id from the matching Purchase Options, which is the k_promotion value in this case.

 // Gets a 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()); // Keep cookies to keep 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"; 
 }

We can then use the k_promotion values we selected to get the members who own those promotions with the Member\Purchase\MemberByPromotionModel endpoint. Only members with active Purchase Options will be returned. We can request multiple Purchase Options in one call by supplying their keys in a comma-separated list.

$o_promotion_model = new \WellnessLiving\Wl\Member\Purchase\MemberByPromotionModel($o_config); 
$o_promotion_model->cookieSet($o_notepad->cookieGet()); // Keep cookies to keep 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";