How-To

Add customer to AcyMailing

This How-To can be used to have ABPro add a booking customer to your AcyMailing users table and subscribe them to a list.

The code is based in the publish AcyMailing documents:

  • https://www.acyba.com/acymailing/64-acymailing-developer-documentation.html#api_insertuser
  • https://www.acyba.com/acymailing/64-acymailing-developer-documentation.html#api_subscribe

 

There are 2 steps to the How-To.

  1. Add a new function to do the insert.
  2. Call the new function from an appropriate place in ABPro

#EDIT#

ABPro 3.0.5 will have AcyMailing built-in  ;-) 

#EDIT

 


Step 1:

Add a new function to do an insert into AcyMailing

Edit file: \components\com_rsappt_pro3\functions2.php

Just before the final brace bracket of the file insert the following:

function addToAcyMailing($email_to_add, $name_to_add){
    if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_acymailing'.DS.'helpers'.DS.'helper.php')){
     logIt('This code can not work without the AcyMailing Component', "functions2", "", "");
     return false;
    }
    $myUser = new stdClass();
    $myUser->email = $email_to_add;
    $myUser->name = $name_to_add; //this information is optional

    $subscriberClass = acymailing_get('class.subscriber'); 
    $new_user_id = $subscriberClass->save($myUser); 

    $subscribe = array(1); //Id of the lists you want the user to be subscribed to Example array(2,4,6) 
    $userClass = acymailing_get('class.subscriber');

    $newSubscription = array();
    if(!empty($subscribe)){
        foreach($subscribe as $listId){
            $newList = array();
            $newList['status'] = 1;
            $newSubscription[$listId] = $newList;
        }
    }
    if(empty($newSubscription)){
        logIt("Specified AcyMailing list found.", "functions2", "", "");
        return false; //there is nothing to do...
    }

    $userClass->saveSubscription($new_user_id,$newSubscription);
    return true;
}

 

You will need to enter the list ID(s) that you want the new customer subscribed to. This is shown in red above. 

 


Step 2

Call the new function from an appropriate place in ABPro

Where you place the call will depend on which booking screen you are using. For this example I will assume the GAD booking screen so the modification is being made to the GAD booking screen controller.

Edit File: \components\com_rsappt_pro3\controllers\booking_screen_gad.php

Around line 394 look for:

// if "accepted", add to calendar
if($request_status == "accepted"){
    addToCalendar($last_id->last_id, $apptpro_config);
}

Add the red code:

// if "accepted", add to calendar
if($request_status == "accepted"){
    addToCalendar($last_id->last_id, $apptpro_config);
    if(!addToAcyMailing($email, $name)){
        logIt("Add to AcyMailing failed.", "", "", "");
    }
}