Getting Product Multiples Using getActiveProductIds?

Discussion in 'Integration' started by chwoolgar, Jan 21, 2020.

  1. chwoolgar

    chwoolgar New Member

    Joined:
    Dec 5, 2012
    Messages:
    10
    How can I check for multiples of a product ID with the API?

    E.g.
    Code:
    require_once '....../bootstrap.php';
    $user = Am_Di::getInstance()->userTable->findFirstBy(array('login' => $username));
    $active_subs = $user->getActiveProductIds();
    print_r($active_subs);
    This would show E.g.
    Array ( [0] => 9 [1] => 39 [2] => 71 )

    Whereas the user actually has multiples of product ID 39.

    Is there a way to get active product ID's, or to check how many multiples a user has of a specific product ID?
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,071
    You need to query database to get this info. Here is example code:
    PHP:
    $qty Am_Di::getInstance()->db->selectCell(
        
    "SELECT SUM(qty) FROM ?_access WHERE product_id=? AND user_id=? AND begin_date<=? AND expire_date>=?",
        
    39//pid
        
    $user->pk(), //uid
        
    sqlDate('now'),
        
    sqlDate('now')
    );
    Please note result can be 0 - it means user has not active access to this product (with id 39).
    chwoolgar likes this.
  3. chwoolgar

    chwoolgar New Member

    Joined:
    Dec 5, 2012
    Messages:
    10
    Very helpful, works perfectly. Many thanks :)
    caesar likes this.
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,071
    You are welcome!
    chwoolgar likes this.

Share This Page