What are the correct events for...

Discussion in 'aMember Pro v.4' started by richard_vencu, Nov 28, 2012.

  1. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    1. when someone's subscription becomes active
    2. when someone's subscription expires
    3. when user changes password
    4. when user unsubscribe (if there is such thing)
    Thanks
    Richard
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Richard:
    1. Am_Event::SUBSCRIPTION_ADDED
    2. Am_Event::SUBSCRIPTION_DELETED
    3. Am_Event::SET_PASSWORD
    4. Am_Event::USER_UNSUBSCRIBED_CHANGED
  3. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    Thank you. I also found these events:
    1. Subscription_Changed - meaning the user may still be subscribed but products change (add and/or removal)
    2. Subscription_Updated - what is that?
    3. Subscription_Removed - this is the same as subscription_deleted? Or it is about just partial removing of products (if user remove the product I watch it means I need to treat it like subscription_delete?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    1. Will be fired in addition to subscription_added and subscription_updated hooks. It is fires whenever user's subscriptions are changed.
    2. This hook is deprecated. Use Am_Event::USER_AFTER_UPDATE instead. Will be fired when user change his profile.
    3. This hook will be executed when user is removed from system.
  5. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    OK. The names are little tricky so I insist a bit. Let say one user has subscribed to 2 products and unsubscribe from only one. Then the SUBSCRIPTION_DELETED fires but not SUBSCRIPTION_REMOVED, is that right?
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Yes right.
    SUBSCRIPTION_REMOVED will be fired if user deleted from system.
    SUBSCRIPTION_DElETED if user's subscription expires, but account is still in the system.
  7. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    thanks. is there an event when the user is registering for the first time (and he is valid and saved in aMember database)?
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Use Am_Event::SIGNUP_USER_ADDED
    Executed when User (or affiliate) record is added after submitting signup form - before payment
  9. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    Hi, I just bought the subusers module since I figured out I need to sell access (and invoice) at per company in some cases. At this stage I need to update my integration to use GROUPS and I need to detect additionaly these events:
    - when a reseller subscription is activated
    - when a reseller activates a subuser

    Can you point me to the right events here?
  10. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    Or perhaps I can use the same events and just test if user is reseller and if user is subuser (and who is the parent user). In that case what are the tests to do?
  11. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Just use the same hooks.

    To test User object is it is a reseller use something like this:
    PHP:
    function onAccessAfterInsert($event)
    {
      
    $access $event->getAccess();
      
    $user $access->getUser();
      if (! 
    $user->data()->get('subusers_count')) return;
      
    /// the following code will be executed for resellers only
      
    try {
        
    $invoice $access->getInvoice();
      } catch (
    Exception $e) {
        return; 
    // this access record is not tied to invoice - manually added
      
    }
      
    // now you have User $user and Invoice $invoice - you can do whatever you need this full info
    }
    For second task it is better to use Am_Event::USER_AFTER_INSERT hook.
    To test if User is a "subuser" add to your plugin the following method:
    PHP:
    function onUserAfterInsert($event)
    {
      
    $user $event->getUser();
      if (
    $user->subusers_parent_id)
      {
            
    // this user belongs to a reseller
            // lets load reseller record
            
    $resellerUser Am_Di::getInstance()->userTable->load($user->subusers_parent_idfalse);
            if (!
    $resellerUser) return; // not loaded??? deleted??
      
    }
    }
  12. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    $user->data()->get('subusers_count') will give me the actual number of user the reseller defined or the number he is able to define?

    I am afraid I need to know if he is a reseller even before he starts to define new users. Is that possible?
  13. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Subusers has more complex structure. Do
    PHP:
    $this->getDi()->errorLogTable->log(
        
    "subusers_count: {$user->login} " .
         
    print_r($user->data()->get('subusers_count']), true)
    );
    to review it...
    It will be set before reseller starts to define new users.
    It is only important to check that this hook is executed after the hook of subusers module that defines the "subusers_count" var. Please run such a test: add new user to aMember, go to "Payments" tab and add access to "reseller" product. THen look at aMember CP -> Error Log.

    If it is empty, we can define new hook in subusers module..
  14. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    This part:
    PHP:
    print_r($user->data()->get('subusers_count'), true)
    returns empty string
  15. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Can you provide exact code which you use and also explain in what hook do you have this code.
  16. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    In fact I solved my problem like this: I am not anymore interested if the user is reseller until he register the first subuser. When first subuser subscription is activated I check who is the reseller and I create a group it it does not already exists. Then I associate the reseller and the current user with that group.

Share This Page