Display a user's product category

Discussion in 'Customization & add-ons' started by awa_la, Aug 14, 2013.

Thread Status:
Not open for further replies.
  1. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Hello,

    I was wondering how I would go about displaying the product category a user has a product from.

    A little background: The way we're using aMember is to create new products each year, so that all members have to renew around the same time. eg. "Professional 2013" will expire at the end of September and members will have to purchase "Professional 2014" by then. I've created a "Professional" product category to manage the overlap and to avoid having to update protections every year.

    Now I would like to be able to display what product category a member "belongs" to. Since product IDs change every year, I'm not sure how to do this. I found Alex's answer to a related question here, but I don't have the knowledge to make use of it.

    Is there a way to do this without having to manually update the product IDs each year?

    Thanks,
    Scott
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello Scott,

    It is good approach to use product categories to set up protection.

    Where is exactly you want to show product categories of active products for user?
    Please let me know and I will suggest some solution for you.

    Best Regards.
  3. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Caesar,

    We're looking to display the product category as part of the profiles in our members directory. We're using the members directory module, for which I've created a custom template that currently displays the membership level, based on the product ID of the active products for each user:

    PHP:
     
    <?php
         
          $membership 
    $user->getActiveProductIds();
                         
          foreach(
    $membership as $k=>$v):
          if (
    $v == 79 || $v == 84) echo 'Professional Membership';
          if (
    $v == 80 || $v == 85) echo 'Professional Membership + Premier Listing';
          if (
    $v == 81 || $v == 86) echo 'Associate Membership';
          if (
    $v == 76 || $v == 87) echo 'Pre-Professional Membership';
          if (
    $v == 83) echo 'Honorary Membership';
         
          endforeach;
    ?>
    Thanks,
    Scott
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Dear Scott,

    You can use the following code to show product categories

    PHP:
    /* this code should be executed once in template before foreach loop */
    $categoriyProducts Am_Di::getInstance()->productCategoryTable->getCategoryProducts();
    $categoryTitles Am_Di::getInstance()->productCategoryTable->getUserSelectOptions();
     
    /* this code should be located within foreach loop */
    /* @var $user User */
    $active_product_ids $user->getActiveProductIds();
    $userCat = array();
    foreach(
    $categoriyProducts as $cat_id => $product_ids) {
        if (
    array_intersect($active_product_ids$product_ids) && isset($categoryTitles[$cat_id]))
            
    $userCat[$cat_id] = $categoryTitles[$cat_id];
    }
     
    echo 
    implode(', '$userCat); // this statement echo active user categories separated by coma
  5. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Perfect. Once again, that's exactly what I needed. Thanks for all of your help Caesar!

    Scott
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page