Number of Active Subscriptions

Discussion in 'Customization & add-ons' started by thetemplateblog, Apr 9, 2012.

  1. thetemplateblog

    thetemplateblog New Member

    Joined:
    Dec 23, 2011
    Messages:
    7
    Two questions
    1) Is there a way to display the number of active subscriptions for a given subscription? Say for example I would like to display the following
    Active Subscriptions

    5 - Social- Lifetime
    3 - Small Business - Lifetime

    http://screencast.com/t/OVkBgupdTGVq

    2) Is there a way to have a custom field, or many custom fields PER subscription.

    Thanks
    dave
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    1. Here is how you can get number of active users who have product subscribed.
    PHP:
    Am_Di::getInstance()->getDbService()->selectCell("select count(distinct(user_id)) from ?_access where product_id = ? and begin_date <= now() and expire_date>=now()"1);
    Where 1 is product id
    2. Possible in php only. What exactly you need to implement?
  3. thetemplateblog

    thetemplateblog New Member

    Joined:
    Dec 23, 2011
    Messages:
    7
    Hi Alexander,

    I'm sorry I wasn't clear on the request. I have a situation where I can have a customer purchase more then one quantity of a given subscription.

    eg:
    user1

    5 of subscription1
    2 of subscription2
    3 of subscription3
    etc...

    What I would like to do is find out how many of a given subscription a particular users would have.

    So the question would be How any of subscription2 does user1 have?

    Thanks
    Dave
  4. thetemplateblog

    thetemplateblog New Member

    Joined:
    Dec 23, 2011
    Messages:
    7
  5. crystalmedia

    crystalmedia Member

    Joined:
    Oct 15, 2013
    Messages:
    59
    I would like this option too! Is there anything we can modify to do this? I have single users with multiple subscriptions for a single software item. It would be nice if we could display in Active Resources how many of each they have.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,064
    Do you mean you want to show qty with Active Subscription widget?

    You can do the following:

    widget-active-subscriptions.png

    With this code snippet within site.php file:
    https://www.amember.com/docs/Site.php_file/

    PHP:
    Am_Di::getInstance()->blocks->add('member/main/bottom', new Am_Block_Base(null'item-qty'null, function(Am_View $v) {
        
    $di Am_Di::getInstance();
        
    $user $di->user;
        
    $_ $user->getActiveProductIds();
        
    $out = [];
        foreach (
    $_ as $pid) {
            
    $qty $di->db->selectCell(<<<CUT
                SELECT SUM(qty)
                    FROM ?_access
                    WHERE user_id = ?
                        AND product_id = ?
                        AND begin_date<=?
                        AND expire_date>=?
    CUT
                ,
                    
    $user->pk(),
                    
    $pid,
                    
    sqlDate('now'),
                    
    sqlDate('now')
                );
            if (
    $qty 1) {
                
    $out[] = "    jQuery('#member-subscriptions #product-item-{$pid} .am-list-subscriptions-title strong').after(' ({$qty})');";
            }
        }
        if (
    $out) {
            
    $out implode("\n"$out);
            return <<<CUT
    <script>
    jQuery(function(){
    {$out}
    });
    </script>
    CUT;

        }
    }));
    crystalmedia likes this.
  7. crystalmedia

    crystalmedia Member

    Joined:
    Oct 15, 2013
    Messages:
    59
    @caesar You rock as always! Love you guys. Thank you.
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,064

Share This Page