Please Help..Force product change on user status change

Discussion in 'Customization & add-ons' started by janea, Nov 1, 2014.

  1. janea

    janea aMember Pro Customer

    Joined:
    Nov 13, 2009
    Messages:
    44
    Hello aMember community.

    I thought I was well versed enough to make this happen, but obviously I am not...or at least not familiar enough with how the hooks are called in the aMember API.

    We are trying to have a customers products changed depending on the new status of the user. If the user is cancelled or Expired (or maybe it is Invoice status for Expired? In the amember GUI admin panel for a user it will say expired so I "assume" that means the user status is Expired) we want to move them to a particular product, one for cancelled and another for expired users. The purpose is to reflect this in Get Response so that we can control different messages to different customers actions, and it will help move them to different campaigns.


    Can anyone help provide some example code of how I could do two things?:

    1) Add a product ID to a user if the users status changes to say Cancelled.
    2) Remove any other products but the new Product ID due to user status change to Cancelled.
    3) Add a product ID to a user if the users status changes to say Expired.
    4) Remove any other products but the new Product ID due to user status change to Expired.

    I really appreciate any help you can give me.

    Jim <Webmaster of Dramanotebook.com>

    PS This is the closest I could come up with, although I have not tested this yet as my confidence is low:

    <?php
    $di = Am_Di::getInstance();
    $di->hook->add(Am_Event::USER_AFTER_UPDATE, 'assignUserProductOnStatusChange');
    function assignUserProductOnStatusChange(Am_Event $event)
    {
    // configuration
    $status_id = 2; // status# that will trigger group addition
    $product_id = 21; // user products that will be set if user status = cancelled
    // the action
    $user = $event->getUser();
    if (array_intersect($status_id, $user->getStatusIds())) // if user has cancelled status
    {
    $status = $user->getStatus();
    if (!in_array($status_id, $status))
    {
    $product[] = $product_id;
    $user->setProducts($product);
    }
    }
    }

Share This Page