Product category by user

Discussion in 'Customization & add-ons' started by clickleaders, Apr 7, 2013.

  1. clickleaders

    clickleaders Member

    Joined:
    May 10, 2009
    Messages:
    38
    I'm modifying a plugin that currently checks if the user is subscribed to a particular product id. We want to change that to check for a product category instead.

    My current code to get the products is this:
    $user = Am_Di::getInstance()->userTable->getAuthenticatedRow($login, $pass, $code);
    $prodIds = $user->getActiveProductIds();​

    I can't find a similar functionality to get categories. Is there an easy way to do this? Thanks in advance.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    1. Query for all products in category:
    PHP:
    // return array { category_id => [product_id1, product_id2, ...] } 
    $products Am_Di::getInstance()->productCategoryTable->getCategoryProducts();
    2. Then get products for user:
    PHP:
    $prodIds $user->getActiveProductIds();
    and compare both arrays:
    PHP:
    array_intersect($prodIds$products[$category_id])
  3. clickleaders

    clickleaders Member

    Joined:
    May 10, 2009
    Messages:
    38

Share This Page