{"id":308,"date":"2023-09-14T17:53:58","date_gmt":"2023-09-14T17:53:58","guid":{"rendered":"https:\/\/www.wellnessliving.com\/developer-portal\/?p=308"},"modified":"2024-11-11T03:07:43","modified_gmt":"2024-11-11T03:07:43","slug":"getting-members-by-promotion-key","status":"publish","type":"post","link":"https:\/\/www.wellnessliving.com\/developer-portal\/tutorials\/getting-members-by-promotion-key\/","title":{"rendered":"Retrieving members by promotion key"},"content":{"rendered":"\n<p><div class=\"note\"><strong>Note<\/strong>Promotions were rebranded as Purchase Options after this code was initially written. In the future, we aim to refactor our code to use consistent terminology.<\/div><\/p>\n\n\n\n<p>To get started, you\u2019ll need the business and location keys. You can use the\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/wellnessliving\/wl-sdk\/blob\/4a919efe7d18e8403639c4c94600205719f9805b\/WellnessLiving\/Wl\/Location\/ListModel.php\" target=\"_blank\">ListModel<\/a> endpoint to retrieve these for all locations in the business.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve the list of locations for a business. \n$o_model = new \\WellnessLiving\\Wl\\Location\\ListModel($o_config); \n$o_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session. \n$o_model->k_business='3'; \n$o_model->get(); \n \n\/\/ Print the location ID, name, and address. \nforeach($o_model->a_location as $a_location) \n  echo $a_location['k_location'].'    '.$a_location['s_title'].'    '.$a_location['text_address'].\"\\n\"; <\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>After obtaining the <span class=\"coding_type\">k_location<\/span>, you can retrieve a list of Purchase Options sold at the location by using the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/wellnessliving\/wl-sdk\/blob\/4a919efe7d18e8403639c4c94600205719f9805b\/WellnessLiving\/Wl\/Catalog\/StaffApp\/CatalogList\/CatalogListModel.php\" target=\"_blank\">CatalogListModel<\/a> endpoint. Filter the results based on the <span class=\"coding_type\">id_sale<\/span> values representing different types of Purchase Options:&nbsp;<\/p>\n\n\n\n<ul><li><span class=\"coding_type\">PROMOTION_CLASS = 1<\/span> for classes<\/li><li><span class=\"coding_type\">PROMOTION_SERVICE = 2<\/span> for appointments<\/li><li><span class=\"coding_type\">PACKAGE = 5<\/span> for packages<\/li><li><span class=\"coding_type\">PROMOTION_RESOURCE = 9<\/span> for Book-a-Spot assets<\/li><\/ul>\n\n\n\n<p>You need the <span class=\"coding_type\">k_id<\/span> for the matching Purchase Options, which corresponds to the <span class=\"coding_type\">k_promotion<\/span> value in this case.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve the list of products from the store. \n$o_catalog_model = new \\WellnessLiving\\Wl\\Catalog\\StaffApp\\CatalogList\\CatalogListModel($o_config); \n$o_catalog_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session. \n$o_catalog_model->k_business='3'; \n$o_catalog_model->k_location='3'; \n \n\/\/ Perform the request. \n$o_catalog_model->get(); \n\n\/\/ Print each product's k_id, id_sale, and name. \nforeach ($o_catalog_model->a_shop_product as $a_product) \n{ \n  if($a_product['id_sale'] === WlSaleSid::PROMOTION_SERVICE) \n    echo 'Appointment Membership: '; \n  else if($a_product['id_sale'] === WlSaleSid::PROMOTION_CLASS) \n    echo 'Class Membership: '; \n  else if($a_product['id_sale'] === WlSaleSid::PACKAGE) \n    echo 'Package: '; \n  else if($a_product['id_sale'] === WlSaleSid::PROMOTION_RESOURCE) \n    echo 'Resource Membership: '; \n  echo $a_product['k_id'].' '.$a_product['id_sale'].' '.$a_product['text_title'].\"\\n\"; \n}<\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>Once you&#8217;ve selected the <span class=\"coding_type\">k_promotion<\/span> values, you can retrieve the members who own these Purchase Options with the <a href=\"https:\/\/github.com\/wellnessliving\/wl-sdk\/blob\/4a919efe7d18e8403639c4c94600205719f9805b\/WellnessLiving\/Wl\/Member\/Purchase\/MemberByPromotionModel.php\" target=\"_blank\" rel=\"noreferrer noopener\">MemberByPromotionModel<\/a> 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.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve members by Purchase Option keys.\n$o_promotion_model = new \\WellnessLiving\\Wl\\Member\\Purchase\\MemberByPromotionModel($o_config); \n$o_promotion_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session. \n$o_promotion_model->k_business='3'; \n$o_promotion_model->s_promotion_keys='1,16,29'; \n\n\/\/ Perform the request. \n$o_promotion_model->get(); \n \nforeach($o_promotion_model->a_clients as $a_client) \n echo $a_client['uid'].\"\\n\"; <\/pre>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Promotions 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\u2019ll need the business and location keys. You can use the\u00a0ListModel endpoint to retrieve these for all locations in the business. After obtaining the k_location, you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,39],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/308"}],"collection":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":19,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/308\/revisions\/492"}],"wp:attachment":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}